<commit_before><?php
/**
 * Created by IntelliJ IDEA.
 * User: Kevin
 * Date: 21.06.2015
 * Time: 16:19
 */

namespace Kevinrob\GuzzleCache;


use Psr\Http\Message\ResponseInterface;

class CacheEntry
{

    /**
     * @var ResponseInterface
     */
    protected $response;

    /**
     * @var \DateTime
     */
    protected $staleAt;

    /**
     * @var \DateTime
     */
    protected $staleIfErrorTo;

    /**
     * Cached timestamp of staleAt variable
     * @var int
     */
    private $timestampStale;


    /**
     * @param ResponseInterface $response
     * @param \DateTime $staleAt
     * @param \DateTime|null $staleIfErrorTo if null, detected with the headers (RFC 5861)
     */
    public function __construct(ResponseInterface $response, \DateTime $staleAt, \DateTime $staleIfErrorTo = null)
    {
        $this->response = $response;
        $this->staleAt  = $staleAt;

        if ($staleIfErrorTo === null) {
            foreach ($response->getHeader("Cache-Control") as $directive) {
                $matches = [];
                if (preg_match('/^stale-if-error=([0-9]*)$/', $directive, $matches)) {
                    $this->staleIfErrorTo = new \DateTime('+' . $matches[1] . 'seconds');
                    break;
                }
            }
        } else {
            $this->staleIfErrorTo = $staleIfErrorTo;
        }
    }

    /**
     * @return ResponseInterface
     */
    public function getResponse()
    {<commit_msg>#8 if "Cache-Control:must-revalidate" => no stale cache<commit_after><?php
/**
 * Created by IntelliJ IDEA.
 * User: Kevin
 * Date: 21.06.2015
 * Time: 16:19
 */

namespace Kevinrob\GuzzleCache;


use Psr\Http\Message\ResponseInterface;

class CacheEntry
{

    /**
     * @var ResponseInterface
     */
    protected $response;

    /**
     * @var \DateTime
     */
    protected $staleAt;

    /**
     * @var \DateTime
     */
    protected $staleIfErrorTo;

    /**
     * Cached timestamp of staleAt variable
     * @var int
     */
    private $timestampStale;


    /**
     * @param ResponseInterface $response
     * @param \DateTime $staleAt
     * @param \DateTime|null $staleIfErrorTo if null, detected with the headers (RFC 5861)
     */
    public function __construct(ResponseInterface $response, \DateTime $staleAt, \DateTime $staleIfErrorTo = null)
    {
        $this->response = $response;
        $this->staleAt  = $staleAt;

        if ($staleIfErrorTo === null) {
            $headersCacheControl = $response->getHeader("Cache-Control");

            if (!in_array("must-revalidate", $headersCacheControl)) {
                foreach ($headersCacheControl as $directive) {
                    $matches = [];
                    if (preg_match('/^stale-if-error=([0-9]*)$/', $directive, $matches)) {
                        $this->staleIfErrorTo = new \DateTime('+' . $matches[1] . 'seconds');
                        break;
                    }
                }
            }
        } else {
            $this->staleIfErrorTo = $staleIfErrorTo;
        }
    }

    /**
     * @return ResponseInterface
     */
    public function getResponse()
    {
{'fraction_non_alphanumeric': 0.13448056086679414, 'fraction_numerical': 0.0124282982791587, 'mean_word_length': 1.8984302862419207, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 14, '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': '3992930', 'n_tokens_mistral': 988, 'n_tokens_neox': 929, 'n_words': 198}