Passed
Push — dev ( 840a26...5b15b7 )
by Janko
18:04
created

Location::getSectorString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Lib\Map;
6
7
use Doctrine\Common\Collections\Collection;
8
use InvalidArgumentException;
9
use Stu\Orm\Entity\MapInterface;
10
use Stu\Orm\Entity\ShipInterface;
11
use Stu\Orm\Entity\StarSystemMapInterface;
12
13
class Location
14
{
15
    private MapInterface|StarSystemMapInterface $location;
16
17
    public function __construct(?MapInterface $map, ?StarSystemMapInterface $sysMap)
18
    {
19
        if (
20
            $map === null && $sysMap === null
0 ignored issues
show
introduced by
Consider adding parentheses for clarity. Current Interpretation: ($map === null && $sysMa...ull && $sysMap !== null, Probably Intended Meaning: $map === null && ($sysMa...ll && $sysMap !== null)
Loading history...
21
            || $map !== null && $sysMap !== null
22
        ) {
23
            throw new InvalidArgumentException('Either map or systemMap has to be filled');
24
        }
25
26
        $this->location = $map !== null ? $map : $sysMap;
27
    }
28
29
    /**
30
     * @return Collection<int, ShipInterface>
31
     */
32
    public function getShips(): Collection
33
    {
34
        return $this->location->getShips();
35
    }
36
37
    public function getSectorString(): string
38
    {
39
        return $this->location->getSectorString();
40
    }
41
42
    public function hasAnomaly(int $anomalyType): bool
43
    {
44
        foreach ($this->location->getAnomalies() as $anomaly) {
45
            if ($anomaly->getAnomalyType()->getId() === $anomalyType) {
46
                return true;
47
            }
48
        }
49
50
        return false;
51
    }
52
}
53