| 1 | <?php |
||
| 5 | class Math implements \Transphporm\TSSFunction { |
||
| 6 | private $mode; |
||
| 7 | |||
| 8 | const ADD = 'add'; |
||
| 9 | const SUBTRACT = 'sub'; |
||
| 10 | const MULTIPLY = 'mult'; |
||
| 11 | const DIVIDE = 'div'; |
||
| 12 | |||
| 13 | public function __construct($mode) { |
||
| 16 | |||
| 17 | public function run(array $args, \DomElement $element) { |
||
| 22 | |||
| 23 | private function getModeResult($val, $prev) { |
||
| 26 | |||
| 27 | private function add($val, $prev) { |
||
| 30 | |||
| 31 | private function sub($val, $prev) { |
||
| 34 | |||
| 35 | private function mult($val, $prev) { |
||
| 38 | |||
| 39 | private function div($val, $prev) { |
||
| 42 | } |
||
| 43 |
If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration: