Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
14 / 14 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
| FromMetadataType | |
100.00% |
14 / 14 |
|
100.00% |
1 / 1 |
4 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
14 / 14 |
|
100.00% |
1 / 1 |
4 | |||
| 1 | <?php |
| 2 | namespace Apie\Graphql\Types; |
| 3 | |
| 4 | use Apie\Core\Attributes\Description; |
| 5 | use Apie\Core\Metadata\MetadataInterface; |
| 6 | use Apie\Graphql\Concerns\CreatesFromMeta; |
| 7 | use GraphQL\Type\Definition\ObjectType; |
| 8 | use ReflectionAttribute; |
| 9 | |
| 10 | class FromMetadataType extends ObjectType |
| 11 | { |
| 12 | use CreatesFromMeta; |
| 13 | |
| 14 | public function __construct(MetadataInterface $metadata, string $suffix = '') |
| 15 | { |
| 16 | $config = [ |
| 17 | 'name' => ($metadata->toClass()?->getShortName() ?? $metadata->toScalarType()->value) . $suffix, |
| 18 | 'fields' => [ |
| 19 | ], |
| 20 | ]; |
| 21 | |
| 22 | foreach ($metadata->toClass()?->getAttributes(Description::class, ReflectionAttribute::IS_INSTANCEOF) ?? [] as $descriptionAttribute) { |
| 23 | $description = $descriptionAttribute->newInstance(); |
| 24 | $config['description'] = $description->description; |
| 25 | } |
| 26 | |
| 27 | foreach ($metadata->getHashmap() as $name => $field) { |
| 28 | if ($field->isField()) { |
| 29 | $config['fields'][$name] = [ |
| 30 | 'type' => self::createFromField($field), |
| 31 | ]; |
| 32 | } |
| 33 | } |
| 34 | parent::__construct($config); |
| 35 | } |
| 36 | } |