Test Failed
Push — master ( dbe410...b8c007 )
by Kirill
02:19
created

DirectiveLocation::isAllowedFor()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 0
cts 3
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
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\Common\Verifiable;
16
use Railt\Reflection\Exception\TypeConflictException;
17
use Railt\Reflection\Type;
18
19
/**
20
 * Class DirectiveLocation
21
 */
22
class DirectiveLocation extends AbstractDependentTypeDefinition implements DirectiveLocationInterface, Verifiable
23
{
24
    /**
25
     * @throws \Railt\Io\Exception\ExternalFileException
26
     */
27 View Code Duplication
    public function verify(): void
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
28
    {
29
        $locations = \array_merge(static::EXECUTABLE_LOCATIONS, static::SDL_LOCATIONS);
30
31
        if (! \in_array($this->name, $locations, true)) {
32
            throw $this->error(new TypeConflictException(\sprintf('Invalid name of %s', $this)));
33
        }
34
    }
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
     * @throws \Railt\Io\Exception\ExternalFileException
56
     */
57
    public function isAllowedFor(TypeInterface $type): bool
58
    {
59
        $location = static::LOCATION_TO_TYPES[$this->getName()] ?? Type::ANY;
60
61
        return $type->instanceOf(Type::of($location));
62
    }
63
64
    /**
65
     * @return TypeInterface
66
     * @throws \Railt\Io\Exception\ExternalFileException
67
     */
68
    public static function getType(): TypeInterface
69
    {
70
        return Type::of(Type::DIRECTIVE_LOCATION);
71
    }
72
}
73