Completed
Push — dev-master ( ccccd1...cfb4f7 )
by Karol
03:20
created

AbstractParametersProcessor   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
c 1
b 0
f 0
dl 0
loc 49
ccs 18
cts 18
cp 1
rs 10
wmc 8

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getParametersToProcess() 0 3 1
A setParametersToProcess() 0 5 1
A needToProcess() 0 3 1
A __construct() 0 4 1
A process() 0 9 3
A getConverter() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Pgs\HashIdBundle\ParametersProcessor;
6
7
use Pgs\HashIdBundle\ParametersProcessor\Converter\ConverterInterface;
8
9
abstract class AbstractParametersProcessor implements ParametersProcessorInterface
10
{
11
    protected $parametersToProcess = [];
12
13
    /**
14
     * @var ConverterInterface
15
     */
16
    protected $converter;
17
18 8
    public function __construct(ConverterInterface $converter, array $parametersToProcess = [])
19
    {
20 8
        $this->converter = $converter;
21 8
        $this->parametersToProcess = $parametersToProcess;
22 8
    }
23
24 2
    public function setParametersToProcess(array $parametersToProcess): ParametersProcessorInterface
25
    {
26 2
        $this->parametersToProcess = $parametersToProcess;
27
28 2
        return $this;
29
    }
30
31 8
    public function getParametersToProcess(): array
32
    {
33 8
        return $this->parametersToProcess;
34
    }
35
36 3
    public function getConverter(): ConverterInterface
37
    {
38 3
        return $this->converter;
39
    }
40
41 7
    public function process(array $parameters): array
42
    {
43 7
        foreach ($this->getParametersToProcess() as $parameter) {
44 5
            if (isset($parameters[$parameter])) {
45 5
                $parameters[$parameter] = $this->processValue($parameters[$parameter]);
46
            }
47
        }
48
49 7
        return $parameters;
50
    }
51
52 4
    public function needToProcess(): bool
53
    {
54 4
        return \count($this->getParametersToProcess()) > 0;
55
    }
56
57
    abstract protected function processValue($value);
58
}
59