Passed
Push — master ( 8a05d4...47c113 )
by Janko
21:55 queued 10:03
created

CommodityConsumption::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 0
nc 1
nop 1
dl 0
loc 2
ccs 1
cts 1
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Module\Colony\Lib;
6
7
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...
8
use Stu\Orm\Entity\ColonyInterface;
9
10
final class CommodityConsumption implements CommodityConsumptionInterface
11
{
12
    #[Override]
13
    public function getConsumption(
14
        array $production,
15
        ColonyInterface $colony
16
    ): array {
17
        $depositMinings = $colony->getUserDepositMinings();
18
        $storages = $colony->getStorage();
19
        $ret = [];
20
        foreach ($production as $commodityId => $productionItem) {
21
            $proc = $productionItem->getProduction();
22
            if ($proc >= 0) {
23
                continue;
24
            }
25
26
            $commodity = $productionItem->getCommodity();
27
            $ret[$commodityId]['commodity'] = $commodity;
28
            $ret[$commodityId]['production'] = $productionItem->getProduction();
29
30
            if (array_key_exists($commodityId, $depositMinings)) {
31
                $deposit = $depositMinings[$commodityId];
32
                $ret[$commodityId]['turnsleft'] = (int) floor($deposit->getAmountLeft() / abs($proc));
33
            } else {
34
                $storage = $storages->get($commodityId);
35
                $stored = $storage !== null ? $storage->getAmount() : 0;
36
                $ret[$commodityId]['turnsleft'] = (int) floor($stored / abs($proc));
37
            }
38
        }
39
40
        return $ret;
41
    }
42
}
43