<commit_before><?php
/**
 * AnimeDb package
 *
 * @package   AnimeDb
 * @author    <NAME> <<EMAIL>>
 * @copyright Copyright (c) 2014, <NAME>
 * @license   http://opensource.org/licenses/MIT
 */

namespace AnimeDb\Bundle\CacheTimeKeeperBundle\Service\Driver;

use AnimeDb\Bundle\CacheTimeKeeperBundle\Service\Driver\Base;
use AnimeDb\Shmop\FixedBlock as BlockShmop;

/**
 * Shmop driver
 *
 * @package AnimeDb\Bundle\CacheTimeKeeperBundle\Service\Driver
 * @author  <NAME> <<EMAIL>>
 */
class Shmop extends Base
{
    /**
     * Cache key salt
     *
     * @var string
     */
    protected $salt;

    /**
     * Construct
     *
     * @param string $salt
     */
    public function __construct($salt)
    {
        // can't test it
        // @codeCoverageIgnoreStart
        if (!extension_loaded('shmop')) {
            throw new \RuntimeException('Extension "shmop" is not loaded');
        }
        // @codeCoverageIgnoreEnd
        $this->salt = $salt;
    }

    /**
     * Get time for key
     *
     * @param string $key
     *
     * @return \DateTime|null
     */
    public function get($key)
    {
        $sh = new BlockShmop($this->getIdBykey($key), 10);
        if ($time = $sh->read()) {
            return new \DateTime(date('Y-m-d H:i:s', $time));
        }
        return null;
    }

    /**
     * Set time for key
     *
     * @param string $key
     * @param \DateTime $time
     *
     * @return boolean
     */
    public function set($key, \DateTime $time)
    {
        $sh = new BlockShmop($this->getIdBykey($key), 10);
        if (!($old_time = $sh->read()) || $old_time < $time->getTimestamp()) {
            $sh->write($time->getTimestamp());
        }
        return true;
    }

    /**
     * Remove time for key
     *
     * @param string $key
     *
     * @return boolean
     */
    public function remove($key)
    {
        $sh = new BlockShmop($this->getIdBykey($key), 10);
        return $sh->delete();
    }

    /**
     * Get id
     *
     * @param string $key
     *
     * @return integer
     */
    public function getIdBykey($key)
    {
        return (int)sprintf('%u', crc32($key.$this->salt));
    }
}
<commit_msg>not check shmop extension<commit_after><?php
/**
 * AnimeDb package
 *
 * @package   AnimeDb
 * @author    <NAME> <<EMAIL>>
 * @copyright Copyright (c) 2014, <NAME>
 * @license   http://opensource.org/licenses/MIT
 */

namespace AnimeDb\Bundle\CacheTimeKeeperBundle\Service\Driver;

use AnimeDb\Bundle\CacheTimeKeeperBundle\Service\Driver\Base;
use AnimeDb\Shmop\FixedBlock as BlockShmop;

/**
 * Shmop driver
 *
 * @package AnimeDb\Bundle\CacheTimeKeeperBundle\Service\Driver
 * @author  <NAME> <<EMAIL>>
 */
class Shmop extends Base
{
    /**
     * Cache key salt
     *
     * @var string
     */
    protected $salt;

    /**
     * Construct
     *
     * @param string $salt
     */
    public function __construct($salt)
    {
        $this->salt = $salt;
    }

    /**
     * Get time for key
     *
     * @param string $key
     *
     * @return \DateTime|null
     */
    public function get($key)
    {
        $sh = new BlockShmop($this->getIdBykey($key), 10);
        if ($time = $sh->read()) {
            return new \DateTime(date('Y-m-d H:i:s', $time));
        }
        return null;
    }

    /**
     * Set time for key
     *
     * @param string $key
     * @param \DateTime $time
     *
     * @return boolean
     */
    public function set($key, \DateTime $time)
    {
        $sh = new BlockShmop($this->getIdBykey($key), 10);
        if (!($old_time = $sh->read()) || $old_time < $time->getTimestamp()) {
            $sh->write($time->getTimestamp());
        }
        return true;
    }

    /**
     * Remove time for key
     *
     * @param string $key
     *
     * @return boolean
     */
    public function remove($key)
    {
        $sh = new BlockShmop($this->getIdBykey($key), 10);
        return $sh->delete();
    }

    /**
     * Get id
     *
     * @param string $key
     *
     * @return integer
     */
    public function getIdBykey($key)
    {
        return (int)sprintf('%u', crc32($key.$this->salt));
    }
}

{'fraction_non_alphanumeric': 0.15406906544312968, 'fraction_numerical': 0.005795701521371649, 'mean_word_length': 1.9210155148095909, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 39, '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': '7221478', 'n_tokens_mistral': 1406, 'n_tokens_neox': 1362, 'n_words': 289}