| Total Complexity | 10 |
| Total Lines | 110 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 19 | class NamedList |
||
| 20 | { |
||
| 21 | /** @var array $list */ |
||
| 22 | protected $list = []; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * Adds an item to the list |
||
| 26 | * |
||
| 27 | * @param string $name |
||
| 28 | * @param mixed $value |
||
| 29 | * |
||
| 30 | * @return $this |
||
| 31 | */ |
||
| 32 | public function add($name, $value = null) |
||
| 37 | } |
||
| 38 | |||
| 39 | /** |
||
| 40 | * Adds items to the list |
||
| 41 | * |
||
| 42 | * @param array $array |
||
| 43 | * |
||
| 44 | * @return $this |
||
| 45 | */ |
||
| 46 | public function addAll(array $array) |
||
| 47 | { |
||
| 48 | $this->list = array_merge($this->list, $array); |
||
| 49 | |||
| 50 | return $this; |
||
| 51 | } |
||
| 52 | |||
| 53 | /** |
||
| 54 | * Clears the list |
||
| 55 | * |
||
| 56 | * @return $this |
||
| 57 | */ |
||
| 58 | public function clear() |
||
| 59 | { |
||
| 60 | $this->list = []; |
||
| 61 | |||
| 62 | return $this; |
||
| 63 | } |
||
| 64 | |||
| 65 | /** |
||
| 66 | * Removes an item from the list |
||
| 67 | * |
||
| 68 | * @param string $name |
||
| 69 | * |
||
| 70 | * @return $this |
||
| 71 | */ |
||
| 72 | public function remove($name) |
||
| 73 | { |
||
| 74 | unset($this->list[$name]); |
||
| 75 | |||
| 76 | return $this; |
||
| 77 | } |
||
| 78 | |||
| 79 | /** |
||
| 80 | * Returns list size |
||
| 81 | * |
||
| 82 | * @return int |
||
| 83 | */ |
||
| 84 | public function count() |
||
| 85 | { |
||
| 86 | return count($this->list); |
||
| 87 | } |
||
| 88 | |||
| 89 | /** |
||
| 90 | * Returns an item with the name from the list |
||
| 91 | * |
||
| 92 | * @param string $name |
||
| 93 | * |
||
| 94 | * @return array|bool|object |
||
| 95 | */ |
||
| 96 | public function get($name) |
||
| 97 | { |
||
| 98 | if (isset($this->list[$name])) { |
||
| 99 | return $this->list[$name]; |
||
| 100 | } |
||
| 101 | |||
| 102 | return false; |
||
| 103 | } |
||
| 104 | |||
| 105 | /** |
||
| 106 | * Returns the list |
||
| 107 | * |
||
| 108 | * @return array |
||
| 109 | */ |
||
| 110 | public function getAll() |
||
| 111 | { |
||
| 112 | return $this->list; |
||
| 113 | } |
||
| 114 | |||
| 115 | /** |
||
| 116 | * Checks if the item exists |
||
| 117 | * |
||
| 118 | * @param object $value |
||
| 119 | * |
||
| 120 | * @return bool |
||
| 121 | */ |
||
| 122 | public function contains($value) |
||
| 129 | } |
||
| 130 | } |
||
| 131 |