| Total Complexity | 7 |
| Total Lines | 40 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 0 | ||
| 1 | <?php |
||
| 5 | class FuncTpl |
||
| 6 | { |
||
| 7 | private $pattern = '/{\s?func ([\w]+)\((.*?)\)\s?}/is'; |
||
| 8 | private $content; |
||
| 9 | private $match; |
||
| 10 | private $funcName; |
||
| 11 | private $funcArgs; |
||
| 12 | |||
| 13 | 4 | public function __construct(string $content) |
|
| 14 | { |
||
| 15 | 4 | $this->content = $content; |
|
| 16 | 4 | $this->func(); |
|
| 17 | 4 | } |
|
| 18 | |||
| 19 | 4 | public function __toString(): string |
|
| 20 | { |
||
| 21 | 4 | return $this->content; |
|
| 22 | } |
||
| 23 | |||
| 24 | 4 | public function func(): void |
|
| 25 | { |
||
| 26 | 4 | if (preg_match_all($this->pattern, $this->content, $matches, PREG_SET_ORDER)) { |
|
| 27 | 2 | for ($i = 0; $i < count($matches); $i++) { |
|
|
|
|||
| 28 | 2 | $this->match = $matches[$i]; |
|
| 29 | 2 | $this->setFuncName(); |
|
| 30 | 2 | $this->setFuncArgs(); |
|
| 31 | 2 | $content = '<?php echo('.$this->funcName.'('.$this->funcArgs.')); ?>'; |
|
| 32 | 2 | $this->content = str_replace($matches[$i][0], $content, $this->content); |
|
| 33 | }; |
||
| 34 | } |
||
| 35 | 4 | } |
|
| 36 | |||
| 37 | 2 | private function setFuncName() |
|
| 40 | 2 | } |
|
| 41 | |||
| 42 | 2 | private function setFuncArgs() |
|
| 45 | 2 | } |
|
| 46 | } |
||
| 47 |
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: