<commit_before><?php

namespace Applistic\Common;

use Closure;
use Countable;
use ArrayAccess;

/**
 * A basic key/value store.
 *
 * @author <NAME> <<EMAIL>>
 * @copyright (c) 2014, <NAME>
 * @license http://www.opensource.org/licenses/mit-license.php MIT License
 */
class KeyValue implements Countable, ArrayAccess
{
// ===== CONSTANTS =============================================================
// ===== STATIC PROPERTIES =====================================================
// ===== STATIC FUNCTIONS ======================================================
// ===== PROPERTIES ============================================================

    /**
     * The items.
     *
     * @var array
     */
    protected $items = array();

    /**
     * The iterator index.
     *
     * @var integer
     */
    protected $index = 0;


// ===== CONSTRUCTOR ===========================================================

    /**
     * Constructs a KeyValue object.
     *
     * @param array $items Optional initial items.
     */
    public function __construct(array $items = null)
    {
        if (!is_null($items)) {
            $this->items = $items;
        }
    }


// ===== PUBLIC METHODS ========================================================

    /**
     * Checks if the $key is registered.
     *
     * The value associated with the $key can be null.
     *
     * @param  string  $key
     * @return boolean
     */
    public function has($key)
    {
        return array_key_exists($key, $this->items);
    }

    /**
     * Sets the value of a key.
     *
     * @param string|int $key
     * @param mixed $value
     */
    public function set($key, $value)
    {
        if (!is_string($key)) {
            $message = "\$key must be a string.";
            throw new \InvalidArgumentException($message);
        }

        $this->items[$key] = $value;
    }

    /**
     * Returns the value of a key.
     *
     * @param  string|int $key
     * @return mixed
     */
    public function get($key, $default = null)
    {
        if ($this->has($key)) {
            return $this->items[$key];
        } else {
            return $default;
        }
    }

    /**
     * Removes a key.
     *
     * @param  string $key The key to remove.
     * @return void
     */
    public function remove($key)
    {
        unset($this->items[$key]);
    }

    /**
     * Increases a value.
     *
     * @param  string  $key    The key.
     * @param  numeric $amount The amount to add.
     * @return void
     */
    public function increase($key, $amount = 1)
    {
        $this->changeNumericValue($key, $amount);
    }

    /**
     * Decreases a value.
     *
     * @param  string  $key    The key.
     * @param  numeric $amount The amount to remove.
     * @return void
     */
    public function decrease($key, $amount = 1)
    {
        $this->changeNumericValue($key, $amount, true);
    }

    /**
     * Randomizes.
     *
     * @return void
     */
    public function shuffle()
    {
        shuffle($this->items);
    }

    /**
     * Sorts the keys alphabetically.
     *
     * @return void
     */
    public function sort($order = 'asc')
    {
        if ($order == 'desc') {
            krsort($this->items);
        } else {
            ksort($this->items);
        }
    }

    public function toArray()
    {
        return $this->items;
    }

    /**
     * Returns a JSON representation.
     *
     * @return string
     */
    public function toJson()
    {
        return json_encode($this->items);
    }

    /**
     * Removes all items and restore the index.
     *
     * @return void
     */
    public function clear()
    {
        $this->items = array();
        $this->rewind();
    }

    /**
     * Walks through the items to perform actions.
     *
     * @see array_walk
     *
     * @param  Closure $handler The function.
     * @return void
     */
    public function each(Closure $handler)
    {
        foreach ($this->items as $key => $value) {
            if ($handler($key, $value) === false) {
                break;<commit_msg>Removed the no longer used `index` property.<commit_after><?php

namespace Applistic\Common;

use Closure;
use Countable;
use ArrayAccess;

/**
 * A basic key/value store.
 *
 * @author <NAME> <<EMAIL>>
 * @copyright (c) 2014, <NAME>
 * @license http://www.opensource.org/licenses/mit-license.php MIT License
 */
class KeyValue implements Countable, ArrayAccess
{
// ===== CONSTANTS =============================================================
// ===== STATIC PROPERTIES =====================================================
// ===== STATIC FUNCTIONS ======================================================
// ===== PROPERTIES ============================================================

    /**
     * The items.
     *
     * @var array
     */
    protected $items = array();


// ===== CONSTRUCTOR ===========================================================

    /**
     * Constructs a KeyValue object.
     *
     * @param array $items Optional initial items.
     */
    public function __construct(array $items = null)
    {
        if (!is_null($items)) {
            $this->items = $items;
        }
    }


// ===== PUBLIC METHODS ========================================================

    /**
     * Checks if the $key is registered.
     *
     * The value associated with the $key can be null.
     *
     * @param  string  $key
     * @return boolean
     */
    public function has($key)
    {
        return array_key_exists($key, $this->items);
    }

    /**
     * Sets the value of a key.
     *
     * @param string|int $key
     * @param mixed $value
     */
    public function set($key, $value)
    {
        if (!is_string($key)) {
            $message = "\$key must be a string.";
            throw new \InvalidArgumentException($message);
        }

        $this->items[$key] = $value;
    }

    /**
     * Returns the value of a key.
     *
     * @param  string|int $key
     * @return mixed
     */
    public function get($key, $default = null)
    {
        if ($this->has($key)) {
            return $this->items[$key];
        } else {
            return $default;
        }
    }

    /**
     * Removes a key.
     *
     * @param  string $key The key to remove.
     * @return void
     */
    public function remove($key)
    {
        unset($this->items[$key]);
    }

    /**
     * Increases a value.
     *
     * @param  string  $key    The key.
     * @param  numeric $amount The amount to add.
     * @return void
     */
    public function increase($key, $amount = 1)
    {
        $this->changeNumericValue($key, $amount);
    }

    /**
     * Decreases a value.
     *
     * @param  string  $key    The key.
     * @param  numeric $amount The amount to remove.
     * @return void
     */
    public function decrease($key, $amount = 1)
    {
        $this->changeNumericValue($key, $amount, true);
    }

    /**
     * Randomizes.
     *
     * @return void
     */
    public function shuffle()
    {
        shuffle($this->items);
    }

    /**
     * Sorts the keys alphabetically.
     *
     * @return void
     */
    public function sort($order = 'asc')
    {
        if ($order == 'desc') {
            krsort($this->items);
        } else {
            ksort($this->items);
        }
    }

    public function toArray()
    {
        return $this->items;
    }

    /**
     * Returns a JSON representation.
     *
     * @return string
     */
    public function toJson()
    {
        return json_encode($this->items);
    }

    /**
     * Removes all items.
     *
     * @return void
     */
    public function clear()
    {
        $this->items = array();
        $this->rewind();
    }

    /**
     * Walks through the items to perform actions.
     *
     * @see array_walk
     *
     * @param  Closure $handler The function.
     * @return void
     */
    public function each(Closure $handler)
    {
        foreach ($this->items as $key => $value) {
            if ($handler($key, $value) === false) {
                break;
{'fraction_non_alphanumeric': 0.21504315659679407, 'fraction_numerical': 0.0016029593094944513, 'mean_word_length': 1.8559859154929577, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '1666146', 'n_tokens_mistral': 2408, 'n_tokens_neox': 2298, 'n_words': 591}