<commit_before><?php

namespace Nayjest\Collection\Decorator;

use InvalidArgumentException;
use Nayjest\Collection\CollectionDataTrait;
use Nayjest\Collection\CollectionReadInterface;
use Nayjest\Collection\CollectionReadTrait;

class ReadonlyCollection implements CollectionReadInterface
{
    use CollectionDataTrait;
    use CollectionReadTrait;

    /**
     * @param CollectionReadInterface|array $collection
     */
    public function __construct($collection)
    {
        if ($collection instanceof CollectionReadInterface)
        {
            $this->data = $collection->toArray();
        } elseif(is_array($collection)) {
            $this->data = $collection;
        } else {
            throw new InvalidArgumentException;
        }
    }

    protected function createCollection(array $items)
    {
        return new static($items);
    }
}<commit_msg>ReadonlyCollection now will be updated after modifying source collection<commit_after><?php

namespace Nayjest\Collection\Decorator;

use Nayjest\Collection\Collection;
use Nayjest\Collection\CollectionReadInterface;
use Nayjest\Collection\CollectionReadTrait;

class ReadonlyCollection implements CollectionReadInterface
{
    use CollectionReadTrait;

    private $collection;
    private $data;

    protected function &items()
    {
        $this->data = $this->collection->toArray();
        return $this->data;
    }

    /**
     * @param CollectionReadInterface|array $collection
     */
    public function __construct(CollectionReadInterface $collection)
    {
        $this->collection = $collection;
    }

    protected function createCollection(array $items)
    {
        $collection = new Collection();
        $collection->setItems($items);
        return new static($collection);
    }
}
{'fraction_non_alphanumeric': 0.09121621621621621, 'fraction_numerical': 0.0, 'mean_word_length': 3.3341463414634145, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 12, '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': '3382054', 'n_tokens_mistral': 463, 'n_tokens_neox': 447, 'n_words': 99}