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

ColonyMember   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Test Coverage

Coverage 83.33%

Importance

Changes 1
Bugs 1 Features 0
Metric Value
eloc 27
c 1
b 1
f 0
dl 0
loc 69
ccs 20
cts 24
cp 0.8333
rs 10
wmc 14

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A get() 0 4 1
B canBeAccessedFrom() 0 28 7
A getUser() 0 4 1
A getLocation() 0 4 1
A canAccess() 0 14 3
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