Completed
Pull Request — 1.x (#55)
by Akihito
20:51
created

HttpCache::transfer()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 4
cts 4
cp 1
rs 9.9666
c 0
b 0
f 0
cc 2
nc 2
nop 0
crap 2
1
<?php
2
/**
3
 * This file is part of the BEAR.QueryRepository package.
4
 *
5
 * @license http://opensource.org/licenses/MIT MIT
6
 */
7
namespace BEAR\QueryRepository;
8
9
final class HttpCache implements HttpCacheInterface
10
{
11
    /**
12
     * @var ResourceStorageInterface
13
     */
14
    private $storage;
15
16
    public function __construct(ResourceStorageInterface $storage)
17
    {
18
        $this->storage = $storage;
19
    }
20
21
    /**
22
     * {@inheritdoc}
23
     */
24
    public function isNotModified(array $server) : bool
25
    {
26 14
        if (! isset($server['HTTP_IF_NONE_MATCH'])) {
27
            return false;
28 14
        }
29 14
30
        return $this->storage->hasEtag($server['HTTP_IF_NONE_MATCH']);
31
    }
32
33
    /**
34 3
     * {@inheritdoc}
35
     */
36 3
    public function transfer()
37 1
    {
38
        if (PHP_SAPI === 'cli') {
39 2
            echo '304 Not Modified' . PHP_EOL . PHP_EOL;
40
41 2
            return;
42
        }
43
        \http_response_code(304);
44
    }
45
}
46