Issues (158)

src/NodeParser/ScalarNodeParser.php (1 issue)

Labels
Severity
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Jerowork\GraphqlAttributeSchema\NodeParser;
6
7
use Generator;
8
use GraphQL\Type\Definition\ScalarType;
9
use Jerowork\GraphqlAttributeSchema\Attribute\Scalar;
10
use Jerowork\GraphqlAttributeSchema\Node\ScalarNode;
11
use Override;
12
use ReflectionClass;
13
use ReflectionMethod;
14
15
/**
16
 * @internal
17
 */
18
final readonly class ScalarNodeParser implements NodeParser
0 ignored issues
show
A parse error occurred: Syntax error, unexpected T_READONLY, expecting T_CLASS on line 18 at column 6
Loading history...
19
{
20
    use GetAttributeTrait;
21
    use RetrieveNameForTypeTrait;
22
23
    /**
24
     * @throws ParseException
25
     */
26 5
    #[Override]
27
    public function parse(string $attribute, ReflectionClass $class, ?ReflectionMethod $method): Generator
28
    {
29 5
        if ($attribute !== Scalar::class) {
30 3
            return;
31
        }
32
33 4
        if ($class->getParentClass() === false || $class->getParentClass()->getName() !== ScalarType::class) {
34 1
            throw ParseException::missingExtends($class->getName(), ScalarType::class);
35
        }
36
37 3
        $attribute = $this->getAttribute($class, Scalar::class);
38
39 3
        yield new ScalarNode(
40 3
            $class->getName(),
41 3
            $this->retrieveNameForType($class, $attribute),
42 3
            $attribute->description,
43 3
            $attribute->alias,
44 3
        );
45
    }
46
}
47