Passed
Pull Request — master (#118)
by Christoffer
03:28 queued 01:12
created

ValidatesNamesTrait::validateName()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 3
nc 2
nop 2
1
<?php
2
3
namespace Digia\GraphQL\SchemaValidator\Rule;
4
5
use Digia\GraphQL\Error\InvariantException;
6
use Digia\GraphQL\SchemaValidator\ValidationContext;
7
use function Digia\GraphQL\Util\isValidNameError;
8
9
trait ValidatesNamesTrait
10
{
11
    /**
12
     * @param ValidationContext $context
13
     * @param mixed             $node
14
     * @throws InvariantException
15
     */
16
    protected function validateName(ValidationContext $context, $node): void
17
    {
18
        // Ensure names are valid, however introspection types opt out.
19
        /** @noinspection PhpUndefinedMethodInspection */
20
        $error = isValidNameError($node->getName(), $node);
21
22
        if (null !== $error) {
23
            $context->reportError($error);
24
        }
25
    }
26
}
27