<commit_before><?php
/**
 * This file is part of the BEAR.QueryRepository package.
 *
 * @license http://opensource.org/licenses/MIT MIT
 */
namespace BEAR\QueryRepository;

use BEAR\RepositoryModule\Annotation\Cacheable;
use BEAR\Resource\ResourceObject;
use Doctrine\Common\Annotations\Reader;
use Ray\Aop\MethodInterceptor;
use Ray\Aop\MethodInvocation;

class CacheInterceptor implements MethodInterceptor
{
    /**
     * @var QueryRepositoryInterface
     */
    private $repository;

    /**
     * @var EtagSetterInterface
     */
    private $setEtag;

    /**
     * @var Reader
     */
    private $reader;

    public function __construct(
        QueryRepositoryInterface $repository,
        EtagSetterInterface $setEtag,
        Reader $annotationReader
    ) {
        $this->repository = $repository;
        $this->setEtag = $setEtag;
        $this->reader = $annotationReader;
    }

    /**
     * {@inheritdoc}
     */
    public function invoke(MethodInvocation $invocation)
    {
        /** @var ResourceObject $ro */
        $ro = $invocation->getThis();
        $stored = $this->repository->get($ro->uri);
        if ($stored) {
            list($ro->uri, $ro->code, $ro->headers, $ro->body, $ro->view) = $stored;

            return $ro;
        }
        /* @var $cacheable Cacheable */
        try {
            /** @var ResourceObject $ro */
            $ro = $invocation->proceed();
            $ro->code === 200 ? $this->repository->put($ro) : $this->repository->purge($ro->uri);
        } catch (\Exception $e) {
            $this->repository->purge($ro->uri);
            throw $e;
        }

        return $ro;
    }
}<commit_msg>remove unused EtagSetter<commit_after><?php
/**
 * This file is part of the BEAR.QueryRepository package.
 *
 * @license http://opensource.org/licenses/MIT MIT
 */
namespace BEAR\QueryRepository;

use BEAR\RepositoryModule\Annotation\Cacheable;
use BEAR\Resource\ResourceObject;
use Doctrine\Common\Annotations\Reader;
use Ray\Aop\MethodInterceptor;
use Ray\Aop\MethodInvocation;

class CacheInterceptor implements MethodInterceptor
{
    /**
     * @var QueryRepositoryInterface
     */
    private $repository;

    /**
     * @var Reader
     */
    private $reader;

    public function __construct(
        QueryRepositoryInterface $repository,
        Reader $annotationReader
    ) {
        $this->repository = $repository;
        $this->reader = $annotationReader;
    }

    /**
     * {@inheritdoc}
     */
    public function invoke(MethodInvocation $invocation)
    {
        /** @var ResourceObject $ro */
        $ro = $invocation->getThis();
        $stored = $this->repository->get($ro->uri);
        if ($stored) {
            list($ro->uri, $ro->code, $ro->headers, $ro->body, $ro->view) = $stored;

            return $ro;
        }
        /* @var $cacheable Cacheable */
        try {
            /** @var ResourceObject $ro */
            $ro = $invocation->proceed();
            $ro->code === 200 ? $this->repository->put($ro) : $this->repository->purge($ro->uri);
        } catch (\Exception $e) {
            $this->repository->purge($ro->uri);
            throw $e;
        }

        return $ro;
    }
}
{'fraction_non_alphanumeric': 0.1453579243513598, 'fraction_numerical': 0.001875586120662707, 'mean_word_length': 2.235591506572295, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 46, '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': '1326175', 'n_tokens_mistral': 957, 'n_tokens_neox': 933, 'n_words': 190}