Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
15 / 15 |
|
100.00% |
7 / 7 |
CRAP | |
100.00% |
1 / 1 |
| PropertiesTrait | |
100.00% |
15 / 15 |
|
100.00% |
7 / 7 |
13 | |
100.00% |
1 / 1 |
| addProperties | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
| addProperty | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| getProperty | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
3 | |||
| getProperties | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| hasProperty | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
2 | |||
| hasProperties | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| removeProperty | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
3 | |||
| 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\Traits; |
| 16 | |
| 17 | use Pop\Code\Generator\PropertyGenerator; |
| 18 | |
| 19 | /** |
| 20 | * Properties trait |
| 21 | * |
| 22 | * @category Pop |
| 23 | * @package Pop\Code |
| 24 | * @author Nick Sagona, III <dev@noladev.com> |
| 25 | * @copyright Copyright (c) 2009-2027 NOLA Interactive, LLC. |
| 26 | * @license https://www.popphp.org/license New BSD License |
| 27 | * @version 6.0.0 |
| 28 | */ |
| 29 | trait PropertiesTrait |
| 30 | { |
| 31 | |
| 32 | /** |
| 33 | * Array of property generator objects |
| 34 | * @var array |
| 35 | */ |
| 36 | protected array $properties = []; |
| 37 | |
| 38 | /** |
| 39 | * Add class properties |
| 40 | * |
| 41 | * @param array $properties |
| 42 | * @return static |
| 43 | */ |
| 44 | public function addProperties(array $properties): static |
| 45 | { |
| 46 | foreach ($properties as $property) { |
| 47 | $this->addProperty($property); |
| 48 | } |
| 49 | |
| 50 | return $this; |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * Add a class property |
| 55 | * |
| 56 | * @param PropertyGenerator $property |
| 57 | * @return static |
| 58 | */ |
| 59 | public function addProperty(PropertyGenerator $property): static |
| 60 | { |
| 61 | $this->properties[$property->getName()] = $property; |
| 62 | return $this; |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * Get a class property |
| 67 | * |
| 68 | * @param mixed $property |
| 69 | * @return PropertyGenerator|null |
| 70 | */ |
| 71 | public function getProperty(mixed $property): PropertyGenerator|null |
| 72 | { |
| 73 | $p = ($property instanceof PropertyGenerator) ? $property->getName() : $property; |
| 74 | return (isset($this->properties[$p])) ? $this->properties[$p] : null; |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * Get all properties |
| 79 | * |
| 80 | * @return array |
| 81 | */ |
| 82 | public function getProperties(): array |
| 83 | { |
| 84 | return $this->properties; |
| 85 | } |
| 86 | |
| 87 | /** |
| 88 | * Has a class property |
| 89 | * |
| 90 | * @param mixed $property |
| 91 | * @return bool |
| 92 | */ |
| 93 | public function hasProperty(mixed $property): bool |
| 94 | { |
| 95 | $p = ($property instanceof PropertyGenerator) ? $property->getName() : $property; |
| 96 | return (isset($this->properties[$p])); |
| 97 | } |
| 98 | |
| 99 | /** |
| 100 | * Has properties |
| 101 | * |
| 102 | * @return bool |
| 103 | */ |
| 104 | public function hasProperties(): bool |
| 105 | { |
| 106 | return (!empty($this->properties)); |
| 107 | } |
| 108 | |
| 109 | /** |
| 110 | * Remove a class property |
| 111 | * |
| 112 | * @param mixed $property |
| 113 | * @return static |
| 114 | */ |
| 115 | public function removeProperty(mixed $property): static |
| 116 | { |
| 117 | $p = ($property instanceof PropertyGenerator) ? $property->getName() : $property; |
| 118 | if (isset($this->properties[$p])) { |
| 119 | unset($this->properties[$p]); |
| 120 | } |
| 121 | return $this; |
| 122 | } |
| 123 | |
| 124 | } |