<commit_before><?php namespace Arcanedev\Markup\Support;

use Arcanedev\Markup\Contracts\Arrayable;
use ArrayAccess;
use Closure;
use Countable;

class Collection implements Countable, ArrayAccess, Arrayable
{
    /* ------------------------------------------------------------------------------------------------
     |  Properties
     | ------------------------------------------------------------------------------------------------
     */
    /** @var array */
    protected $items = [];

    /* ------------------------------------------------------------------------------------------------
     |  Constructor
     | ------------------------------------------------------------------------------------------------
     */
    /**
     * @param Collection|array $items
     */
    function __construct($items = [])
    {
        $items = ! is_null($items)
            ? $this->getArrayableItems($items)
            : [];

        $this->items = (array) $items;
    }

    /* ------------------------------------------------------------------------------------------------
     |  Main Functions
     | ------------------------------------------------------------------------------------------------
     */
    /**
     * Get all of the items in the collection.
     *
     * @return array
     */
    public function all()
    {
        return $this->items;
    }

    /**
     * @param mixed      $key
     * @param mixed|null $default
     *
     * @return mixed
     */
    public function get($key, $default = null)
    {
        if ( $this->offsetExists($key) ) {
            return $this->offsetGet($key);
        }

        return $this->value($default);
    }

    /**
     * Set an item in the collection by key.
     *
     * @param mixed $key
     * @param mixed $value
     *
     * @return Collection
     */
    public function set($key, $value)
    {
        $this->offsetSet($key, $value);

        return $this;
    }

    /**
     * Put an item in the collection by key.
     *
     * @param mixed $key
     * @param mixed $value
     *
     * @return Collection
     */
    public function put($key, $value)
    {
        return $this->set($key, $value);
    }

    /**
     * Push an item
     *
     * @param mixed $value
     *
     * @return Collection
     */
    public function push($value)
    {
        $this->items[] = $value;

        return $this;
    }

    /**
     * Check if has an item by Key
     *
     * @param mixed $key
     *
     * @return bool
     */
    public function has($key)
    {
        return $this->offsetExists($key);
    }

    /**
     * Remove an item from the collection by key.
     *
     * @param  mixed  $key
     * @return void
     */
    public function forget($key)
    {
        $this->offsetUnset($key);
    }

    /**
     * Execute a callback over each item.
     *
     * @param Closure $callback
     *
     * @return Collection
     */
    public function each(Closure $callback)
    {
        return new self(array_map($callback, $this->items));
    }

    /**
     * Get array items
     *
     * @return array
     */
    public function toArray()
    {
        return $this->all();
    }

    /* ------------------------------------------------------------------------------------------------
     |  ArrayAccess Functions
     | ------------------------------------------------------------------------------------------------
     */
    /**
     * Determine if an item exists at an offset.
     *
     * @param  mixed  $key
     *
     * @return bool
     */
    public function offsetExists($key)
    {
        return array_key_exists($key, $this->items);
    }

    /**
     * Get an item at a given offset.
     *
     * @param  mixed  $key
     *
     * @return mixed<commit_msg>Adding keys method to Collection Class<commit_after><?php namespace Arcanedev\Markup\Support;

use Arcanedev\Markup\Contracts\Arrayable;
use ArrayAccess;
use Closure;
use Countable;

class Collection implements Countable, ArrayAccess, Arrayable
{
    /* ------------------------------------------------------------------------------------------------
     |  Properties
     | ------------------------------------------------------------------------------------------------
     */
    /** @var array */
    protected $items = [];

    /* ------------------------------------------------------------------------------------------------
     |  Constructor
     | ------------------------------------------------------------------------------------------------
     */
    /**
     * @param Collection|array $items
     */
    function __construct($items = [])
    {
        $items = ! is_null($items)
            ? $this->getArrayableItems($items)
            : [];

        $this->items = (array) $items;
    }

    /* ------------------------------------------------------------------------------------------------
     |  Main Functions
     | ------------------------------------------------------------------------------------------------
     */
    /**
     * Get all of the items in the collection.
     *
     * @return array
     */
    public function all()
    {
        return $this->items;
    }

    /**
     * @param mixed      $key
     * @param mixed|null $default
     *
     * @return mixed
     */
    public function get($key, $default = null)
    {
        if ( $this->offsetExists($key) ) {
            return $this->offsetGet($key);
        }

        return $this->value($default);
    }

    /**
     * Set an item in the collection by key.
     *
     * @param mixed $key
     * @param mixed $value
     *
     * @return Collection
     */
    public function set($key, $value)
    {
        $this->offsetSet($key, $value);

        return $this;
    }

    /**
     * Put an item in the collection by key.
     *
     * @param mixed $key
     * @param mixed $value
     *
     * @return Collection
     */
    public function put($key, $value)
    {
        return $this->set($key, $value);
    }

    /**
     * Push an item
     *
     * @param mixed $value
     *
     * @return Collection
     */
    public function push($value)
    {
        $this->items[] = $value;

        return $this;
    }

    /**
     * Check if has an item by Key
     *
     * @param mixed $key
     *
     * @return bool
     */
    public function has($key)
    {
        return $this->offsetExists($key);
    }

    /**
     * Remove an item from the collection by key.
     *
     * @param  mixed  $key
     * @return void
     */
    public function forget($key)
    {
        $this->offsetUnset($key);
    }

    /**
     * Execute a callback over each item.
     *
     * @param Closure $callback
     *
     * @return Collection
     */
    public function each(Closure $callback)
    {
        return new self(array_map($callback, $this->items));
    }

    /**
     * Get array items
     *
     * @return array
     */
    public function toArray()
    {
        return $this->all();
    }

    /**
     * Get only keys
     *
     * @return array
     */
    public function keys()
    {
        return array_keys($this->items);
    }

    /* ------------------------------------------------------------------------------------------------
     |  ArrayAccess Functions
     | ------------------------------------------------------------------------------------------------
     */
    /**
     * Determine if an item exists at an offset.
     *
     * @param  mixed  $key
     *
     * @return bool
     */
    public function offsetExists($key)
    {
        return array_key_exists($key, $this->items);
    }

    /**
     * Get an item at a given offset.
     *
     * @param  mixed  $key
     *
     * @return mixed
{'fraction_non_alphanumeric': 0.3033562265128936, 'fraction_numerical': 0.0, 'mean_word_length': 0.9242084268262278, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 32, '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': '3365703', 'n_tokens_mistral': 1950, 'n_tokens_neox': 1901, 'n_words': 470}