Passed
Push — 0.4.0 ( 434eea...cba0fe )
by Anton
03:50
created

Group::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 0
1
<?php
2
3
/**
4
 * @package Framework\Template
5
 * @author Anton Romanov
6
 * @copyright Copyright (c) 2015-2016, Anton Romanov
7
 * @link http://cadmium-cms.com
8
 */
9
10
namespace Template {
11
12
	class Group {
13
14
		protected $items = [], $count = 0;
15
16
		/**
17
		 * Constructor
18
		 */
19
20
		public function __construct() {
21
22
			// nothing here
23
		}
24
25
		/**
26
		 * Cloner
27
		 */
28
29
		public function __clone() {
30
31
			foreach ($this->items as $name => $item) $this->items[$name] = clone $item;
32
		}
33
34
		/**
35
		 * Add an item
36
		 *
37
		 * @return the current group object
38
		 */
39
40
		public function addItem(Block $item) : Group {
41
42
 			$this->items[] = $item; $this->count++;
43
44
 			return $this;
45
 		}
46
47
		/**
48
		 * Add multiple items
49
		 *
50
		 * @return the current group object
51
		 */
52
53
		public function addItems(array $items) : Group {
54
55
 			foreach ($items as $item) if ($item instanceof Block) $this->addItem($item);
56
57
 			return $this;
58
 		}
59
60
		/**
61
		 * Clear the items list
62
		 *
63
		 * @return the current group object
64
		 */
65
66
		 public function removeItems() : Group {
67
68
 			$this->items = []; $this->count = 0;
69
70
 			return $this;
71
 		}
72
73
		/**
74
		 * Set items list
75
		 *
76
		 * @return the current group object
77
		 */
78
79
		public function setItems(array $items) : Group {
80
81
 			$this->removeItems(); $this->addItems($items);
82
83
 			return $this;
84
 		}
85
86
		/**
87
		 * Get the items list
88
		 */
89
90
		public function getItems() : array {
91
92
 			return $this->items;
93
 		}
94
95
		/**
96
		 * Get the items count
97
		 */
98
99
		 public function getCount() : int {
100
101
 			return $this->count;
102
 		}
103
104
		/**
105
		 * Get the group contents
106
		 */
107
108
		public function getContents() : string {
109
110
			$contents = '';
111
112
			# Process items
113
114
			foreach ($this->items as $block) $contents .= $block->getContents();
115
116
			# ------------------------
117
118
			return $contents;
119
		}
120
	}
121
}
122