<commit_before><?php

/**
 * The Menu class provides a generic way to deal with simple or complex menus
 * on web projects. It supports an infinite amount of submenus and in theory
 * can build a menu from any data structure.
 *
 * @package monolyth
 * @subpackage render
 */

namespace monolyth\render;
use ArrayObject;
use StdClass;
use ErrorException;

/**
 * The Menu class. It should be constructed with an iterable object, or a
 * simple array.
 *
 * The default behaviour is to expect query results from monad_menu, or a
 * compatible form.
 *
 * @see monolyth\render\Item_Menu
 */
class Menu extends ArrayObject
{
    const ITERATE = 1;
    const KEY = 2;
    const VALUE = 3;

    public function build($items, array $options = [])
    {
        $options += [
            self::ITERATE => null,
            self::KEY => function($key) { return $key; },
            self::VALUE => function($value) {
                return $this->item->build($value);
            },
        ];
        if (!isset($options[self::ITERATE])) {
            $options[self::ITERATE] = function($key, $value) use($options) {
                $key = call_user_func($options[self::KEY], $key);
                $value = call_user_func($options[self::VALUE], $value);
                return [$key, $value];
            };
        }
        foreach ($items as $key => $value) {
            list($key, $value) = call_user_func(
                $options[self::ITERATE],
                $key,
                $value
            );
            $this[$key] = $value;
        }
        return $this;
    }
}

<commit_msg>modernize<commit_after><?php

/**
 * The Menu class provides a generic way to deal with simple or complex menus
 * on web projects. It supports an infinite amount of submenus and in theory
 * can build a menu from any data structure.
 *
 * @package monolyth
 * @subpackage render
 */

namespace monolyth\render;
use ArrayObject;
use StdClass;
use ErrorException;

/**
 * The Menu class. It should be constructed with an iterable object, or a
 * simple array.
 *
 * The default behaviour is to expect query results from monad_menu, or a
 * compatible form.
 *
 * @see monolyth\render\Item_Menu
 */
class Menu extends ArrayObject
{
    const ITERATE = 1;
    const KEY = 2;
    const VALUE = 3;

    public function build($items, array $options = [])
    {
        $options += [
            self::ITERATE => null,
            self::KEY => function($key) { return $key; },
            self::VALUE => function($value) {
                return (new Item_Menu)->build($value);
            },
        ];
        if (!isset($options[self::ITERATE])) {
            $options[self::ITERATE] = function($key, $value) use($options) {
                $key = call_user_func($options[self::KEY], $key);
                $value = call_user_func($options[self::VALUE], $value);
                return [$key, $value];
            };
        }
        foreach ($items as $key => $value) {
            list($key, $value) = call_user_func(
                $options[self::ITERATE],
                $key,
                $value
            );
            $this[$key] = $value;
        }
        return $this;
    }
}


{'fraction_non_alphanumeric': 0.12523540489642185, 'fraction_numerical': 0.0018832391713747645, 'mean_word_length': 2.055608820709492, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7009017', 'n_tokens_mistral': 922, 'n_tokens_neox': 895, 'n_words': 277}