Passed
Push — dev ( 7914d2...bbc331 )
by Janko
10:29
created

SpacecraftLocationTrait   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Test Coverage

Coverage 87.1%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 23
dl 0
loc 72
ccs 27
cts 31
cp 0.871
rs 10
c 1
b 0
f 0
wmc 14

10 Methods

Rating   Name   Duplication   Size   Complexity  
A getLayer() 0 3 1
A getMap() 0 9 2
A getPosY() 0 3 1
A getPosX() 0 3 1
A getStarsystemMap() 0 7 2
A getSystem() 0 3 1
A isOverColony() 0 3 1
A isOverSystem() 0 8 2
A getSectorString() 0 3 1
A getMapRegion() 0 8 2
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 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(): ?Map
27
    {
28 8
        $location = $this->getThis()->getLocation();
29
30 8
        if ($location instanceof Map) {
31 6
            return $location;
32
        }
33
34 2
        return $location->getSystem()->getMap();
35
    }
36
37 9
    public function getStarsystemMap(): ?StarSystemMap
38
    {
39 9
        if ($this->getThis()->getLocation() instanceof StarSystemMap) {
40 5
            return $this->getThis()->getLocation();
41
        }
42
43 6
        return null;
44
    }
45
46 3
    public function getLayer(): ?Layer
47
    {
48 3
        return $this->getThis()->getLocation()->getLayer();
49
    }
50
51 2
    public function getMapRegion(): ?MapRegion
52
    {
53 2
        $systemMap = $this->getStarsystemMap();
54 2
        if ($systemMap !== null) {
55
            return null;
56
        }
57
58 2
        return $this->getMap()?->getMapRegion();
59
    }
60
61
    public function isOverColony(): ?Colony
62
    {
63
        return $this->getStarsystemMap()?->getColony();
64
    }
65
66 2
    public function isOverSystem(): ?StarSystem
67
    {
68 2
        $location = $this->getThis()->getLocation();
69 2
        if ($location instanceof StarSystemMap) {
70
            return null;
71
        }
72
73 2
        return $location->getSystem();
74
    }
75
76 6
    public function getSystem(): ?StarSystem
77
    {
78 6
        return $this->getStarsystemMap()?->getSystem();
79
    }
80
81 4
    public function getSectorString(): string
82
    {
83 4
        return $this->getThis()->getLocation()->getSectorString();
84
    }
85
}
86