Completed
Pull Request — master (#118)
by Christoffer
02:25
created

ValidatesNamesTrait   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
dl 0
loc 15
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A validateName() 0 8 2
1
<?php
2
3
namespace Digia\GraphQL\SchemaValidator\Rule;
4
5
use Digia\GraphQL\Error\InvariantException;
6
use Digia\GraphQL\SchemaValidator\ValidationContextInterface;
7
use function Digia\GraphQL\Util\isValidNameError;
8
9
trait ValidatesNamesTrait
10
{
11
    /**
12
     * @param ValidationContextInterface $context
13
     * @param mixed                      $node
14
     * @throws InvariantException
15
     */
16
    protected function validateName(ValidationContextInterface $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