Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
8 / 8 |
|
100.00% |
7 / 7 |
CRAP | |
100.00% |
1 / 1 |
| AbstractGenerator | |
100.00% |
8 / 8 |
|
100.00% |
7 / 7 |
7 | |
100.00% |
1 / 1 |
| setIndent | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| getIndent | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| hasIndent | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| printIndent | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getOutput | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| hasOutput | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| isRendered | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| render | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
| 1 | <?php |
| 2 | /** |
| 3 | * Pop PHP Framework (https://www.popphp.org/) |
| 4 | * |
| 5 | * @link https://github.com/popphp/popphp-framework |
| 6 | * @author Nick Sagona, III <dev@noladev.com> |
| 7 | * @copyright Copyright (c) 2009-2026 NOLA Interactive, LLC. |
| 8 | * @license https://www.popphp.org/license New BSD License |
| 9 | */ |
| 10 | |
| 11 | /** |
| 12 | * @namespace |
| 13 | */ |
| 14 | namespace Pop\Code\Generator; |
| 15 | |
| 16 | /** |
| 17 | * Abstract generator class |
| 18 | * |
| 19 | * @category Pop |
| 20 | * @package Pop\Code |
| 21 | * @author Nick Sagona, III <dev@noladev.com> |
| 22 | * @copyright Copyright (c) 2009-2026 NOLA Interactive, LLC. |
| 23 | * @license https://www.popphp.org/license New BSD License |
| 24 | * @version 5.0.5 |
| 25 | */ |
| 26 | abstract class AbstractGenerator implements GeneratorInterface |
| 27 | { |
| 28 | |
| 29 | /** |
| 30 | * Code indent spaces |
| 31 | * @var int |
| 32 | */ |
| 33 | protected int $indent = 4; |
| 34 | |
| 35 | /** |
| 36 | * Output string |
| 37 | * @var ?string |
| 38 | */ |
| 39 | protected ?string $output = null; |
| 40 | |
| 41 | /** |
| 42 | * Set the indent |
| 43 | * |
| 44 | * @param int $indent |
| 45 | * @return AbstractGenerator |
| 46 | */ |
| 47 | public function setIndent(int $indent): AbstractGenerator |
| 48 | { |
| 49 | $this->indent = $indent; |
| 50 | return $this; |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * Get the indent |
| 55 | * |
| 56 | * @return int |
| 57 | */ |
| 58 | public function getIndent(): int |
| 59 | { |
| 60 | return $this->indent; |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * Has indent |
| 65 | * |
| 66 | * @return bool |
| 67 | */ |
| 68 | public function hasIndent(): bool |
| 69 | { |
| 70 | return (!empty($this->indent)); |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * Print the indent |
| 75 | * |
| 76 | * @return string |
| 77 | */ |
| 78 | public function printIndent(): string |
| 79 | { |
| 80 | return str_repeat(' ', $this->indent); |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * Get the output |
| 85 | * |
| 86 | * @return string |
| 87 | */ |
| 88 | public function getOutput(): string |
| 89 | { |
| 90 | return $this->output; |
| 91 | } |
| 92 | |
| 93 | /** |
| 94 | * Has output |
| 95 | * |
| 96 | * @return bool |
| 97 | */ |
| 98 | public function hasOutput(): bool |
| 99 | { |
| 100 | return ($this->output !== null); |
| 101 | } |
| 102 | |
| 103 | /** |
| 104 | * Is rendered (alias to hasOutput()) |
| 105 | * |
| 106 | * @return bool |
| 107 | */ |
| 108 | public function isRendered(): bool |
| 109 | { |
| 110 | return ($this->output !== null); |
| 111 | } |
| 112 | |
| 113 | /** |
| 114 | * Render method |
| 115 | * |
| 116 | * @return string |
| 117 | */ |
| 118 | abstract public function render(): string; |
| 119 | |
| 120 | } |