| Total Complexity | 5 |
| Total Lines | 35 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 0 | ||
| 1 | <?php declare(strict_types=1); |
||
| 19 | final class ParsedConstantsBuilder implements ConstantsBuilder |
||
| 20 | { |
||
| 21 | /** @var string[] */ |
||
| 22 | private const TYPES = [ |
||
| 23 | 'integer' => 'int', |
||
| 24 | 'double' => 'float', |
||
| 25 | 'string' => 'string', |
||
| 26 | ]; |
||
| 27 | |||
| 28 | 44 | public function __construct(private readonly VisibilityBuilder $visibilityBuilder) |
|
|
|
|||
| 29 | { |
||
| 30 | } |
||
| 31 | |||
| 32 | /** |
||
| 33 | * @param ClassConst[] $classConstants |
||
| 34 | * @return Constant[] |
||
| 35 | */ |
||
| 36 | 29 | public function build(array $classConstants): array |
|
| 37 | { |
||
| 38 | 29 | return array_map(fn (ClassConst $constant): Constant => new Constant( |
|
| 39 | 16 | (string) $constant->consts[0]->name, |
|
| 40 | 16 | TypeDeclaration::from($this->determineType($constant->consts[0])), |
|
| 41 | 16 | $this->visibilityBuilder->build($constant) |
|
| 42 | ), $classConstants); |
||
| 43 | } |
||
| 44 | |||
| 45 | 16 | private function determineType(Const_ $constant): ?string |
|
| 46 | { |
||
| 47 | 16 | if (property_exists($constant->value, 'value')) { |
|
| 48 | 15 | return self::TYPES[\gettype($constant->value->value)]; |
|
| 49 | } |
||
| 50 | 12 | if (! $constant->value instanceof ConstFetch) { |
|
| 51 | 1 | return null; |
|
| 52 | } |
||
| 53 | 11 | return 'bool'; |
|
| 54 | } |
||
| 56 |