Passed
Push — master ( 434e9a...778819 )
by Nico
15:27 queued 08:32
created

Commodity   A

Complexity

Total Complexity 25

Size/Duplication

Total Lines 138
Duplicated Lines 0 %

Test Coverage

Coverage 52.27%

Importance

Changes 0
Metric Value
eloc 47
dl 0
loc 138
ccs 23
cts 44
cp 0.5227
rs 10
c 0
b 0
f 0
wmc 25

19 Methods

Rating   Name   Duplication   Size   Complexity  
A getId() 0 3 1
A getTransferCount() 0 5 1
A isBouy() 0 3 1
A setSort() 0 5 1
A isBoundToAccount() 0 3 1
A isWorkbee() 0 3 1
A setView() 0 5 1
A getType() 0 3 1
A setType() 0 5 1
A getView() 0 3 1
A setCheatable() 0 5 1
A isBeamable() 0 5 6
A getName() 0 3 1
A setName() 0 5 1
A isShuttle() 0 3 1
A isTradeable() 0 3 2
A isSaveable() 0 3 1
A getSort() 0 3 1
A getCheatable() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Orm\Entity;
6
7
use Doctrine\ORM\Mapping\Column;
8
use Doctrine\ORM\Mapping\Entity;
9
use Doctrine\ORM\Mapping\GeneratedValue;
10
use Doctrine\ORM\Mapping\Id;
11
use Doctrine\ORM\Mapping\Index;
12
use Doctrine\ORM\Mapping\Table;
13
use Stu\Module\Commodity\CommodityTypeConstants;
0 ignored issues
show
Bug introduced by
The type Stu\Module\Commodity\CommodityTypeConstants 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...
14
use Stu\Orm\Repository\CommodityRepository;
15
16
#[Table(name: 'stu_commodity')]
17
#[Index(name: 'commodity_sort_idx', columns: ['sort'])]
18
#[Entity(repositoryClass: CommodityRepository::class)]
19
class Commodity
20
{
21
    #[Id]
22
    #[Column(type: 'integer')]
23
    #[GeneratedValue(strategy: 'IDENTITY')]
24
    private int $id;
25
26
    #[Column(type: 'string')]
27
    private string $name = '';
28
29
    #[Column(type: 'smallint')]
30
    private int $sort = 0;
31
32
    #[Column(type: 'boolean')]
33
    private bool $view = true;
34
35
    #[Column(type: 'smallint')]
36
    private int $type = CommodityTypeConstants::COMMODITY_TYPE_STANDARD;
37
38
    #[Column(type: 'boolean')]
39
    private bool $npc_commodity = false;
40
41
    #[Column(type: 'boolean')]
42
    private bool $bound = false;
43
44
    #[Column(type: 'boolean', nullable: true)]
45
    private ?bool $cheatable = null;
46
47 37
    public function getId(): int
48
    {
49 37
        return $this->id;
50
    }
51
52 34
    public function getName(): string
53
    {
54 34
        return $this->name;
55
    }
56
57
    public function setName(string $name): Commodity
58
    {
59
        $this->name = $name;
60
61
        return $this;
62
    }
63
64 9
    public function getSort(): int
65
    {
66 9
        return $this->sort;
67
    }
68
69
    public function setSort(int $sort): Commodity
70
    {
71
        $this->sort = $sort;
72
73
        return $this;
74
    }
75
76 12
    public function getView(): bool
77
    {
78 12
        return $this->view;
79
    }
80
81
    public function setView(bool $view): Commodity
82
    {
83
        $this->view = $view;
84
85
        return $this;
86
    }
87
88 19
    public function getType(): int
89
    {
90 19
        return $this->type;
91
    }
92
93
    public function setType(int $typeId): Commodity
94
    {
95
        $this->type = $typeId;
96
97
        return $this;
98
    }
99
100
    public function getCheatable(): ?bool
101
    {
102
        return $this->cheatable;
103
    }
104
105
    public function setCheatable(?bool $cheatable): Commodity
106
    {
107
        $this->cheatable = $cheatable;
108
109
        return $this;
110
    }
111
112 1
    public function isTradeable(): bool
113
    {
114 1
        return $this->isBeamable() && $this->npc_commodity === false;
115
    }
116
117 12
    public function isBeamable(?User $user = null, ?User $targetUser = null): bool
118
    {
119 12
        $isBound = $user !== null && $targetUser !== null && $this->isBoundToAccount() && $user->getId() !== $targetUser->getId();
120
121 12
        return $this->getType() === CommodityTypeConstants::COMMODITY_TYPE_STANDARD && $this->getView() === true && !$isBound;
122
    }
123
124 1
    public function isSaveable(): bool
125
    {
126 1
        return $this->getType() === CommodityTypeConstants::COMMODITY_TYPE_STANDARD;
127
    }
128
129 1
    public function isBoundToAccount(): bool
130
    {
131 1
        return $this->bound;
132
    }
133
134 2
    public function isShuttle(): bool
135
    {
136 2
        return in_array(intdiv($this->getId(), 10) * 10, CommodityTypeConstants::BASE_IDS_SHUTTLE);
137
    }
138
139
    public function isWorkbee(): bool
140
    {
141
        return intdiv($this->getId(), 10) * 10 === CommodityTypeConstants::BASE_ID_WORKBEE;
142
    }
143
144 1
    public function isBouy(): bool
145
    {
146 1
        return $this->getId() === CommodityTypeConstants::BASE_ID_BUOY;
147
    }
148
149
    public function getTransferCount(): int
150
    {
151
        // @todo Anzahl Waren pro Energieeinheit
152
        // Möglicherweise einstellbar nach Warentyp
153
        return 1;
154
    }
155
}
156