1 | <?php |
||
13 | class GeezCalculator |
||
14 | { |
||
15 | const ONE = 1; |
||
16 | |||
17 | const HUNDRED = 100; |
||
18 | |||
19 | const TEN_THOUSAND = 10000; |
||
20 | |||
21 | /** |
||
22 | * @var Queue |
||
23 | */ |
||
24 | protected $queue; |
||
25 | |||
26 | /** |
||
27 | * @var int |
||
28 | */ |
||
29 | protected $total; |
||
30 | |||
31 | /** |
||
32 | * @var int |
||
33 | */ |
||
34 | protected $sub_total; |
||
35 | |||
36 | /** |
||
37 | * GeezCalculator constructor. |
||
38 | * |
||
39 | * @param Queue $queue |
||
40 | */ |
||
41 | public function __construct(Queue $queue) |
||
46 | |||
47 | /** |
||
48 | * Do the magic. |
||
49 | */ |
||
50 | public function calculate() |
||
58 | |||
59 | /** |
||
60 | * set the sub total attribute to zero. |
||
61 | */ |
||
62 | protected function resetSubTotalToZero() |
||
66 | |||
67 | /** |
||
68 | * Process a single token from the Queue. |
||
69 | * |
||
70 | * @param $token |
||
71 | */ |
||
72 | protected function processToken($token) |
||
78 | |||
79 | /** |
||
80 | * Fetch the block and separator from the token. |
||
81 | * |
||
82 | * @param $token |
||
83 | * |
||
84 | * @return array |
||
85 | */ |
||
86 | protected function fetchBlockAndSeparator($token) |
||
97 | |||
98 | /** |
||
99 | * Process based on separator. |
||
100 | * |
||
101 | * @param $block |
||
102 | * @param $separator |
||
103 | */ |
||
104 | protected function processBySeparator($block, $separator) |
||
114 | |||
115 | /** |
||
116 | * Add the sub total and the block to total |
||
117 | * and reset sub total to zero. |
||
118 | * |
||
119 | * @param $block |
||
120 | * |
||
121 | * @return void |
||
122 | */ |
||
123 | protected function addToTotal($block) |
||
128 | |||
129 | /** |
||
130 | * Is the leading block? |
||
131 | * |
||
132 | * @param $block |
||
133 | * |
||
134 | * @return bool |
||
135 | */ |
||
136 | protected function isLeading($block) |
||
142 | |||
143 | /** |
||
144 | * Is the value of block zero? |
||
145 | * |
||
146 | * @param $block |
||
147 | * |
||
148 | * @return bool |
||
149 | */ |
||
150 | protected function isBlockZero($block) |
||
154 | |||
155 | /** |
||
156 | * Is a number zero? |
||
157 | * |
||
158 | * @param $number |
||
159 | * |
||
160 | * @return bool |
||
161 | */ |
||
162 | protected function isZero($number) |
||
166 | |||
167 | /** |
||
168 | * Is sub total attribute zero? |
||
169 | * |
||
170 | * @return bool |
||
171 | */ |
||
172 | protected function isSubtotalZero() |
||
176 | |||
177 | /** |
||
178 | * Add number to sun total. |
||
179 | * |
||
180 | * @param $number integer |
||
181 | */ |
||
182 | protected function addToSubTotal($number) |
||
186 | |||
187 | /** |
||
188 | * Is the leading 10k? |
||
189 | * |
||
190 | * @param $block |
||
191 | * |
||
192 | * @return bool |
||
193 | */ |
||
194 | protected function isLeadingTenThousand($block) |
||
200 | |||
201 | /** |
||
202 | * Is the total attribute zero? |
||
203 | * |
||
204 | * @return bool |
||
205 | */ |
||
206 | protected function isTotalZero() |
||
210 | |||
211 | /** |
||
212 | * Multiply the total attribute by ten thousand. |
||
213 | */ |
||
214 | protected function multiplyTotalBy10k() |
||
218 | |||
219 | /** |
||
220 | * Return the calculated ascii number. |
||
221 | * |
||
222 | * @return int |
||
223 | */ |
||
224 | public function getCalculated() |
||
228 | |||
229 | /** |
||
230 | * Update the sub total attribute. |
||
231 | * |
||
232 | * @param $block |
||
233 | */ |
||
234 | protected function updateSubTotal($block) |
||
244 | |||
245 | /** |
||
246 | * Update the sub total attribute. |
||
247 | * |
||
248 | * @param $block |
||
249 | */ |
||
250 | protected function updateTotal($block) |
||
259 | } |
||
260 |