Signer   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A sign() 0 10 3
A check() 0 4 1
1
<?php
2
3
/*
4
 * This file is part of the `liip/LiipImagineBundle` project.
5
 *
6
 * (c) https://github.com/liip/LiipImagineBundle/graphs/contributors
7
 *
8
 * For the full copyright and license information, please view the LICENSE.md
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Liip\ImagineBundle\Imagine\Cache;
13
14
class Signer implements SignerInterface
15
{
16
    /**
17
     * @var string
18
     */
19
    private $secret;
20
21
    /**
22
     * @param string $secret
23
     */
24
    public function __construct($secret)
25
    {
26
        $this->secret = $secret;
27
    }
28
29
    /**
30
     * {@inheritdoc}
31
     */
32
    public function sign($path, array $runtimeConfig = null)
33
    {
34
        if ($runtimeConfig) {
35
            array_walk_recursive($runtimeConfig, function (&$value) {
36
                $value = (string) $value;
37
            });
38
        }
39
40
        return mb_substr(preg_replace('/[^a-zA-Z0-9-_]/', '', base64_encode(hash_hmac('sha256', ltrim($path, '/').(null === $runtimeConfig ?: serialize($runtimeConfig)), $this->secret, true))), 0, 8);
41
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46
    public function check($hash, $path, array $runtimeConfig = null)
47
    {
48
        return $hash === $this->sign($path, $runtimeConfig);
49
    }
50
}
51