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

HasLocations   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 40%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 46
ccs 4
cts 10
cp 0.4
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getLocations() 0 4 1
A getLocation() 0 4 1
A hasLocation() 0 4 1
A withLocation() 0 8 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\Behaviour;
11
12
use Railt\Reflection\Contracts\Definition\Behaviour\ProvidesLocations;
13
use Railt\Reflection\Contracts\Definition\Dependent\DirectiveLocation;
14
15
/**
16
 * Trait HasLocations
17
 * @mixin ProvidesLocations
18
 */
19
trait HasLocations
20
{
21
    /**
22
     * @var array|DirectiveLocation[]
23
     */
24
    protected $locations = [];
25
26
    /**
27
     * @return iterable|DirectiveLocation[]
28
     */
29
    public function getLocations(): iterable
30
    {
31
        return \array_values($this->locations);
32
    }
33
34
    /**
35
     * @param string $name
36
     * @return null|DirectiveLocation
37
     */
38
    public function getLocation(string $name): ?DirectiveLocation
39
    {
40
        return $this->locations[$name] ?? null;
41
    }
42
43
    /**
44
     * @param string $name
45
     * @return bool
46
     */
47
    public function hasLocation(string $name): bool
48
    {
49
        return isset($this->locations[$name]);
50
    }
51
52
    /**
53
     * @param DirectiveLocation ...$locations
54
     * @return ProvidesLocations|$this
55
     */
56 9
    public function withLocation(DirectiveLocation ...$locations): ProvidesLocations
57
    {
58 9
        foreach ($locations as $location) {
59 9
            $this->locations[$location->getName()] = $location;
60
        }
61
62 9
        return $this;
63
    }
64
}
65