Passed
Pull Request — master (#15)
by Alexander
02:10
created

ActionParametersCollector::addParameter()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 4.074

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 7
ccs 5
cts 6
cp 0.8333
rs 10
c 0
b 0
f 0
cc 4
nc 4
nop 1
crap 4.074
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Middleware\Dispatcher\ActionParametersCollector;
6
7
class ActionParametersCollector implements ActionParametersCollectorInterface
8
{
9
    private array $params;
10
11 16
    public function __construct(array $params = [])
12
    {
13 16
        $this->params = $params;
14 16
    }
15
16 1
    public function addParameter(array $parameter): void
17
    {
18 1
        foreach ($parameter as $key => $value) {
19 1
            if (is_int($key)) {
20
                $this->params[] = $parameter;
21 1
            } elseif (is_string($key)) {
22 1
                $this->params[$key] = $value;
23
            }
24
        }
25 1
    }
26
27
    public function hasParameter($parameter): bool
28
    {
29
        return in_array($this->params, $parameter, true);
30
    }
31
32
    public function removeParameter($parameter): void
33
    {
34
        unset($this->params[array_search($parameter, $this->params, true)]);
35
    }
36
37 8
    public function getParameters(): array
38
    {
39 8
        return $this->params;
40
    }
41
}
42