Completed
Pull Request — 1.x (#55)
by Akihito
11:32 queued 10:17
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.1481

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 4
cts 6
cp 0.6667
rs 9.9666
c 0
b 0
f 0
cc 2
nc 2
nop 0
crap 2.1481
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 15
    public function __construct(ResourceStorageInterface $storage)
17
    {
18 15
        $this->storage = $storage;
19 15
    }
20
21
    /**
22
     * {@inheritdoc}
23
     */
24 4
    public function isNotModified(array $server) : bool
25
    {
26 4
        if (! isset($server['HTTP_IF_NONE_MATCH'])) {
27 1
            return false;
28
        }
29
30 3
        return $this->storage->hasEtag($server['HTTP_IF_NONE_MATCH']);
31
    }
32
33
    /**
34
     * {@inheritdoc}
35
     */
36 1
    public function transfer()
37
    {
38 1
        if (PHP_SAPI === 'cli') {
39 1
            echo '304 Not Modified' . PHP_EOL . PHP_EOL;
40
41 1
            return;
42
        }
43
        \http_response_code(304);
44
    }
45
}
46