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

CreateInterstellarMedia   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 26
ccs 0
cts 14
cp 0
rs 10
c 0
b 0
f 0
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 1 1
A handle() 0 22 4
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