<commit_before><?php
namespace Cujo\Content;

abstract class Content implements \ArrayAccess
{
    public function __get($offset)
    {
        return $this->offsetGet($offset);
    }

    public function __set($offset, $value)
    {
        $this->offsetSet($offset, $value);
    }

    public function __isSet($offset)
    {
        return $this->offsetExists($offset);
    }

    public function __unset($offset)
    {
        $this->offsetUnset($offset);
    }

    public function offsetGet($offset)
    {
        return $this->get($offset);
    }

    public function offsetSet($offset, $value)
    {
        if ($this instanceof Mutable) {
            $this->set($offset, $value);
        }
        throw new \Exception('Content ' . get_class($this) . ' is not mutable');
    }

    public function offsetExists($offset)
    {
        return true;
    }

    public function offsetUnset($offset)
    {
        if ($this instanceof Mutable) {
            $this->remove($offset);
        }
        throw new \Exception('Content ' . get_class($this) . ' is not mutable');
    }

    abstract protected function get($key);

    abstract public function find(array $criteria);

    public function isMutable()
    {
        return $this instanceof Mutable;
    }
}<commit_msg>Add fallback to key option<commit_after><?php
namespace Cujo\Content;

abstract class Content implements \ArrayAccess
{
    protected $fallbackToKey = false;

    public function __get($offset)
    {
        return $this->offsetGet($offset);
    }

    public function __set($offset, $value)
    {
        $this->offsetSet($offset, $value);
    }

    public function __isSet($offset)
    {
        return $this->offsetExists($offset);
    }

    public function __unset($offset)
    {
        $this->offsetUnset($offset);
    }

    public function offsetGet($offset)
    {
        $r = $this->get($offset);
        if ((false !== $r && null !== $r)) {
            return $r;
        }
        return $this->isFallbackToKey() ? $offset : false;
    }

    public function offsetSet($offset, $value)
    {
        if ($this instanceof Mutable) {
            $this->set($offset, $value);
        }
        throw new \Exception('Content ' . get_class($this) . ' is not mutable');
    }

    public function offsetExists($offset)
    {
        return true;
    }

    public function offsetUnset($offset)
    {
        if ($this instanceof Mutable) {
            $this->remove($offset);
        }
        throw new \Exception('Content ' . get_class($this) . ' is not mutable');
    }

    abstract protected function get($key);

    abstract public function find(array $criteria);

    public function isMutable()
    {
        return $this instanceof Mutable;
    }

    public function setFallbackToKey($fallback = true)
    {
        $this->fallbackToKey = $fallback;
    }

    public function isFallbackToKey()
    {
        return $this->fallbackToKey;
    }
}
{'fraction_non_alphanumeric': 0.12512750765045902, 'fraction_numerical': 0.0, 'mean_word_length': 2.250828729281768, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 20, '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': '5766567', 'n_tokens_mistral': 858, 'n_tokens_neox': 833, 'n_words': 201}