PropertyBag   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 0
loc 60
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A set() 0 6 1
A get() 0 8 2
A add() 0 12 2
A getIterator() 0 4 1
1
<?php
2
3
/*
4
 * This file is part of the eluceo/iCal package.
5
 *
6
 * (c) Markus Poerschke <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace Eluceo\iCal;
13
14
class PropertyBag implements \IteratorAggregate
15
{
16
    /**
17
     * @var array
18
     */
19
    protected $elements = [];
20
21
    /**
22
     * Creates a new Property with $name, $value and $params.
23
     *
24
     * @param       $name
25
     * @param       $value
26
     * @param array $params
27
     *
28
     * @return $this
29
     */
30 35
    public function set($name, $value, $params = [])
31
    {
32 35
        $this->add(new Property($name, $value, $params));
33
34 35
        return $this;
35
    }
36
37
    /**
38
     * @return Property|null
39
     */
40 7
    public function get(string $name)
41
    {
42 7
        if (isset($this->elements[$name])) {
43 7
            return $this->elements[$name];
44
        }
45
46 1
        return null;
47
    }
48
49
    /**
50
     * Adds a Property. If Property already exists an Exception will be thrown.
51
     *
52
     * @return $this
53
     *
54
     * @throws \Exception
55
     */
56 37
    public function add(Property $property)
57
    {
58 37
        $name = $property->getName();
59
60 37
        if (isset($this->elements[$name])) {
61 1
            throw new \Exception("Property with name '{$name}' already exists");
62
        }
63
64 37
        $this->elements[$name] = $property;
65
66 37
        return $this;
67
    }
68
69 29
    public function getIterator()
70
    {
71 29
        return new \ArrayObject($this->elements);
72
    }
73
}
74