Property   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 100
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 9
c 1
b 0
f 1
lcom 1
cbo 0
dl 0
loc 100
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A replace() 0 6 1
A add() 0 8 2
A set() 0 6 1
A get() 0 8 2
A has() 0 4 1
A all() 0 4 1
1
<?php
2
/*
3
 * This file is part of the Borobudur-DependencyInjection package.
4
 *
5
 * (c) Hexacodelabs <http://hexacodelabs.com>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Borobudur\DependencyInjection\Definition;
12
13
/**
14
 * @author      Iqbal Maulana <[email protected]>
15
 * @created     8/8/15
16
 */
17
class Property
18
{
19
    /**
20
     * @var array
21
     */
22
    private $properties = array();
23
24
    /**
25
     * Constructor.
26
     *
27
     * @param array $properties
28
     */
29
    public function __construct(array $properties = array())
30
    {
31
        $this->properties = $properties;
32
    }
33
34
    /**
35
     * Clear and replace with sets of properties.
36
     *
37
     * @param array $properties
38
     *
39
     * @return Property
40
     */
41
    public function replace(array $properties)
42
    {
43
        $this->properties = array();
44
45
        return $this->add($properties);
46
    }
47
48
    /**
49
     * Add parameter.
50
     *
51
     * @param array $properties
52
     *
53
     * @return static
54
     */
55
    public function add(array $properties)
56
    {
57
        foreach ($properties as $name => $value) {
58
            $this->set($name, $value);
59
        }
60
61
        return $this;
62
    }
63
64
    /**
65
     * Set property.
66
     *
67
     * @param string $name
68
     * @param mixed  $value
69
     *
70
     * @return static
71
     */
72
    public function set($name, $value)
73
    {
74
        $this->properties[$name] = $value;
75
76
        return $this;
77
    }
78
79
    /**
80
     * Get property value.
81
     *
82
     * @param string $name
83
     *
84
     * @return mixed|null
85
     */
86
    public function get($name)
87
    {
88
        if (array_key_exists($name, $this->properties)) {
89
            return $this->properties[$name];
90
        }
91
92
        return null;
93
    }
94
95
    /**
96
     * Check if has property with specified name.
97
     *
98
     * @param string $name
99
     *
100
     * @return bool
101
     */
102
    public function has($name)
103
    {
104
        return array_key_exists($name, $this->properties);
105
    }
106
107
    /**
108
     * Get all properties.
109
     *
110
     * @return array
111
     */
112
    public function all()
113
    {
114
        return $this->properties;
115
    }
116
}
117