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