RepeatableDirectives::assert()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 3
nc 3
nop 2
1
<?php
2
3
/**
4
 * This file is part of Railt package.
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
declare(strict_types=1);
11
12
namespace Railt\SDL\Spec\Constraint;
13
14
use Phplrt\Contracts\Ast\NodeInterface;
15
use Railt\SDL\Spec\SpecificationInterface;
16
use Railt\SDL\Exception\TypeErrorException;
17
use Phplrt\Source\Exception\NotAccessibleException;
18
use Railt\SDL\Frontend\Ast\Definition\DirectiveDefinitionNode;
19
20
/**
21
 * Class RepeatableDirectives
22
 */
23
class RepeatableDirectives extends Constraint
24
{
25
    /**
26
     * @param NodeInterface $node
27
     * @param SpecificationInterface $spec
28
     * @return void
29
     * @throws TypeErrorException
30
     * @throws NotAccessibleException
31
     * @throws \RuntimeException
32
     */
33
    public static function assert(NodeInterface $node, SpecificationInterface $spec): void
34
    {
35
        if (! $node instanceof DirectiveDefinitionNode) {
36
            return;
37
        }
38
39
        if ($node->repeatable) {
40
            throw TypeErrorException::fromAst(static::notSupported($spec), $node);
41
        }
42
    }
43
}
44