Test Failed
Push — dev ( 83327d...238307 )
by Nico
51:35 queued 19:29
created

LocationMiningRepository   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 35
dl 0
loc 65
ccs 0
cts 5
cp 0
rs 10
c 1
b 0
f 1
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A findDepletedEntries() 0 14 1
A save() 0 5 1
A findById() 0 4 1
A getMiningQueueAtLocation() 0 12 1
A getMiningAtLocation() 0 12 1
A prototype() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Orm\Repository;
6
7
use Doctrine\ORM\EntityRepository;
8
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...
9
use Stu\Orm\Entity\MiningQueue;
10
use Stu\Orm\Entity\MiningQueueInterface;
11
use Stu\Orm\Entity\ShipInterface;
12
use Stu\Orm\Entity\LocationMining;
13
use Stu\Orm\Entity\LocationMiningInterface;
14
15
/**
16
 * @extends EntityRepository<LocationMining>
17
 */
18
final class LocationMiningRepository extends EntityRepository implements LocationMiningRepositoryInterface
19
{
20
    public function prototype(): LocationMiningInterface
21
    {
22
        return new LocationMining();
23
    }
24
25
    public function save(LocationMiningInterface $locationMining): void
26
    {
27
        $em = $this->getEntityManager();
28
        $em->persist($locationMining);
29
        $em->flush();
30
    }
31
32
    #[Override]
33
    public function getMiningAtLocation(ShipInterface $ship): array
34
    {
35
        return $this->getEntityManager()->createQuery(
36
            sprintf(
37
                'SELECT ml FROM %s ml
38
                 WHERE ml.location_id = :locationId',
39
                LocationMining::class
40
            )
41
        )->setParameters([
42
            'locationId' => $ship->getLocation()->getId()
43
        ])->getResult();
44
    }
45
46
    #[Override]
47
    public function getMiningQueueAtLocation(ShipInterface $ship): ?MiningQueueInterface
48
    {
49
        return $this->getEntityManager()->createQuery(
50
            sprintf(
51
                'SELECT mq FROM %s mq
52
                 WHERE mq.ship_id = :shipId',
53
                MiningQueue::class
54
            )
55
        )->setParameters([
56
            'shipId' => $ship->getId()
57
        ])->getOneOrNullResult();
58
    }
59
60
    #[Override]
61
    public function findById(int $id): ?LocationMiningInterface
62
    {
63
        return $this->find($id);
64
    }
65
66
    /**
67
     * @return LocationMiningInterface[]
68
     */
69
    public function findDepletedEntries(): array
70
    {
71
        $twentyDaysAgo = time() - (20 * 24 * 60 * 60);
72
73
        return $this->getEntityManager()->createQuery(
74
            sprintf(
75
                'SELECT lm FROM %s lm
76
                 WHERE lm.depleted_at < :twentyDaysAgo
77
                 AND lm.actual_amount < lm.max_amount',
78
                LocationMining::class
79
            )
80
        )->setParameters([
81
            'twentyDaysAgo' => $twentyDaysAgo
82
        ])->getResult();
83
    }
84
}
85