<commit_before><?php

namespace MatthiasMullie\Scrapbook\Psr16;

use DateInterval;
use DateTime;
use MatthiasMullie\Scrapbook\KeyValueStore;
use Psr\SimpleCache\CacheInterface;
use Traversable;

/**
 * @author <NAME> <<EMAIL>>
 * @copyright Copyright (c) 2014, <NAME>. All rights reserved
 * @license LICENSE MIT
 */
class SimpleCache implements CacheInterface
{
    /**
     * @var KeyValueStore
     */
    protected $store;

    /**
     * @param KeyValueStore $store
     */
    public function __construct(KeyValueStore $store)
    {
        $this->store = $store;
    }

    /**
     * {@inheritdoc}
     */
    public function get($key, $default = null)
    {
        if (!is_string($key)) {
            throw new InvalidArgumentException(
                'Invalid key: '.serialize($key).'. Must be string.'
            );
        }

        // KeyValueStore::get returns false for cache misses (which could also
        // be confused for a `false` value), so we'll check existence with getMulti
        $multi = $this->store->getMulti(array($key));

        return isset($multi[$key]) ? $multi[$key] : $default;
    }

    /**
     * {@inheritdoc}
     */
    public function set($key, $value, $ttl = null)
    {
        if (!is_string($key)) {
            throw new InvalidArgumentException(
                'Invalid key: '.serialize($key).'. Must be string.'
            );
        }

        $ttl = $this->ttl($ttl);

        return $this->store->set($key, $value, $ttl);
    }

    /**
     * {@inheritdoc}
     */
    public function delete($key)
    {
        if (!is_string($key)) {
            throw new InvalidArgumentException(
                'Invalid key: '.serialize($key).'. Must be string.'
            );
        }

        return $this->store->delete($key);
    }

    /**
     * {@inheritdoc}
     */
    public function clear()
    {
        return $this->store->flush();
    }

    /**
     * {@inheritdoc}
     */
    public function getMultiple($keys, $default = null)
    {
        if ($keys instanceof Traversable) {
            $keys = iterator_to_array($keys);
        }

        if (!is_array($keys) || array_filter($keys, 'is_string') !== $keys) {
            throw new InvalidArgumentException(
                'Invalid keys: '.serialize($keys).'. Must be array of strings.'
            );
        }

        $results = $this->store->getMulti($keys);

        // KeyValueStore omits values that are not in cache, while PSR-16 will
        // have them with a default value
        $nulls = array_fill_keys($keys, $default);
        $results = array_merge($nulls, $results);

        return $results;
    }

    /**
     * {@inheritdoc}
     */
    public function setMultiple($items, $ttl = null)
    {
        if ($items instanceof Traversable) {
            $items = iterator_to_array($items);
        }

        $keys = array_keys($items);
        if (!is_array($keys) || array_filter($keys, 'is_string') !== $keys) {
            throw new InvalidArgumentException(
                'Invalid keys: '.serialize($keys).'. Must be array of strings.'
            );
        }

        $ttl = $this->ttl($ttl);
        $success = $this->store->setMulti($items, $ttl);

        return !in_array(false, $success);
    }

    /**
     * {@inheritdoc}
     */
    public function deleteMultiple($keys)
    {
        if ($keys instanceof Traversable) {
            $keys = iterator_to_array($keys);
        }

        if (!is_array($keys) || array_filter($keys, 'is_string') !== $keys) {<commit_msg>Rename getMultiple's $items to $values<commit_after><?php

namespace MatthiasMullie\Scrapbook\Psr16;

use DateInterval;
use DateTime;
use MatthiasMullie\Scrapbook\KeyValueStore;
use Psr\SimpleCache\CacheInterface;
use Traversable;

/**
 * @author <NAME> <<EMAIL>>
 * @copyright Copyright (c) 2014, <NAME>. All rights reserved
 * @license LICENSE MIT
 */
class SimpleCache implements CacheInterface
{
    /**
     * @var KeyValueStore
     */
    protected $store;

    /**
     * @param KeyValueStore $store
     */
    public function __construct(KeyValueStore $store)
    {
        $this->store = $store;
    }

    /**
     * {@inheritdoc}
     */
    public function get($key, $default = null)
    {
        if (!is_string($key)) {
            throw new InvalidArgumentException(
                'Invalid key: '.serialize($key).'. Must be string.'
            );
        }

        // KeyValueStore::get returns false for cache misses (which could also
        // be confused for a `false` value), so we'll check existence with getMulti
        $multi = $this->store->getMulti(array($key));

        return isset($multi[$key]) ? $multi[$key] : $default;
    }

    /**
     * {@inheritdoc}
     */
    public function set($key, $value, $ttl = null)
    {
        if (!is_string($key)) {
            throw new InvalidArgumentException(
                'Invalid key: '.serialize($key).'. Must be string.'
            );
        }

        $ttl = $this->ttl($ttl);

        return $this->store->set($key, $value, $ttl);
    }

    /**
     * {@inheritdoc}
     */
    public function delete($key)
    {
        if (!is_string($key)) {
            throw new InvalidArgumentException(
                'Invalid key: '.serialize($key).'. Must be string.'
            );
        }

        return $this->store->delete($key);
    }

    /**
     * {@inheritdoc}
     */
    public function clear()
    {
        return $this->store->flush();
    }

    /**
     * {@inheritdoc}
     */
    public function getMultiple($keys, $default = null)
    {
        if ($keys instanceof Traversable) {
            $keys = iterator_to_array($keys);
        }

        if (!is_array($keys) || array_filter($keys, 'is_string') !== $keys) {
            throw new InvalidArgumentException(
                'Invalid keys: '.serialize($keys).'. Must be array of strings.'
            );
        }

        $results = $this->store->getMulti($keys);

        // KeyValueStore omits values that are not in cache, while PSR-16 will
        // have them with a default value
        $nulls = array_fill_keys($keys, $default);
        $results = array_merge($nulls, $results);

        return $results;
    }

    /**
     * {@inheritdoc}
     */
    public function setMultiple($values, $ttl = null)
    {
        if ($values instanceof Traversable) {
            $values = iterator_to_array($values);
        }

        $keys = array_keys($values);
        if (!is_array($keys) || array_filter($keys, 'is_string') !== $keys) {
            throw new InvalidArgumentException(
                'Invalid keys: '.serialize($keys).'. Must be array of strings.'
            );
        }

        $ttl = $this->ttl($ttl);
        $success = $this->store->setMulti($values, $ttl);

        return !in_array(false, $success);
    }

    /**
     * {@inheritdoc}
     */
    public function deleteMultiple($keys)
    {
        if ($keys instanceof Traversable) {
            $keys = iterator_to_array($keys);
        }

        if (!is_array($keys) || array_filter($keys, 'is_string') !== $keys) {
{'fraction_non_alphanumeric': 0.14628297362110312, 'fraction_numerical': 0.002257017915079701, 'mean_word_length': 1.9852631578947368, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 41, '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': '2819028', 'n_tokens_mistral': 2107, 'n_tokens_neox': 2031, 'n_words': 490}