Passed
Push — dev ( 0aa780...31f66c )
by Janko
11:20
created

SpacecraftMember::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 0
nc 1
nop 3
dl 0
loc 5
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 Override;
0 ignored issues
show
Bug introduced by
The type Override was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use Stu\Component\Spacecraft\Nbs\NbsUtilityInterface;
7
use Stu\Lib\Interaction\InteractionCheckType;
8
use Stu\Module\Ship\Lib\TholianWebUtilInterface;
9
use Stu\Orm\Entity\MapInterface;
10
use Stu\Orm\Entity\SpacecraftInterface;
11
use Stu\Orm\Entity\StarSystemMapInterface;
12
use Stu\Orm\Entity\UserInterface;
13
14
class SpacecraftMember implements InteractionMemberInterface
15
{
16 15
    public function __construct(
17
        private NbsUtilityInterface $nbsUtility,
18
        private TholianWebUtilInterface $tholianWebUtil,
19
        private SpacecraftInterface $spacecraft
20 15
    ) {}
21
22
    #[Override]
23
    public function get(): SpacecraftInterface
24
    {
25
        return $this->spacecraft;
26
    }
27
28 13
    #[Override]
29
    public function canAccess(
30
        InteractionMemberInterface $other,
31
        callable $shouldCheck
32
    ): ?InteractionCheckType {
33
34
        if (
35 13
            $shouldCheck(InteractionCheckType::EXPECT_SOURCE_UNSHIELDED)
36 13
            && $this->spacecraft->getShieldState()
37
        ) {
38
            return InteractionCheckType::EXPECT_SOURCE_UNSHIELDED;
39
        }
40
41
        if (
42 13
            $shouldCheck(InteractionCheckType::EXPECT_SOURCE_UNCLOAKED)
43 13
            && $this->spacecraft->getCloakState()
44
        ) {
45
            return InteractionCheckType::EXPECT_SOURCE_UNCLOAKED;
46
        }
47
48
        if (
49 13
            $shouldCheck(InteractionCheckType::EXPECT_SOURCE_TACHYON)
50 13
            && $other instanceof SpacecraftMember
51 13
            && $other->get()->getCloakState()
52 13
            && !$this->nbsUtility->isTachyonActive($this->spacecraft)
53
        ) {
54
            return InteractionCheckType::EXPECT_SOURCE_TACHYON;
55
        }
56
57 13
        return null;
58
    }
59
60 12
    #[Override]
61
    public function canBeAccessedFrom(
62
        InteractionMemberInterface $other,
63
        bool $isFriend,
64
        callable $shouldCheck
65
    ): ?InteractionCheckType {
66
67
        if (
68 12
            $shouldCheck(InteractionCheckType::EXPECT_TARGET_UNSHIELDED)
69 12
            && $this->spacecraft->getShieldState() && !$isFriend
70
        ) {
71
            return InteractionCheckType::EXPECT_TARGET_UNSHIELDED;
72
        }
73
74
        if (
75 12
            $shouldCheck(InteractionCheckType::EXPECT_TARGET_UNCLOAKED)
76 12
            && $this->spacecraft->getCloakState()
77
        ) {
78
            return InteractionCheckType::EXPECT_TARGET_UNCLOAKED;
79
        }
80
81
        if (
82 12
            $shouldCheck(InteractionCheckType::EXPECT_TARGET_ALSO_IN_FINISHED_WEB)
83 12
            && $this->tholianWebUtil->isTargetOutsideFinishedTholianWeb($other->get(), $this->spacecraft)
84
        ) {
85
            return InteractionCheckType::EXPECT_TARGET_ALSO_IN_FINISHED_WEB;
86
        }
87
88 12
        return null;
89
    }
90
91 15
    #[Override]
92
    public function getLocation(): MapInterface|StarSystemMapInterface
93
    {
94 15
        return $this->spacecraft->getLocation();
95
    }
96
97 15
    #[Override]
98
    public function getUser(): ?UserInterface
99
    {
100 15
        return $this->spacecraft->getUser();
101
    }
102
}
103