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

HttpCache   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 37
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A isNotModified() 0 8 2
A transfer() 0 9 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