<commit_before><?php
/**
 * This file is part of the InMemoryList package.
 *
 * (c) <NAME><https://github.com/mauretto78>
 *
 *  For the full copyright and license information, please view the LICENSE
 *  file that was distributed with this source code.
 */

namespace InMemoryList\Infrastructure\Persistance;

use InMemoryList\Infrastructure\Persistance\Exceptions\ListElementDoesNotExistsException;

abstract class AbstractRepository
{
    /**
     * @param $listUuid
     *
     * @return mixed
     */
    public function delete($listUuid)
    {
        $list = $this->findListByUuid($listUuid);

        foreach (array_keys($list) as $elementUuid) {
            $this->deleteElement($listUuid, $elementUuid);
        }
    }

    /**
     * @param $listUuid
     * @param $elementUuid
     *
     * @return mixed
     */
    public function existsElement($listUuid, $elementUuid)
    {
        if (isset($this->findListByUuid($listUuid)[$elementUuid])) {
            return $this->findListByUuid($listUuid)[$elementUuid];
        }

        return false;
    }

    /**
     * @param $listUuid
     * @param $elementUuid
     *
     * @return mixed
     *
     * @throws ListElementDoesNotExistsException
     */
    public function findElement($listUuid, $elementUuid)
    {
        if (!$element = $this->existsElement($listUuid, $elementUuid)) {
            throw new ListElementDoesNotExistsException('Cannot retrieve the element '.$elementUuid.' from the collection in memory.');
        }

        return $element;
    }

    /**
     * @param $listUuid
     *
     * @return mixed
     */
    public function getChunkSize($listUuid)
    {
        if ($this->existsListInIndex($listUuid)) {
            $index = unserialize($this->getIndex($listUuid));

            return $index['chunk-size'];
        }

        return 0;
    }

    /**
     * @param $listUuid
     *
     * @return mixed
     */
    public function getCounter($listUuid)
    {
        if ($this->existsListInIndex($listUuid)) {
            $index = unserialize($this->getIndex($listUuid));

            return $index['size'];
        }

        return 0;
    }

    /**
     * @param $listUuid
     *
     * @return bool
     */
    protected function existsListInIndex($listUuid)
    {
        return ($this->getIndex($listUuid)) ? true : false;
    }

    /**
     * @param $listUuid
     *
     * @return float
     */
    public function getNumberOfChunks($listUuid)
    {
        if ($this->existsListInIndex($listUuid)) {
            $index = unserialize($this->getIndex($listUuid));

            return $index['chunks'];
        }

        return 0;
    }

    /**
     * @param \Datetime|null $from
     * @param \Datetime|null $to
     *
     * @return array
     */
    public function getIndexInRangeDate(\Datetime $from = null, \Datetime $to = null)
    {
        $results = [];

        if ($index = $this->getIndex()) {
            foreach ($index as $item) {
                $unserializedItem = unserialize($item);
                $createdOn = $unserializedItem['created_on']->format('Y-m-d');
                $from = $from ? $from->format('Y-m-d') : null;
                $to = $to ? $to->format('Y-m-d') : null;
                $firstStatement = ($from) ? $createdOn >= $from : true;
                $secondStatement = ($to) ? $createdOn <= $to : true;

                if ($firstStatement && $secondStatement) {
                    $results[] = $item;
                }
            }
        }

        return $results;
    }

    /**
     * @param $listUuid
     *
     * @return mixed
     */
    public function getTtl($listUuid)<commit_msg>getIndexInRangeDate function fix on AbstractRepository.<commit_after><?php
/**
 * This file is part of the InMemoryList package.
 *
 * (c) <NAME><https://github.com/mauretto78>
 *
 *  For the full copyright and license information, please view the LICENSE
 *  file that was distributed with this source code.
 */

namespace InMemoryList\Infrastructure\Persistance;

use InMemoryList\Infrastructure\Persistance\Exceptions\ListElementDoesNotExistsException;

abstract class AbstractRepository
{
    /**
     * @param $listUuid
     *
     * @return mixed
     */
    public function delete($listUuid)
    {
        $list = $this->findListByUuid($listUuid);

        foreach (array_keys($list) as $elementUuid) {
            $this->deleteElement($listUuid, $elementUuid);
        }
    }

    /**
     * @param $listUuid
     * @param $elementUuid
     *
     * @return mixed
     */
    public function existsElement($listUuid, $elementUuid)
    {
        if (isset($this->findListByUuid($listUuid)[$elementUuid])) {
            return $this->findListByUuid($listUuid)[$elementUuid];
        }

        return false;
    }

    /**
     * @param $listUuid
     * @param $elementUuid
     *
     * @return mixed
     *
     * @throws ListElementDoesNotExistsException
     */
    public function findElement($listUuid, $elementUuid)
    {
        if (!$element = $this->existsElement($listUuid, $elementUuid)) {
            throw new ListElementDoesNotExistsException('Cannot retrieve the element '.$elementUuid.' from the collection in memory.');
        }

        return $element;
    }

    /**
     * @param $listUuid
     *
     * @return mixed
     */
    public function getChunkSize($listUuid)
    {
        if ($this->existsListInIndex($listUuid)) {
            $index = unserialize($this->getIndex($listUuid));

            return $index['chunk-size'];
        }

        return 0;
    }

    /**
     * @param $listUuid
     *
     * @return mixed
     */
    public function getCounter($listUuid)
    {
        if ($this->existsListInIndex($listUuid)) {
            $index = unserialize($this->getIndex($listUuid));

            return $index['size'];
        }

        return 0;
    }

    /**
     * @param $listUuid
     *
     * @return bool
     */
    protected function existsListInIndex($listUuid)
    {
        return ($this->getIndex($listUuid)) ? true : false;
    }

    /**
     * @param $listUuid
     *
     * @return float
     */
    public function getNumberOfChunks($listUuid)
    {
        if ($this->existsListInIndex($listUuid)) {
            $index = unserialize($this->getIndex($listUuid));

            return $index['chunks'];
        }

        return 0;
    }

    /**
     * @param \Datetime|null $from
     * @param \Datetime|null $to
     *
     * @return array
     */
    public function getIndexInRangeDate(\Datetime $from = null, \Datetime $to = null)
    {
        $results = [];

        if ($index = $this->getIndex()) {
            foreach ($index as $key => $item) {
                $unserializedItem = unserialize($item);
                $createdOn = $unserializedItem['created_on']->format('Y-m-d');
                $from = $from ? $from->format('Y-m-d') : null;
                $to = $to ? $to->format('Y-m-d') : null;
                $firstStatement = ($from) ? $createdOn >= $from : true;
                $secondStatement = ($to) ? $createdOn <= $to : true;

                if ($firstStatement && $secondStatement) {
                    $results[$key] = $item;
                }
            }
        }

        return $results;
    }

    /**
     * @param $listUuid
     *
     * @return mixed
     */
    public function getTtl($listUuid)
{'fraction_non_alphanumeric': 0.1360664669027513, 'fraction_numerical': 0.001362026695723236, 'mean_word_length': 1.963276836158192, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 42, 'https://': 2, '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': '6987682', 'n_tokens_mistral': 2239, 'n_tokens_neox': 2175, 'n_words': 432}