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

ActionParametersCollector::getParameters()   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 0
Metric Value
eloc 1
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
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