Passed
Branch 0.4.0 (deb4fd)
by Anton
03:02
created

Loop::__clone()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

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 2
nc 1
nop 0
1
<?php
2
3
namespace Template {
4
5
	class Loop {
6
7
		private $block = null, $items = null;
8
9
		/**
10
		 * Constructor
11
		 */
12
13
		public function __construct(string $contents = '') {
14
15
			$this->block = new Block($contents); $this->items = new Block;
16
		}
17
18
		/**
19
		 * Add an item
20
		 *
21
		 * @return the current loop object
22
		 */
23
24
		public function addItem(array $data) : Loop {
25
26
			$this->items->addItem((clone $this->block)->setArray($data));
27
28
			return $this;
29
		}
30
31
		/**
32
		 * Add multiple items
33
		 *
34
		 * @return the current loop object
35
		 */
36
37
		public function addItems(array $items) : Loop {
38
39
			foreach ($items as $item) if (is_array($item)) $this->addItem($item);
40
41
			return $this;
42
		}
43
44
		/**
45
		 * Clear the items list
46
		 *
47
		 * @return the current loop object
48
		 */
49
50
		public function removeItems() : Loop {
51
52
			$this->items->removeItems();
53
54
			return $this;
55
		}
56
57
		/**
58
		 * Set items list
59
		 *
60
		 * @return the current loop object
61
		 */
62
63
		public function setItems(array $items) : Loop {
64
65
			$this->removeItems(); $this->addItems($items);
66
67
			return $this;
68
		}
69
70
		/**
71
		 * Get the items list
72
		 */
73
74
		public function getItems() : array {
75
76
			return $this->items->getItems();
77
		}
78
79
		/**
80
		 * Get the items count
81
		 */
82
83
		public function getCount() : int {
84
85
			return $this->items->getCount();
86
		}
87
88
		/**
89
		 * Get the loop contents
90
		 */
91
92
		public function getContents() : string {
93
94
			return $this->items->getContents();
95
		}
96
97
		/**
98
		 * Cloner
99
		 */
100
101
		public function __clone() {
102
103
			$this->items = clone $this->items;
104
		}
105
	}
106
}
107