<commit_before><?php

namespace Isswp101\Persimmon\Cache;

use Isswp101\Persimmon\Model;

class RuntimeCache
{
    /**
     * Cache.
     *
     * @var array [
     *   'instance' => Model,
     *   'attributes' => []
     * ]
     */
    private $cache = [];

    /**
     * Return true if cache contains this key.
     *
     * @param mixed $key
     * @return bool
     */
    public function has($key)
    {
        return array_key_exists($key, $this->cache);
    }

    /**
     * Return instance from cache.
     *
     * @param mixed $key
     * @return Model
     */
    public function get($key)
    {
        return $this->has($key) ? $this->cache[$key]['instance'] : null;
    }

    /**
     * Return all cache keys.
     *
     * @return array
     */
    public function keys()
    {
        return array_keys($this->cache);
    }

    /**
     * Put instance to cache.
     *
     * @param mixed $key
     * @param Model $instance
     * @param array $attributes
     * @return Model
     */
    public function put($key, Model $instance, array $attributes = ['*'])
    {
        if ($attributes != ['*'] && $this->has($key)) {
            $instance = Model::merge($this->cache[$key]['instance'], $instance, $attributes);
            $attributes = array_merge($this->cache[$key]['attributes'], $attributes);
        }

        $this->cache[$key] = [
            'instance' => $instance,
            'attributes' => $attributes
        ];

        return $instance;
    }

    /**
     * Return true if cache has already given attributes.
     *
     * @param mixed $key
     * @param array $attributes
     * @return bool
     */
    public function containsAttributes($key, array $attributes = ['*'])
    {
        return empty($this->getNotCachedAttributes($key, $attributes));
    }

    /**
     * Return the difference between given attributes and attributes which are already cached.
     *
     * @param mixed $key
     * @param array $attributes
     * @return array
     */
    public function getNotCachedAttributes($key, array $attributes = ['*'])
    {
        if (!$this->has($key)) {
            return $attributes;
        }
        $cached_attributes = $this->cache[$key]['attributes'];
        return $cached_attributes == ['*'] ? [] : array_diff($attributes, $cached_attributes);
    }

    /**
     * Remove an item from the cache by key.
     *
     * @param mixed $key
     * @return $this
     */
    public function forget($key)
    {
        unset($this->cache[$key]);
        return $this;
    }
}
<commit_msg>Code style fix<commit_after><?php

namespace Isswp101\Persimmon\Cache;

use Isswp101\Persimmon\Model;

class RuntimeCache
{
    /**
     * Cache.
     *
     * @var array [
     *   'instance' => Model,
     *   'attributes' => []
     * ]
     */
    private $cache = [];

    /**
     * Return true if cache contains this key.
     *
     * @param mixed $key
     * @return bool
     */
    public function has($key)
    {
        return array_key_exists($key, $this->cache);
    }

    /**
     * Return instance from cache.
     *
     * @param mixed $key
     * @return Model
     */
    public function get($key)
    {
        return $this->has($key) ? $this->cache[$key]['instance'] : null;
    }

    /**
     * Return all cache keys.
     *
     * @return array
     */
    public function keys()
    {
        return array_keys($this->cache);
    }

    /**
     * Put instance to cache.
     *
     * @param mixed $key
     * @param Model $instance
     * @param array $attributes
     * @return Model
     */
    public function put($key, Model $instance, array $attributes = ['*'])
    {
        if ($attributes != ['*'] && $this->has($key)) {
            $instance = Model::merge($this->cache[$key]['instance'], $instance, $attributes);
            $attributes = array_merge($this->cache[$key]['attributes'], $attributes);
        }

        $this->cache[$key] = [
            'instance' => $instance,
            'attributes' => $attributes
        ];

        return $instance;
    }

    /**
     * Return true if cache has already given attributes.
     *
     * @param mixed $key
     * @param array $attributes
     * @return bool
     */
    public function containsAttributes($key, array $attributes = ['*'])
    {
        return empty($this->getNotCachedAttributes($key, $attributes));
    }

    /**
     * Return the difference between given attributes and attributes which are already cached.
     *
     * @param mixed $key
     * @param array $attributes
     * @return array
     */
    public function getNotCachedAttributes($key, array $attributes = ['*'])
    {
        if (!$this->has($key)) {
            return $attributes;
        }
        $cachedAttributes = $this->cache[$key]['attributes'];
        return $cachedAttributes == ['*'] ? [] : array_diff($attributes, $cachedAttributes);
    }

    /**
     * Remove an item from the cache by key.
     *
     * @param mixed $key
     * @return $this
     */
    public function forget($key)
    {
        unset($this->cache[$key]);
        return $this;
    }
}

{'fraction_non_alphanumeric': 0.15098039215686274, 'fraction_numerical': 0.002352941176470588, 'mean_word_length': 1.9536768963520557, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 35, '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': '3365668', 'n_tokens_mistral': 1484, 'n_tokens_neox': 1463, 'n_words': 356}