Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
30 / 30
100.00% covered (success)
100.00%
14 / 14
CRAP
100.00% covered (success)
100.00%
1 / 1
AbstractClassGenerator
100.00% covered (success)
100.00%
30 / 30
100.00% covered (success)
100.00%
14 / 14
26
100.00% covered (success)
100.00%
1 / 1
 addConstants
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
2
 addConstant
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getConstant
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
3
 hasConstant
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
2
 hasConstants
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getConstants
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 removeConstant
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
3
 addMethods
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
2
 addMethod
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getMethod
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
3
 hasMethod
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
2
 hasMethods
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getMethods
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 removeMethod
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
3
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 class 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 AbstractClassGenerator extends AbstractGenerator
28{
29
30    use Traits\NameTrait, Traits\NamespaceTrait, Traits\DocblockTrait, Traits\AttributesTrait;
31
32    /**
33     * Array of constant generator objects
34     * @var array
35     */
36    protected array $constants = [];
37
38    /**
39     * Array of method generator objects
40     * @var array
41     */
42    protected array $methods = [];
43
44    /**
45     * Add constants
46     *
47     * @param  array $constants
48     * @return AbstractClassGenerator
49     */
50    public function addConstants(array $constants): AbstractClassGenerator
51    {
52        foreach ($constants as $constant) {
53            $this->addConstant($constant);
54        }
55        return $this;
56    }
57
58    /**
59     * Add a constant
60     *
61     * @param  ConstantGenerator $constant
62     * @return AbstractClassGenerator
63     */
64    public function addConstant(ConstantGenerator $constant): AbstractClassGenerator
65    {
66        $this->constants[$constant->getName()] = $constant;
67        return $this;
68    }
69
70    /**
71     * Get a constant
72     *
73     * @param  mixed $constant
74     * @return ConstantGenerator|null
75     */
76    public function getConstant(mixed $constant): ConstantGenerator|null
77    {
78        $c = ($constant instanceof ConstantGenerator) ? $constant->getName() : $constant;
79        return (isset($this->constants[$c])) ? $this->constants[$c] : null;
80    }
81
82    /**
83     * Has a constant
84     *
85     * @param  mixed $constant
86     * @return bool
87     */
88    public function hasConstant(mixed $constant): bool
89    {
90        $c = ($constant instanceof ConstantGenerator) ? $constant->getName() : $constant;
91        return (isset($this->constants[$c]));
92    }
93
94    /**
95     * Has constants
96     *
97     * @return bool
98     */
99    public function hasConstants(): bool
100    {
101        return (!empty($this->constants));
102    }
103
104    /**
105     * Get all constants
106     *
107     * @return array
108     */
109    public function getConstants(): array
110    {
111        return $this->constants;
112    }
113
114    /**
115     * Remove a constant
116     *
117     * @param  mixed $constant
118     * @return AbstractClassGenerator
119     */
120    public function removeConstant(mixed $constant): AbstractClassGenerator
121    {
122        $c = ($constant instanceof ConstantGenerator) ? $constant->getName() : $constant;
123        if (isset($this->constants[$c])) {
124            unset($this->constants[$c]);
125        }
126        return $this;
127    }
128
129    /**
130     * Add methods
131     *
132     * @param  array $methods
133     * @return AbstractClassGenerator
134     */
135    public function addMethods(array $methods): AbstractClassGenerator
136    {
137        foreach ($methods as $method) {
138            $this->addMethod($method);
139        }
140        return $this;
141    }
142
143    /**
144     * Add a method
145     *
146     * @param  MethodGenerator $method
147     * @return AbstractClassGenerator
148     */
149    public function addMethod(MethodGenerator $method): AbstractClassGenerator
150    {
151        $this->methods[$method->getName()] = $method;
152        return $this;
153    }
154
155    /**
156     * Get a method
157     *
158     * @param  mixed $method
159     * @return MethodGenerator|null
160     */
161    public function getMethod(mixed $method): MethodGenerator|null
162    {
163        $m = ($method instanceof MethodGenerator) ? $method->getName() : $method;
164        return (isset($this->methods[$m])) ? $this->methods[$m] : null;
165    }
166
167    /**
168     * Has a method
169     *
170     * @param  mixed $method
171     * @return bool
172     */
173    public function hasMethod(mixed $method): bool
174    {
175        $m = ($method instanceof MethodGenerator) ? $method->getName() : $method;
176        return (isset($this->methods[$m]));
177    }
178
179    /**
180     * Has methods
181     *
182     * @return bool
183     */
184    public function hasMethods(): bool
185    {
186        return (!empty($this->methods));
187    }
188
189    /**
190     * Get all methods
191     *
192     * @return array
193     */
194    public function getMethods(): array
195    {
196        return $this->methods;
197    }
198
199    /**
200     * Remove a method
201     *
202     * @param  mixed $method
203     * @return AbstractClassGenerator
204     */
205    public function removeMethod(mixed $method): AbstractClassGenerator
206    {
207        $m = ($method instanceof MethodGenerator) ? $method->getName() : $method;
208        if (isset($this->methods[$m])) {
209            unset($this->methods[$m]);
210        }
211        return $this;
212    }
213
214}