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-2023 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-2023 NOLA Interactive, LLC. (http://www.nolainteractive.com) |
23 | * @license http://www.popphp.org/license New BSD License |
24 | * @version 4.1.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 $visibility = 'public'; |
36 | |
37 | /** |
38 | * Static flag |
39 | * @var boolean |
40 | */ |
41 | protected $static = false; |
42 | |
43 | /** |
44 | * Set the visibility |
45 | * |
46 | * @param string $visibility |
47 | * @return AbstractClassElementGenerator |
48 | */ |
49 | public function setVisibility($visibility = 'public') |
50 | { |
51 | $visibility = strtolower($visibility); |
52 | |
53 | if (!in_array($visibility, ['public', 'protected', 'private'])) { |
54 | throw new Exception("Error: The visibility '" . $visibility . "' is not allowed."); |
55 | } |
56 | |
57 | $this->visibility = $visibility; |
58 | return $this; |
59 | } |
60 | |
61 | /** |
62 | * Set the visibility to public |
63 | * |
64 | * @return AbstractClassElementGenerator |
65 | */ |
66 | public function setAsPublic() |
67 | { |
68 | return $this->setVisibility('public'); |
69 | } |
70 | |
71 | /** |
72 | * Set the visibility to protected |
73 | * |
74 | * @return AbstractClassElementGenerator |
75 | */ |
76 | public function setAsProtected() |
77 | { |
78 | return $this->setVisibility('protected'); |
79 | } |
80 | |
81 | /** |
82 | * Set the visibility to public |
83 | * |
84 | * @return AbstractClassElementGenerator |
85 | */ |
86 | public function setAsPrivate() |
87 | { |
88 | return $this->setVisibility('private'); |
89 | } |
90 | |
91 | /** |
92 | * Is visibility public |
93 | * |
94 | * @return boolean |
95 | */ |
96 | public function isPublic() |
97 | { |
98 | return ($this->visibility == 'public'); |
99 | } |
100 | |
101 | /** |
102 | * Set the visibility to protected |
103 | * |
104 | * @return boolean |
105 | */ |
106 | public function isProtected() |
107 | { |
108 | return ($this->visibility == 'protected'); |
109 | } |
110 | |
111 | /** |
112 | * Set the visibility to private |
113 | * |
114 | * @return boolean |
115 | */ |
116 | public function isPrivate() |
117 | { |
118 | return ($this->visibility == 'private'); |
119 | } |
120 | |
121 | /** |
122 | * Get the visibility |
123 | * |
124 | * @return string |
125 | */ |
126 | public function getVisibility() |
127 | { |
128 | return $this->visibility; |
129 | } |
130 | |
131 | /** |
132 | * Set the static flag |
133 | * |
134 | * @param boolean $static |
135 | * @return AbstractClassElementGenerator |
136 | */ |
137 | public function setAsStatic($static = true) |
138 | { |
139 | $this->static = (boolean)$static; |
140 | return $this; |
141 | } |
142 | |
143 | /** |
144 | * Get the static flag |
145 | * |
146 | * @return boolean |
147 | */ |
148 | public function isStatic() |
149 | { |
150 | return $this->static; |
151 | } |
152 | |
153 | } |