Completed
Push — master ( 8eb127...4ccffb )
by Beniamin
02:30
created

ParameterCollection   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 84.21%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 1
dl 0
loc 54
ccs 16
cts 19
cp 0.8421
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A __clone() 0 4 1
A cloneParameters() 0 10 2
A toArray() 0 4 1
A getParameter() 0 8 2
1
<?php
2
3
/**
4
 * This file is part of Phuria SQL Builder 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\SQLBuilder\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 2
    public function __construct(array $parameters = [])
25
    {
26 2
        $this->parameters = $parameters;
27 2
    }
28
29
    /**
30
     * @inheritdoc
31
     */
32
    public function __clone()
33
    {
34
        $this->parameters = $this->cloneParameters();
35
    }
36
37
    /**
38
     * @return QueryParameterInterface[]
39
     */
40 1
    private function cloneParameters()
41
    {
42 1
        $params = [];
43
44 1
        foreach ($this->parameters as $key => $param) {
45 1
            $params[$key] = clone $param;
46 1
        }
47
48 1
        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 2
    public function getParameter($name)
63
    {
64 2
        if (false === array_key_exists($name, $this->parameters)) {
65 2
            $this->parameters[$name] = new QueryParameter($name);
66 2
        }
67
68 2
        return $this->parameters[$name];
69
    }
70
}