Passed
Push — master ( 92a2e9...9d73f4 )
by Nico
41:55
created

CreateInterstellarMedia::handle()   A

Complexity

Conditions 4
Paths 5

Size

Total Lines 22
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
cc 4
eloc 14
nc 5
nop 0
dl 0
loc 22
ccs 0
cts 13
cp 0
crap 20
rs 9.7998
c 0
b 0
f 0
1
<?php
2
3
namespace Stu\Module\Maintenance;
4
5
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...
6
use Stu\Orm\Repository\LocationMiningRepositoryInterface;
7
8
final class CreateInterstellarMedia implements MaintenanceHandlerInterface
9
{
10
    public function __construct(private LocationMiningRepositoryInterface $locationMiningRepository) {}
11
12
    #[Override]
13
    public function handle(): void
14
    {
15
        $entries = $this->locationMiningRepository->findDepletedEntries();
16
17
        foreach ($entries as $entry) {
18
            $currentAmount = $entry->getActualAmount();
19
            $maxAmount = $entry->getMaxAmount();
20
21
            if ($currentAmount === 0) {
22
                $newAmount = max(1, (int) ceil($maxAmount * 0.05));
23
            } else {
24
                $newAmount = (int) ceil($currentAmount * 1.15);
25
            }
26
27
            if ($newAmount >= $maxAmount) {
28
                $newAmount = $maxAmount;
29
                $entry->setDepletedAt(null);
30
            }
31
32
            $entry->setActualAmount($newAmount);
33
            $this->locationMiningRepository->save($entry);
34
        }
35
    }
36
}
37