Passed
Push — dev ( c12b3a...6ad196 )
by Janko
24:31 queued 10:07
created

SpacecraftLocationTrait::getMapRegion()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3.1406

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 7
c 1
b 0
f 0
nc 3
nop 0
dl 0
loc 13
ccs 6
cts 8
cp 0.75
crap 3.1406
rs 10
1
<?php
2
3
namespace Stu\Component\Spacecraft\Trait;
4
5
use Stu\Orm\Entity\ColonyInterface;
6
use Stu\Orm\Entity\LayerInterface;
7
use Stu\Orm\Entity\MapInterface;
8
use Stu\Orm\Entity\MapRegionInterface;
9
use Stu\Orm\Entity\StarSystemInterface;
10
use Stu\Orm\Entity\StarSystemMapInterface;
11
12
trait SpacecraftLocationTrait
13
{
14
    use SpacecraftTrait;
15
16 5
    public function getPosX(): int
17
    {
18 5
        return $this->getThis()->getLocation()->getX();
19
    }
20
21 5
    public function getPosY(): int
22
    {
23 5
        return $this->getThis()->getLocation()->getY();
24
    }
25
26 8
    public function getMap(): ?MapInterface
27
    {
28 8
        $location = $this->getThis()->getLocation();
29
30 8
        if ($location instanceof MapInterface) {
31 6
            return $location;
32
        }
33
34 2
        return $location->getSystem()->getMap();
35
    }
36
37 9
    public function getStarsystemMap(): ?StarSystemMapInterface
38
    {
39 9
        if ($this->getThis()->getLocation() instanceof StarSystemMapInterface) {
40 5
            return $this->getThis()->getLocation();
41
        }
42
43 6
        return null;
44
    }
45
46 3
    public function getLayer(): ?LayerInterface
47
    {
48 3
        return $this->getThis()->getLocation()->getLayer();
49
    }
50
51 2
    public function getMapRegion(): ?MapRegionInterface
52
    {
53 2
        $systemMap = $this->getStarsystemMap();
54 2
        if ($systemMap !== null) {
55
            return null;
56
        }
57
58 2
        $map = $this->getMap();
59 2
        if ($map === null) {
60
            return null;
61
        }
62
63 2
        return $map->getMapRegion();
64
    }
65
66
    public function isOverColony(): ?ColonyInterface
67
    {
68
        return $this->getStarsystemMap() !== null ? $this->getStarsystemMap()->getColony() : null;
69
    }
70
71 2
    public function isOverSystem(): ?StarSystemInterface
72
    {
73 2
        $location = $this->getThis()->getLocation();
74 2
        if ($location instanceof StarSystemMapInterface) {
75
            return null;
76
        }
77
78 2
        return $location->getSystem();
79
    }
80
81 6
    public function getSystem(): ?StarSystemInterface
82
    {
83 6
        return $this->getStarsystemMap() !== null ? $this->getStarsystemMap()->getSystem() : null;
84
    }
85
86 4
    public function getSectorString(): string
87
    {
88 4
        return $this->getThis()->getLocation()->getSectorString();
89
    }
90
}
91