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

getParametersToProcess()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
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