Passed
Push — master ( 9d73f4...fd4f11 )
by Nico
25:31
created

TransferInformation   A

Complexity

Total Complexity 31

Size/Duplication

Total Lines 93
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 1 Features 0
Metric Value
eloc 37
dl 0
loc 93
ccs 0
cts 43
cp 0
rs 9.92
c 2
b 1
f 0
wmc 31

12 Methods

Rating   Name   Duplication   Size   Complexity  
A isOtherGoodTransferPossible() 0 5 3
A getTargetId() 0 3 1
A isFriend() 0 9 3
B isTorpedoTransferPossible() 0 15 11
A __construct() 0 1 1
A isColonyTarget() 0 3 1
A getTarget() 0 3 1
A isCommodityTransferPossible() 0 4 2
A getSource() 0 3 1
A isCrewTransferPossible() 0 17 5
A getTransferType() 0 3 1
A isUnload() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Lib\Transfer;
6
7
use Stu\Orm\Entity\ColonyInterface;
8
use Stu\Orm\Entity\ShipInterface;
9
10
class TransferInformation
11
{
12
    public function __construct(private TransferTypeEnum $currentType, private ColonyInterface|ShipInterface $from, private ColonyInterface|ShipInterface $to, private bool $isUnload, private bool $isFriend) {}
13
14
    public function isCommodityTransferPossible(bool $isOtherTypeRequired = true): bool
15
    {
16
        return !($isOtherTypeRequired
17
            && $this->currentType === TransferTypeEnum::COMMODITIES);
18
    }
19
20
    public function isCrewTransferPossible(bool $isOtherTypeRequired = true): bool
21
    {
22
        if (
23
            $isOtherTypeRequired
24
            && $this->currentType === TransferTypeEnum::CREW
25
        ) {
26
            return false;
27
        }
28
29
        if (
30
            $this->to instanceof ShipInterface
31
            && $this->to->hasUplink()
32
        ) {
33
            return true;
34
        }
35
36
        return $this->to->getUser() === $this->from->getUser();
37
    }
38
39
    public function isTorpedoTransferPossible(bool $isOtherTypeRequired = true): bool
40
    {
41
        if (
42
            $isOtherTypeRequired
43
            && $this->currentType === TransferTypeEnum::TORPEDOS
44
        ) {
45
            return false;
46
        }
47
48
        return $this->from instanceof ShipInterface
49
            && $this->to instanceof ShipInterface
50
            && $this->from->isTorpedoStorageHealthy()
51
            && (!$this->isUnload() || $this->from->getTorpedoCount() > 0)
52
            && ($this->to->hasTorpedo() || $this->to->isTorpedoStorageHealthy())
53
            && ($this->isUnload() || $this->to->getTorpedoCount() > 0);
54
    }
55
56
    public function isFriend(): bool
57
    {
58
        if (
59
            !$this->isFriend
60
            && $this->from->getUser() !== $this->to->getUser()
61
        ) {
62
            return false;
63
        } else {
64
            return true;
65
        }
66
    }
67
68
    public function isOtherGoodTransferPossible(): bool
69
    {
70
        return $this->isCommodityTransferPossible()
71
            || $this->isCrewTransferPossible()
72
            || $this->isTorpedoTransferPossible();
73
    }
74
75
    public function getTransferType(): TransferTypeEnum
76
    {
77
        return $this->currentType;
78
    }
79
80
    public function isUnload(): bool
81
    {
82
        return $this->isUnload;
83
    }
84
85
    public function getTargetId(): int
86
    {
87
        return $this->to->getId();
88
    }
89
90
    public function isColonyTarget(): bool
91
    {
92
        return $this->to instanceof ColonyInterface;
93
    }
94
95
    public function getSource(): ShipInterface|ColonyInterface
96
    {
97
        return $this->from;
98
    }
99
100
    public function getTarget(): ShipInterface|ColonyInterface
101
    {
102
        return $this->to;
103
    }
104
}
105