Test Failed
Push — master ( 3b7232...dbe410 )
by Kirill
02:20
created

DirectiveLocation   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 30.76%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 3
dl 0
loc 50
ccs 4
cts 13
cp 0.3076
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A isExecutable() 0 4 1
A isPrivate() 0 4 1
A isAllowedFor() 0 6 1
A getType() 0 4 1
1
<?php
2
/**
3
 * This file is part of Railt package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
declare(strict_types=1);
9
10
namespace Railt\Reflection\Definition\Dependent;
11
12
use Railt\Reflection\Contracts\Definition\Dependent\DirectiveLocation as DirectiveLocationInterface;
13
use Railt\Reflection\Contracts\Definition\TypeDefinition;
14
use Railt\Reflection\Contracts\Type as TypeInterface;
15
use Railt\Reflection\Document;
16
use Railt\Reflection\Type;
17
18
/**
19
 * Class DirectiveLocation
20
 */
21
class DirectiveLocation extends AbstractDependentTypeDefinition implements DirectiveLocationInterface
22
{
23
    /**
24
     * DirectiveLocation constructor.
25
     * @param TypeDefinition $parent
26
     * @param Document $document
27
     * @param string $name
28
     */
29 9
    public function __construct(TypeDefinition $parent, Document $document, string $name)
30
    {
31 9
        \assert(\in_array($name, \array_merge(static::EXECUTABLE_LOCATIONS, static::SDL_LOCATIONS), true));
32
33 9
        parent::__construct($parent, $document, $name);
34 9
    }
35
36
    /**
37
     * @return bool
38
     */
39
    public function isExecutable(): bool
40
    {
41
        return \in_array($this->getName(), static::EXECUTABLE_LOCATIONS, true);
42
    }
43
44
    /**
45
     * @return bool
46
     */
47
    public function isPrivate(): bool
48
    {
49
        return \in_array($this->getName(), static::SDL_LOCATIONS, true);
50
    }
51
52
    /**
53
     * @param TypeInterface $type
54
     * @return bool
55
     */
56
    public function isAllowedFor(TypeInterface $type): bool
57
    {
58
        $location = static::LOCATION_TO_TYPES[$this->getName()] ?? Type::ANY;
59
60
        return $type->instanceOf(Type::of($location));
61
    }
62
63
    /**
64
     * @return TypeInterface
65
     */
66
    public static function getType(): TypeInterface
67
    {
68
        return Type::of(Type::DIRECTIVE_LOCATION);
69
    }
70
}
71