Test Failed
Pull Request — master (#2138)
by Nico
10:57
created

Trumfield::setHull()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 5
rs 10
c 0
b 0
f 0
ccs 0
cts 3
cp 0
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Orm\Entity;
6
7
use Doctrine\Common\Collections\ArrayCollection;
8
use Doctrine\Common\Collections\Collection;
9
use Doctrine\ORM\Mapping\Column;
10
use Doctrine\ORM\Mapping\Entity;
11
use Doctrine\ORM\Mapping\GeneratedValue;
12
use Doctrine\ORM\Mapping\Id;
13
use Doctrine\ORM\Mapping\JoinColumn;
14
use Doctrine\ORM\Mapping\ManyToOne;
15
use Doctrine\ORM\Mapping\OneToMany;
16
use Doctrine\ORM\Mapping\OrderBy;
17
use Doctrine\ORM\Mapping\Table;
18
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...
19
use RuntimeException;
20
use Stu\Lib\Transfer\CommodityTransfer;
21
use Stu\Lib\Transfer\TransferEntityTypeEnum;
22
use Stu\Orm\Repository\TrumfieldRepository;
23
24
#[Table(name: 'stu_trumfield')]
25
#[Entity(repositoryClass: TrumfieldRepository::class)]
26
class Trumfield implements TrumfieldInterface
27
{
28
    #[Id]
29
    #[Column(type: 'integer')]
30
    #[GeneratedValue(strategy: 'IDENTITY')]
31
    private int $id;
32
33
    #[Column(type: 'integer', length: 6)]
34
    private int $huelle = 0;
35
36
    #[Column(type: 'integer')]
37
    private int $former_rump_id = 0;
38
39
    #[Column(type: 'integer')]
40
    private int $location_id = 0;
0 ignored issues
show
introduced by
The private property $location_id is not used, and could be removed.
Loading history...
41
42
    /**
43
     * @var ArrayCollection<int, StorageInterface>
44
     */
45
    #[OneToMany(targetEntity: 'Storage', mappedBy: 'trumfield', indexBy: 'commodity_id')]
46
    #[OrderBy(['commodity_id' => 'ASC'])]
47
    private Collection $storage;
48
49
    #[ManyToOne(targetEntity: 'Location')]
50
    #[JoinColumn(name: 'location_id', referencedColumnName: 'id')]
51
    private LocationInterface $location;
52
53 2
    #[Override]
54
    public function getId(): int
55
    {
56 2
        return $this->id;
57
    }
58
59 1
    #[Override]
60
    public function getHull(): int
61
    {
62 1
        return $this->huelle;
63
    }
64
65
    #[Override]
66
    public function setHull(int $hull): TrumfieldInterface
67
    {
68
        $this->huelle = $hull;
69
        return $this;
70
    }
71
72 2
    #[Override]
73
    public function getFormerRumpId(): int
74
    {
75 2
        return $this->former_rump_id;
76
    }
77
78
    #[Override]
79
    public function setFormerRumpId(int $formerRumpId): TrumfieldInterface
80
    {
81
        $this->former_rump_id = $formerRumpId;
82
        return $this;
83
    }
84
85 1
    #[Override]
86
    public function getStorage(): Collection
87
    {
88 1
        return $this->storage;
89
    }
90
91 1
    #[Override]
92
    public function getStorageSum(): int
93
    {
94 1
        return array_reduce(
95 1
            $this->getStorage()->getValues(),
96 1
            fn(int $sum, StorageInterface $storage): int => $sum + $storage->getAmount(),
97 1
            0
98 1
        );
99
    }
100
101 1
    #[Override]
102
    public function getMaxStorage(): int
103
    {
104 1
        return $this->getStorageSum();
105
    }
106
107 1
    #[Override]
108
    public function getBeamableStorage(): Collection
109
    {
110 1
        return CommodityTransfer::excludeNonBeamable($this->storage);
111
    }
112
113
    #[Override]
114
    public function getCrewAssignments(): Collection
115
    {
116
        return new ArrayCollection();
117
    }
118
119 1
    #[Override]
120
    public function getLocation(): MapInterface|StarSystemMapInterface
121
    {
122
        if (
123 1
            $this->location instanceof MapInterface
124 1
            || $this->location instanceof StarSystemMapInterface
125
        ) {
126 1
            return $this->location;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->location returns the type Stu\Orm\Entity\LocationInterface which includes types incompatible with the type-hinted return Stu\Orm\Entity\MapInterf...\StarSystemMapInterface.
Loading history...
127
        }
128
129
        throw new RuntimeException('unknown type');
130
    }
131
132
    #[Override]
133
    public function setLocation(LocationInterface $location): TrumfieldInterface
134
    {
135
        $this->location = $location;
136
137
        return $this;
138
    }
139
140 1
    #[Override]
141
    public function getUser(): ?UserInterface
142
    {
143 1
        return null;
144
    }
145
146 2
    #[Override]
147
    public function getTransferEntityType(): TransferEntityTypeEnum
148
    {
149 2
        return TransferEntityTypeEnum::TRUMFIELD;
150
    }
151
152
    #[Override]
153
    public function getHref(): string
154
    {
155
        return '';
156
    }
157
}
158