Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
13 / 13 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
| ConstantReflection | |
100.00% |
13 / 13 |
|
100.00% |
1 / 1 |
5 | |
100.00% |
1 / 1 |
| parse | |
100.00% |
13 / 13 |
|
100.00% |
1 / 1 |
5 | |||
| 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\Reflection; |
| 16 | |
| 17 | use Pop\Code\Generator; |
| 18 | use Pop\Code\Reflection\Support\TypeNormalizer; |
| 19 | use Pop\Code\Reflection\Support\AttributeCollector; |
| 20 | |
| 21 | /** |
| 22 | * Constant reflection code class |
| 23 | * |
| 24 | * @category Pop |
| 25 | * @package Pop\Code |
| 26 | * @author Nick Sagona, III <dev@noladev.com> |
| 27 | * @copyright Copyright (c) 2009-2027 NOLA Interactive, LLC. |
| 28 | * @license https://www.popphp.org/license New BSD License |
| 29 | * @version 6.0.0 |
| 30 | */ |
| 31 | class ConstantReflection extends AbstractReflection |
| 32 | { |
| 33 | |
| 34 | /** |
| 35 | * Method to parse a constant |
| 36 | * |
| 37 | * @param mixed $code |
| 38 | * @param ?string $name |
| 39 | * @return Generator\ConstantGenerator |
| 40 | */ |
| 41 | public static function parse(mixed $code, ?string $name = null): Generator\ConstantGenerator |
| 42 | { |
| 43 | if ($code->isProtected()) { |
| 44 | $visibility = 'protected'; |
| 45 | } else if ($code->isPrivate()) { |
| 46 | $visibility = 'private'; |
| 47 | } else { |
| 48 | $visibility = 'public'; |
| 49 | } |
| 50 | |
| 51 | $isTyped = $code->hasType(); |
| 52 | $type = $isTyped ? (string) $code->getType() : TypeNormalizer::normalize(strtolower(gettype($code->getValue()))); |
| 53 | |
| 54 | $constant = new Generator\ConstantGenerator($name ?? $code->getName(), $type, $code->getValue()); |
| 55 | $constant->setVisibility($visibility); |
| 56 | $constant->setTyped($isTyped); |
| 57 | |
| 58 | foreach ($code->getAttributes() as $reflectionAttribute) { |
| 59 | $constant->addAttribute(AttributeCollector::build($reflectionAttribute)); |
| 60 | } |
| 61 | |
| 62 | return $constant; |
| 63 | } |
| 64 | |
| 65 | } |