Completed
Push — master ( a7c3c6...973485 )
by Peter
04:02
created

EtagHasher::hash()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 9
ccs 7
cts 7
cp 1
rs 9.6666
cc 1
eloc 6
nc 1
nop 2
crap 1
1
<?php
2
/**
3
 * AnimeDb package.
4
 *
5
 * @author    Peter Gribanov <[email protected]>
6
 * @copyright Copyright (c) 2014, Peter Gribanov
7
 * @license   http://opensource.org/licenses/MIT
8
 */
9
namespace AnimeDb\Bundle\CacheTimeKeeperBundle\Service\CacheKeyBuilder;
10
11
use Symfony\Component\HttpFoundation\Request;
12
use Symfony\Component\HttpFoundation\Response;
13
14
class EtagHasher implements EtagHasherInterface
15
{
16
    /**
17
     * @var string
18
     */
19
    const ETAG_SEPARATOR = '|';
20
21
    /**
22
     * @var string
23
     */
24
    protected $algorithm = '';
25
26
    /**
27
     * @param string $algorithm
28
     */
29 2
    public function __construct($algorithm)
30
    {
31 2
        $this->algorithm = $algorithm;
32 2
    }
33
34
    /**
35
     * @param Request $request
36
     * @param Response $response
37
     *
38
     * @return string
39
     */
40 2
    public function hash(Request $request, Response $response)
41
    {
42 2
        return hash(
43 2
            $this->algorithm,
44 2
            $response->getLastModified()->format(\DateTime::ISO8601).
45 2
                self::ETAG_SEPARATOR.
46 2
                http_build_query($request->cookies->all())
47 2
        );
48
    }
49
}
50