| Total Complexity | 6 |
| Total Lines | 78 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 17 | final class ViewSource |
||
| 18 | { |
||
| 19 | /** @var string */ |
||
| 20 | private $filename; |
||
| 21 | |||
| 22 | /** @var string */ |
||
| 23 | private $name; |
||
| 24 | |||
| 25 | /** @var string */ |
||
| 26 | private $namespace; |
||
| 27 | |||
| 28 | /** @var string|null */ |
||
| 29 | private $code = null; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * @param string $filename |
||
| 33 | * @param string $name |
||
| 34 | * @param string $namespace |
||
| 35 | */ |
||
| 36 | public function __construct(string $filename, string $namespace, string $name) |
||
| 37 | { |
||
| 38 | $this->filename = $filename; |
||
| 39 | $this->namespace = $namespace; |
||
| 40 | $this->name = $name; |
||
| 41 | } |
||
| 42 | |||
| 43 | /** |
||
| 44 | * Template namespace. |
||
| 45 | * |
||
| 46 | * @return string |
||
| 47 | */ |
||
| 48 | public function getNamespace(): string |
||
| 49 | { |
||
| 50 | return $this->namespace; |
||
| 51 | } |
||
| 52 | |||
| 53 | /** |
||
| 54 | * Template name. |
||
| 55 | * |
||
| 56 | * @return string |
||
| 57 | */ |
||
| 58 | public function getName(): string |
||
| 59 | { |
||
| 60 | return $this->name; |
||
| 61 | } |
||
| 62 | |||
| 63 | /** |
||
| 64 | * Template filename. |
||
| 65 | * |
||
| 66 | * @return string |
||
| 67 | */ |
||
| 68 | public function getFilename(): string |
||
| 71 | } |
||
| 72 | |||
| 73 | /** |
||
| 74 | * Template code. |
||
| 75 | * |
||
| 76 | * @return string |
||
| 77 | */ |
||
| 78 | public function getCode(): string |
||
| 79 | { |
||
| 80 | return $this->code ?? file_get_contents($this->getFilename()); |
||
| 81 | } |
||
| 82 | |||
| 83 | /** |
||
| 84 | * Get source copy with redefined code. |
||
| 85 | * |
||
| 86 | * @param string $code |
||
| 87 | * @return self |
||
| 88 | */ |
||
| 89 | public function withCode(string $code): ViewSource |
||
| 95 | } |
||
| 96 | } |
||
| 97 |