Passed
Push — master ( 97ec3d...2b008e )
by Janko
06:04
created

ColonyMember::getLocation()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Stu\Lib\Interaction\Member;
4
5
use Stu\Component\Anomaly\Type\AnomalyTypeEnum;
6
use Stu\Lib\Interaction\InteractionCheckType;
7
use Stu\Module\Ship\Lib\TholianWebUtilInterface;
8
use Stu\Orm\Entity\Colony;
9
use Stu\Orm\Entity\Map;
10
use Stu\Orm\Entity\StarSystemMap;
11
use Stu\Orm\Entity\User;
12
13
class ColonyMember implements InteractionMemberInterface
14
{
15 4
    public function __construct(
16
        private TholianWebUtilInterface $tholianWebUtil,
17
        private Colony $colony
18 4
    ) {}
19
20 2
    #[\Override]
21
    public function get(): Colony
22
    {
23 2
        return $this->colony;
24
    }
25
26 2
    #[\Override]
27
    public function canAccess(
28
        InteractionMemberInterface $other,
29
        callable $shouldCheck
30
    ): ?InteractionCheckType {
31
32
        if (
33 2
            $shouldCheck(InteractionCheckType::EXPECT_SOURCE_UNBLOCKED)
34 2
            && $this->colony->isBlocked()
35
        ) {
36
            return InteractionCheckType::EXPECT_SOURCE_UNBLOCKED;
37
        }
38
39 2
        return null;
40
    }
41
42 2
    #[\Override]
43
    public function canBeAccessedFrom(
44
        InteractionMemberInterface $other,
45
        callable $shouldCheck
46
    ): ?InteractionCheckType {
47
48
        if (
49 2
            $shouldCheck(InteractionCheckType::EXPECT_TARGET_DOCKED_OR_NO_ION_STORM)
50 2
            && $this->colony->getLocation()->hasAnomaly(AnomalyTypeEnum::ION_STORM)
51
        ) {
52
            return InteractionCheckType::EXPECT_TARGET_DOCKED_OR_NO_ION_STORM;
53
        }
54
55
        if (
56 2
            $shouldCheck(InteractionCheckType::EXPECT_TARGET_ALSO_IN_FINISHED_WEB)
57 2
            && $this->tholianWebUtil->isTargetOutsideFinishedTholianWeb($other->get(), $this->colony)
58
        ) {
59
            return InteractionCheckType::EXPECT_TARGET_ALSO_IN_FINISHED_WEB;
60
        }
61
62
        if (
63 2
            $shouldCheck(InteractionCheckType::EXPECT_TARGET_UNBLOCKED)
64 2
            && $this->colony->isBlocked()
65
        ) {
66
            return InteractionCheckType::EXPECT_TARGET_UNBLOCKED;
67
        }
68
69 2
        return null;
70
    }
71
72 4
    #[\Override]
73
    public function getLocation(): Map|StarSystemMap
74
    {
75 4
        return $this->colony->getLocation();
76
    }
77
78 2
    #[\Override]
79
    public function getUser(): ?User
80
    {
81 2
        return $this->colony->getUser();
82
    }
83
}
84