Passed
Push — dev ( 3fd410...aa33df )
by Janko
13:32
created

SpacecraftStorageTrait::getStorageSum()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 6
ccs 5
cts 5
cp 1
crap 1
rs 10
1
<?php
2
3
namespace Stu\Component\Spacecraft\Trait;
4
5
use Doctrine\Common\Collections\Collection;
6
use Stu\Lib\Transfer\CommodityTransfer;
7
use Stu\Orm\Entity\CommodityInterface;
8
use Stu\Orm\Entity\StorageInterface;
9
10
trait SpacecraftStorageTrait
11
{
12
    use SpacecraftTrait;
13
14 14
    public function getStorageSum(): int
15
    {
16 14
        return array_reduce(
17 14
            $this->getThis()->getStorage()->getValues(),
18 14
            fn(int $sum, StorageInterface $storage): int => $sum + $storage->getAmount(),
19 14
            0
20 14
        );
21
    }
22
23 13
    public function getMaxStorage(): int
24
    {
25 13
        return $this->getRump()->getStorage();
0 ignored issues
show
Bug introduced by
It seems like getRump() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

25
        return $this->/** @scrutinizer ignore-call */ getRump()->getStorage();
Loading history...
26
    }
27
28 8
    public function getBeamableStorage(): Collection
29
    {
30 8
        return CommodityTransfer::excludeNonBeamable($this->storage);
31
    }
32
33
    public function getStoredShuttles(): Collection
34
    {
35
        return $this->getThis()->getStorage()
36
            ->map(fn(StorageInterface $storage): CommodityInterface => $storage->getCommodity())
37
            ->filter(fn(CommodityInterface $commodity): bool => $commodity->isShuttle());
38
    }
39
40 2
    public function hasStoredBuoy(): bool
41
    {
42 2
        return $this->getThis()->getStorage()
43 2
            ->exists(fn(int $key, StorageInterface $storage): bool => $storage->getCommodity()->isBouy());
44
    }
45
}
46