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

SpacecraftStorageTrait   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 76.47%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
dl 0
loc 34
ccs 13
cts 17
cp 0.7647
rs 10
c 1
b 0
f 0
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getStorageSum() 0 6 1
A getBeamableStorage() 0 3 1
A hasStoredBuoy() 0 4 1
A getMaxStorage() 0 3 1
A getStoredShuttles() 0 5 1
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