Completed
Pull Request — 1.x (#55)
by Akihito
11:32 queued 10:17
created

HttpCache   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 84.62%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 37
ccs 11
cts 13
cp 0.8462
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 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