Completed
Push — master ( 789220...9af5c5 )
by Jonathan
04:43
created

EnvelopeEncryptingPoolDecorator   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%
Metric Value
wmc 2
lcom 1
cbo 2
dl 0
loc 45
ccs 15
cts 15
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 13 1
A decorate() 0 10 1
1
<?php
2
namespace Jsq\Cache;
3
4
use Psr\Cache\CacheItemInterface;
5
use Psr\Cache\CacheItemPoolInterface;
6
7
class EnvelopeEncryptingPoolDecorator extends EncryptingPoolDecorator
8
{
9
    /** @var resource|string */
10
    private $certificate;
11
    /** @var string */
12
    private $key;
13
    /** @var null|string */
14
    private $passPhrase;
15
    /** @var string */
16
    private $cipher;
17
18
    /**
19
     * @param CacheItemPoolInterface $decorated
20
     * @param string|resource $certificate
21
     * @param string $key
22
     * @param string|null $passPhrase
23
     * @param string $cipher
24
     *
25
     * @throws \Psr\Cache\InvalidArgumentException
26
     */
27 441
    public function __construct(
28
        CacheItemPoolInterface $decorated,
29
        $certificate,
30
        $key,
31
        $passPhrase = null,
32
        $cipher = 'aes-256-cbc'
33
    ) {
34 441
        parent::__construct($decorated);
35 441
        $this->cipher = $cipher;
36 441
        $this->certificate = $certificate;
37 441
        $this->key = $key;
38 441
        $this->passPhrase = $passPhrase;
39 441
    }
40
41 135
    protected function decorate(CacheItemInterface $inner)
42
    {
43 135
        return new EnvelopeEncryptingItemDecorator(
44 135
            $inner,
45 135
            $this->certificate,
46 135
            $this->key,
47 135
            $this->passPhrase,
48 135
            $this->cipher
49 135
        );
50
    }
51
}
52