Passed
Push — master ( 0971b0...b7d7cf )
by Kirill
03:21
created

DirectiveLocation::verify()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 8
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 8
loc 8
ccs 0
cts 5
cp 0
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
crap 6
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\Type as TypeInterface;
14
use Railt\Reflection\Exception\TypeConflictException;
15
use Railt\Reflection\Type;
16
17
/**
18
 * Class DirectiveLocation
19
 */
20
class DirectiveLocation extends AbstractDependentTypeDefinition implements DirectiveLocationInterface
21
{
22
    /**
23
     * @return bool
24
     */
25
    public function isExecutable(): bool
26
    {
27
        return \in_array($this->getName(), static::EXECUTABLE_LOCATIONS, true);
28
    }
29
30
    /**
31
     * @return bool
32
     */
33
    public function isPrivate(): bool
34
    {
35
        return \in_array($this->getName(), static::SDL_LOCATIONS, true);
36
    }
37
38
    /**
39
     * @param TypeInterface $type
40
     * @return bool
41
     * @throws \Railt\Io\Exception\ExternalFileException
42
     */
43
    public function isAllowedFor(TypeInterface $type): bool
44
    {
45
        $location = static::LOCATION_TO_TYPES[$this->getName()] ?? Type::ANY;
46
47
        return $type->instanceOf(Type::of($location));
48
    }
49
50
    /**
51
     * @return TypeInterface
52
     */
53
    public static function getType(): TypeInterface
54
    {
55
        return Type::of(Type::DIRECTIVE_LOCATION);
56
    }
57
}
58