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 | declare(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 | */ |
| 15 | namespace 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 | */ |
| 27 | abstract class AbstractClassElementGenerator extends AbstractGenerator |
| 28 | { |
| 29 | |
| 30 | use Traits\NameTrait, Traits\DocblockTrait, Traits\AttributesTrait; |
| 31 | |
| 32 | /** |
| 33 | * Visibility |
| 34 | * @var string |
| 35 | */ |
| 36 | protected string $visibility = 'public'; |
| 37 | |
| 38 | /** |
| 39 | * Static flag |
| 40 | * @var bool |
| 41 | */ |
| 42 | protected bool $static = false; |
| 43 | |
| 44 | /** |
| 45 | * Valid visibility values |
| 46 | * @var array |
| 47 | */ |
| 48 | protected const VALID_VISIBILITIES = ['public', 'protected', 'private']; |
| 49 | |
| 50 | /** |
| 51 | * Set the visibility |
| 52 | * |
| 53 | * @param string $visibility |
| 54 | * @throws Exception |
| 55 | * @return AbstractClassElementGenerator |
| 56 | */ |
| 57 | public function setVisibility(string $visibility = 'public'): AbstractClassElementGenerator |
| 58 | { |
| 59 | $visibility = strtolower($visibility); |
| 60 | |
| 61 | if (!in_array($visibility, self::VALID_VISIBILITIES)) { |
| 62 | throw new Exception("Error: The visibility '" . $visibility . "' is not allowed."); |
| 63 | } |
| 64 | |
| 65 | $this->visibility = $visibility; |
| 66 | return $this; |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * Set the visibility to public |
| 71 | * |
| 72 | * @throws Exception |
| 73 | * @return AbstractClassElementGenerator |
| 74 | */ |
| 75 | public function setAsPublic(): AbstractClassElementGenerator |
| 76 | { |
| 77 | return $this->setVisibility('public'); |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * Set the visibility to protected |
| 82 | * |
| 83 | * @throws Exception |
| 84 | * @return AbstractClassElementGenerator |
| 85 | */ |
| 86 | public function setAsProtected(): AbstractClassElementGenerator |
| 87 | { |
| 88 | return $this->setVisibility('protected'); |
| 89 | } |
| 90 | |
| 91 | /** |
| 92 | * Set the visibility to public |
| 93 | * |
| 94 | * @throws Exception |
| 95 | * @return AbstractClassElementGenerator |
| 96 | */ |
| 97 | public function setAsPrivate(): AbstractClassElementGenerator |
| 98 | { |
| 99 | return $this->setVisibility('private'); |
| 100 | } |
| 101 | |
| 102 | /** |
| 103 | * Is visibility public |
| 104 | * |
| 105 | * @return bool |
| 106 | */ |
| 107 | public function isPublic(): bool |
| 108 | { |
| 109 | return ($this->visibility == 'public'); |
| 110 | } |
| 111 | |
| 112 | /** |
| 113 | * Set the visibility to protected |
| 114 | * |
| 115 | * @return bool |
| 116 | */ |
| 117 | public function isProtected(): bool |
| 118 | { |
| 119 | return ($this->visibility == 'protected'); |
| 120 | } |
| 121 | |
| 122 | /** |
| 123 | * Set the visibility to private |
| 124 | * |
| 125 | * @return bool |
| 126 | */ |
| 127 | public function isPrivate(): bool |
| 128 | { |
| 129 | return ($this->visibility == 'private'); |
| 130 | } |
| 131 | |
| 132 | /** |
| 133 | * Get the visibility |
| 134 | * |
| 135 | * @return string |
| 136 | */ |
| 137 | public function getVisibility(): string |
| 138 | { |
| 139 | return $this->visibility; |
| 140 | } |
| 141 | |
| 142 | /** |
| 143 | * Set the static flag |
| 144 | * |
| 145 | * @param bool $static |
| 146 | * @return AbstractClassElementGenerator |
| 147 | */ |
| 148 | public function setAsStatic(bool $static = true): AbstractClassElementGenerator |
| 149 | { |
| 150 | $this->static = $static; |
| 151 | return $this; |
| 152 | } |
| 153 | |
| 154 | /** |
| 155 | * Get the static flag |
| 156 | * |
| 157 | * @return bool |
| 158 | */ |
| 159 | public function isStatic(): bool |
| 160 | { |
| 161 | return $this->static; |
| 162 | } |
| 163 | |
| 164 | } |