Passed
Push — dev ( 91186a...20d5e2 )
by Janko
05:17
created

SpacecraftLocationTrait::getStarsystemMap()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

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