| Total Complexity | 11 |
| Total Lines | 56 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 0 | ||
| 1 | <?php |
||
| 7 | class VariableTpl |
||
| 8 | { |
||
| 9 | private $pattern = '/{\s?([\w]+.?[\w]+)\s?\|?\s?([\w]+)?\s?}/is'; |
||
| 10 | private $match = []; |
||
| 11 | private $matches = []; |
||
| 12 | private $replace = ''; |
||
| 13 | private $variable = ''; |
||
| 14 | |||
| 15 | 6 | public function __construct(string $content) |
|
| 16 | { |
||
| 17 | 6 | $this->content = $content; |
|
|
|
|||
| 18 | 6 | $this->variable(); |
|
| 19 | 6 | } |
|
| 20 | |||
| 21 | 6 | public function __toString(): string |
|
| 22 | { |
||
| 23 | 6 | return $this->content; |
|
| 24 | } |
||
| 25 | |||
| 26 | 6 | private function variable(): void |
|
| 27 | { |
||
| 28 | 6 | if (preg_match_all($this->pattern, $this->content, $this->matches, PREG_SET_ORDER)) { |
|
| 29 | 6 | for ($i = 0; $i < count($this->matches); $i++) { |
|
| 30 | 6 | $this->match = $this->matches[$i]; |
|
| 31 | 6 | $this->getVariable(); |
|
| 32 | 6 | $this->replace = '<?php echo('.$this->variable.'); ?>'; |
|
| 33 | 6 | $this->filter('upper'); |
|
| 34 | 6 | $this->content = str_replace($this->match[0], $this->replace, $this->content); |
|
| 35 | }; |
||
| 36 | } |
||
| 37 | 6 | } |
|
| 38 | |||
| 39 | 6 | private function getVariable(): void |
|
| 52 | 6 | } |
|
| 53 | |||
| 54 | 6 | private function filter(string $name): void |
|
| 57 | 6 | } |
|
| 58 | |||
| 59 | 6 | private function upper(): void |
|
| 63 | } |
||
| 64 | 6 | } |
|
| 66 |