TransferInformation::isOtherGoodTransferPossible()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 3
nc 3
nop 0
dl 0
loc 5
ccs 4
cts 4
cp 1
crap 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Lib\Transfer;
6
7
use Stu\Lib\Transfer\Wrapper\StorageEntityWrapperInterface;
8
use Stu\Orm\Entity\Colony;
9
use Stu\Orm\Entity\Ship;
10
use Stu\Orm\Entity\Spacecraft;
11
12
class TransferInformation
13
{
14
    private EntityWithStorageInterface $source;
15
    private EntityWithStorageInterface $target;
16
17 13
    public function __construct(
18
        private TransferTypeEnum $currentType,
19
        private StorageEntityWrapperInterface $sourceWrapper,
20
        private StorageEntityWrapperInterface $targetWrapper,
21
        private bool $isUnload,
22
        private bool $isFriend
23
    ) {
24 13
        $this->source = $sourceWrapper->get();
25 13
        $this->target = $targetWrapper->get();
26
    }
27
28 13
    public function isCommodityTransferPossible(bool $isOtherTypeRequired = true): bool
29
    {
30 13
        return !($isOtherTypeRequired
31 13
            && $this->currentType === TransferTypeEnum::COMMODITIES);
32
    }
33
34 13
    public function isCrewTransferPossible(bool $isOtherTypeRequired = true): bool
35
    {
36
        if (
37 13
            $isOtherTypeRequired
38 13
            && $this->currentType === TransferTypeEnum::CREW
39
        ) {
40 4
            return false;
41
        }
42
43
        if (
44 9
            $this->target instanceof Spacecraft
45 9
            && $this->target->hasUplink()
0 ignored issues
show
Bug introduced by
The method hasUplink() does not exist on Stu\Lib\Transfer\EntityWithStorageInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

45
            && $this->target->/** @scrutinizer ignore-call */ hasUplink()

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
46
        ) {
47
            return true;
48
        }
49
50 9
        return $this->target->getUser() === $this->source->getUser();
51
    }
52
53 13
    public function isTorpedoTransferPossible(bool $isOtherTypeRequired = true): bool
54
    {
55
        if (
56 13
            $isOtherTypeRequired
57 13
            && $this->currentType === TransferTypeEnum::TORPEDOS
58
        ) {
59
            return false;
60
        }
61
62 13
        return $this->source instanceof Spacecraft
63 13
            && $this->target instanceof Spacecraft
64 13
            && $this->source->isTorpedoStorageHealthy()
0 ignored issues
show
Bug introduced by
The method isTorpedoStorageHealthy() does not exist on Stu\Lib\Transfer\EntityWithStorageInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

64
            && $this->source->/** @scrutinizer ignore-call */ isTorpedoStorageHealthy()

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
65 13
            && (!$this->isUnload() || $this->source->getTorpedoCount() > 0)
0 ignored issues
show
Bug introduced by
The method getTorpedoCount() does not exist on Stu\Lib\Transfer\EntityWithStorageInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

65
            && (!$this->isUnload() || $this->source->/** @scrutinizer ignore-call */ getTorpedoCount() > 0)

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
66 13
            && ($this->target->hasTorpedo() || $this->target->isTorpedoStorageHealthy())
0 ignored issues
show
Bug introduced by
The method hasTorpedo() does not exist on Stu\Lib\Transfer\EntityWithStorageInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

66
            && ($this->target->/** @scrutinizer ignore-call */ hasTorpedo() || $this->target->isTorpedoStorageHealthy())

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
67 13
            && ($this->isUnload() || $this->target->getTorpedoCount() > 0);
68
    }
69
70
    public function isFriend(): bool
71
    {
72
        return $this->isFriend || $this->source->getUser() === $this->target->getUser();
73
    }
74
75 13
    public function isOtherGoodTransferPossible(): bool
76
    {
77 13
        return $this->isCommodityTransferPossible()
78 13
            || $this->isCrewTransferPossible()
79 13
            || $this->isTorpedoTransferPossible();
80
    }
81
82 13
    public function getTransferType(): TransferTypeEnum
83
    {
84 13
        return $this->currentType;
85
    }
86
87 13
    public function getSourceType(): TransferEntityTypeEnum
88
    {
89 13
        return $this->source->getTransferEntityType();
90
    }
91
92 13
    public function getTargetType(): TransferEntityTypeEnum
93
    {
94 13
        return $this->target->getTransferEntityType();
95
    }
96
97 13
    public function isUnload(): bool
98
    {
99 13
        return $this->isUnload;
100
    }
101
102 13
    public function getSourceId(): int
103
    {
104 13
        return $this->source->getId();
105
    }
106
107 13
    public function getTargetId(): int
108
    {
109 13
        return $this->target->getId();
110
    }
111
112 13
    public function getSource(): EntityWithStorageInterface
113
    {
114 13
        return $this->source;
115
    }
116
117 13
    public function getTarget(): EntityWithStorageInterface
118
    {
119 13
        return $this->target;
120
    }
121
122 13
    public function getSourceWrapper(): StorageEntityWrapperInterface
123
    {
124 13
        return $this->sourceWrapper;
125
    }
126
127 13
    public function getTargetWrapper(): StorageEntityWrapperInterface
128
    {
129 13
        return $this->targetWrapper;
130
    }
131
132 13
    public function getBeamFactor(): int
133
    {
134 13
        return $this->sourceWrapper->getBeamFactor();
135
    }
136
137 13
    public function isSourceAbove(): bool
138
    {
139 13
        return $this->getSourceType() !== TransferEntityTypeEnum::COLONY;
140
    }
141
142 13
    public function isUpIcon(): bool
143
    {
144 13
        return ($this->getSource() instanceof Colony) === $this->isUnload();
145
    }
146
147 9
    public function showFleetleaderActions(): bool
148
    {
149 9
        $source = $this->getSource();
150 9
        if (!$source instanceof Ship) {
151 5
            return false;
152
        }
153
154 4
        $fleet = $source->getFleet();
155
156 4
        return $fleet !== null
157 4
            && $source->isFleetLeader()
158 4
            && $fleet->getShipCount() > 1;
159
    }
160
}
161