<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;

/**
 * File driver
 *
 * @package AnimeDb\Bundle\CacheTimeKeeperBundle\Service\Driver
 * @author  <NAME> <<EMAIL>>
 */
class File extends Base
{
    /**
     * Filename suffix
     *
     * @var string
     */
    const FILENAME_SUFFIX = '.key';

    /**
     * Dir
     *
     * @var string
     */
    protected $dir;

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

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

    /**
     * Set time for key
     *
     * @param string $key
     * @param \DateTime $time
     *
     * @return boolean
     */
    public function set($key, \DateTime $time)
    {
        $time = $time->getTimestamp();
        $file = $this->getFilename($key);
        if (!file_exists($file) || $time > filemtime($file)) {
            return touch($file, $time);
        }
        return true;
    }

    /**
     * Get filename from key
     *
     * @param string $key
     *
     * @return string
     */
    protected function getFilename($key)
    {
        return $this->dir.'/'.md5($key).self::FILENAME_SUFFIX;
    }
}<commit_msg>create dir if not exists<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;

/**
 * File driver
 *
 * @package AnimeDb\Bundle\CacheTimeKeeperBundle\Service\Driver
 * @author  <NAME> <<EMAIL>>
 */
class File extends Base
{
    /**
     * Filename suffix
     *
     * @var string
     */
    const FILENAME_SUFFIX = '.key';

    /**
     * Dir
     *
     * @var string
     */
    protected $dir;

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

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

    /**
     * Set time for key
     *
     * @param string $key
     * @param \DateTime $time
     *
     * @return boolean
     */
    public function set($key, \DateTime $time)
    {
        $time = $time->getTimestamp();
        $file = $this->getFilename($key);
        if (!file_exists($file) || $time > filemtime($file)) {
            return touch($file, $time);
        }
        return true;
    }

    /**
     * Get filename from key
     *
     * @param string $key
     *
     * @return string
     */
    protected function getFilename($key)
    {
        if (!is_dir($this->dir)) {
            mkdir($this->dir, 0644, true);
        }
        return $this->dir.'/'.md5($key).self::FILENAME_SUFFIX;
    }
}
{'fraction_non_alphanumeric': 0.152191894127378, 'fraction_numerical': 0.0038599393438103115, 'mean_word_length': 1.8566929133858268, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 31, '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': '6409379', 'n_tokens_mistral': 1206, 'n_tokens_neox': 1172, 'n_words': 245}