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

Location   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 38
ccs 0
cts 14
cp 0
rs 10
wmc 11

4 Methods

Rating   Name   Duplication   Size   Complexity  
A hasAnomaly() 0 9 3
A __construct() 0 10 6
A getSectorString() 0 3 1
A getShips() 0 3 1
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