Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
15 / 15 |
|
100.00% |
10 / 10 |
CRAP | |
100.00% |
1 / 1 |
AbstractClassElementGenerator | |
100.00% |
15 / 15 |
|
100.00% |
10 / 10 |
11 | |
100.00% |
1 / 1 |
setVisibility | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
2 | |||
setAsPublic | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setAsProtected | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setAsPrivate | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
isPublic | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
isProtected | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
isPrivate | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getVisibility | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setAsStatic | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
isStatic | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | /** |
3 | * Pop PHP Framework (http://www.popphp.org/) |
4 | * |
5 | * @link https://github.com/popphp/popphp-framework |
6 | * @author Nick Sagona, III <dev@nolainteractive.com> |
7 | * @copyright Copyright (c) 2009-2024 NOLA Interactive, LLC. (http://www.nolainteractive.com) |
8 | * @license http://www.popphp.org/license New BSD License |
9 | */ |
10 | |
11 | /** |
12 | * @namespace |
13 | */ |
14 | namespace Pop\Code\Generator; |
15 | |
16 | /** |
17 | * Abstract class generator class |
18 | * |
19 | * @category Pop |
20 | * @package Pop\Code |
21 | * @author Nick Sagona, III <dev@nolainteractive.com> |
22 | * @copyright Copyright (c) 2009-2024 NOLA Interactive, LLC. (http://www.nolainteractive.com) |
23 | * @license http://www.popphp.org/license New BSD License |
24 | * @version 5.0.0 |
25 | */ |
26 | abstract class AbstractClassElementGenerator extends AbstractGenerator |
27 | { |
28 | |
29 | use Traits\NameTrait, Traits\DocblockTrait; |
30 | |
31 | /** |
32 | * Visibility |
33 | * @var string |
34 | */ |
35 | protected string $visibility = 'public'; |
36 | |
37 | /** |
38 | * Static flag |
39 | * @var bool |
40 | */ |
41 | protected bool $static = false; |
42 | |
43 | /** |
44 | * Set the visibility |
45 | * |
46 | * @param string $visibility |
47 | * @throws Exception |
48 | * @return AbstractClassElementGenerator |
49 | */ |
50 | public function setVisibility(string $visibility = 'public'): AbstractClassElementGenerator |
51 | { |
52 | $visibility = strtolower($visibility); |
53 | |
54 | if (!in_array($visibility, ['public', 'protected', 'private'])) { |
55 | throw new Exception("Error: The visibility '" . $visibility . "' is not allowed."); |
56 | } |
57 | |
58 | $this->visibility = $visibility; |
59 | return $this; |
60 | } |
61 | |
62 | /** |
63 | * Set the visibility to public |
64 | * |
65 | * @throws Exception |
66 | * @return AbstractClassElementGenerator |
67 | */ |
68 | public function setAsPublic(): AbstractClassElementGenerator |
69 | { |
70 | return $this->setVisibility('public'); |
71 | } |
72 | |
73 | /** |
74 | * Set the visibility to protected |
75 | * |
76 | * @throws Exception |
77 | * @return AbstractClassElementGenerator |
78 | */ |
79 | public function setAsProtected(): AbstractClassElementGenerator |
80 | { |
81 | return $this->setVisibility('protected'); |
82 | } |
83 | |
84 | /** |
85 | * Set the visibility to public |
86 | * |
87 | * @throws Exception |
88 | * @return AbstractClassElementGenerator |
89 | */ |
90 | public function setAsPrivate(): AbstractClassElementGenerator |
91 | { |
92 | return $this->setVisibility('private'); |
93 | } |
94 | |
95 | /** |
96 | * Is visibility public |
97 | * |
98 | * @return bool |
99 | */ |
100 | public function isPublic(): bool |
101 | { |
102 | return ($this->visibility == 'public'); |
103 | } |
104 | |
105 | /** |
106 | * Set the visibility to protected |
107 | * |
108 | * @return bool |
109 | */ |
110 | public function isProtected(): bool |
111 | { |
112 | return ($this->visibility == 'protected'); |
113 | } |
114 | |
115 | /** |
116 | * Set the visibility to private |
117 | * |
118 | * @return bool |
119 | */ |
120 | public function isPrivate(): bool |
121 | { |
122 | return ($this->visibility == 'private'); |
123 | } |
124 | |
125 | /** |
126 | * Get the visibility |
127 | * |
128 | * @return string |
129 | */ |
130 | public function getVisibility(): string |
131 | { |
132 | return $this->visibility; |
133 | } |
134 | |
135 | /** |
136 | * Set the static flag |
137 | * |
138 | * @param bool $static |
139 | * @return AbstractClassElementGenerator |
140 | */ |
141 | public function setAsStatic(bool $static = true): AbstractClassElementGenerator |
142 | { |
143 | $this->static = $static; |
144 | return $this; |
145 | } |
146 | |
147 | /** |
148 | * Get the static flag |
149 | * |
150 | * @return bool |
151 | */ |
152 | public function isStatic(): bool |
153 | { |
154 | return $this->static; |
155 | } |
156 | |
157 | } |