Passed
Push — dev ( 20f168...3a8ec2 )
by Nico
15:39
created

CommodityConsumption::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 0
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
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
use Stu\Orm\Repository\ColonyDepositMiningRepositoryInterface;
10
11
final class CommodityConsumption implements CommodityConsumptionInterface
12
{
13 2
    public function __construct(
14
        private readonly ColonyDepositMiningRepositoryInterface $colonyDepositMiningRepository
15 2
    ) {}
16
17 1
    #[Override]
18
    public function getConsumption(
19
        array $production,
20
        ColonyInterface $colony
21
    ): array {
22 1
        $depositMinings = $this->colonyDepositMiningRepository->getCurrentUserDepositMinings($colony);
23 1
        $storages = $colony->getStorage();
24 1
        $ret = [];
25 1
        foreach ($production as $commodityId => $productionItem) {
26 1
            $proc = $productionItem->getProduction();
27 1
            if ($proc >= 0) {
28 1
                continue;
29
            }
30
31
            $commodity = $productionItem->getCommodity();
32
            $ret[$commodityId]['commodity'] = $commodity;
33
            $ret[$commodityId]['production'] = $productionItem->getProduction();
34
35
            if (array_key_exists($commodityId, $depositMinings)) {
36
                $deposit = $depositMinings[$commodityId];
37
                $ret[$commodityId]['turnsleft'] = (int) floor($deposit->getAmountLeft() / abs($proc));
38
            } else {
39
                $storage = $storages->get($commodityId);
40
                $stored = $storage !== null ? $storage->getAmount() : 0;
41
                $ret[$commodityId]['turnsleft'] = (int) floor($stored / abs($proc));
42
            }
43
        }
44
45 1
        return $ret;
46
    }
47
}
48