ParameterCollection::__clone()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
/**
4
 * This file is part of UnderQuery package.
5
 *
6
 * Copyright (c) 2016 Beniamin Jonatan Šimko
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Phuria\UnderQuery\Parameter;
13
14
/**
15
 * @author Beniamin Jonatan Šimko <[email protected]>
16
 */
17
class ParameterCollection implements ParameterCollectionInterface
18
{
19
    private $parameters;
20
21
    /**
22
     * @param array $parameters
23
     */
24 3
    public function __construct(array $parameters = [])
25
    {
26 3
        $this->parameters = $parameters;
27 3
    }
28
29
    /**
30
     * @inheritdoc
31
     */
32 1
    public function __clone()
33
    {
34 1
        $this->parameters = $this->cloneParameters();
35 1
    }
36
37
    /**
38
     * @return QueryParameterInterface[]
39
     */
40 2
    private function cloneParameters()
41
    {
42 2
        $params = [];
43
44 2
        foreach ($this->parameters as $key => $param) {
45 2
            $params[$key] = clone $param;
46 2
        }
47
48 2
        return $params;
49
    }
50
51
    /**
52
     * @inheritdoc
53
     */
54 1
    public function toArray()
55
    {
56 1
        return array_values($this->cloneParameters());
57
    }
58
59
    /**
60
     * @inheritdoc
61
     */
62 3
    public function getParameter($name)
63
    {
64 3
        if (false === array_key_exists($name, $this->parameters)) {
65 3
            $this->parameters[$name] = new QueryParameter($name);
66 3
        }
67
68 3
        return $this->parameters[$name];
69
    }
70
71
    /**
72
     * @inheritdoc
73
     */
74
    public function setValue($parameterName, $value)
75
    {
76
        $this->getParameter($parameterName)->setValue($value);
77
78
        return $this;
79
    }
80
}