Passed
Push — master ( 434e9a...778819 )
by Nico
15:27 queued 08:32
created

CommodityRepository::getTradeable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 0
dl 0
loc 8
ccs 6
cts 6
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Orm\Repository;
6
7
use Doctrine\ORM\EntityRepository;
8
use Stu\Lib\Colony\PlanetFieldHostInterface;
9
use Stu\Module\Commodity\CommodityTypeConstants;
0 ignored issues
show
Bug introduced by
The type Stu\Module\Commodity\CommodityTypeConstants 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...
10
use Stu\Orm\Entity\BuildingCommodity;
11
use Stu\Orm\Entity\Commodity;
12
use Stu\Orm\Entity\PlanetField;
13
14
/**
15
 * @extends EntityRepository<Commodity>
16
 */
17
final class CommodityRepository extends EntityRepository implements CommodityRepositoryInterface
18
{
19 1
    #[\Override]
20
    public function getByBuildingsOnColony(PlanetFieldHostInterface $host): array
21
    {
22 1
        return $this->getEntityManager()
23 1
            ->createQuery(
24 1
                sprintf(
25 1
                    'SELECT c FROM %s c
26
                    WHERE c.id IN (
27
                        SELECT bg.commodity_id
28
                        FROM %s bg
29
                        WHERE bg.buildings_id IN (
30
                            SELECT pf.buildings_id
31
                            FROM %s pf
32
                            WHERE pf.%s = :hostId
33
                        )
34 1
                    ) ORDER BY c.name ASC',
35 1
                    Commodity::class,
36 1
                    BuildingCommodity::class,
37 1
                    PlanetField::class,
38 1
                    $host->getHostType()->getPlanetFieldHostColumnIdentifier()
39 1
                )
40 1
            )
41 1
            ->setParameter('hostId', $host->getId())
42 1
            ->getResult();
43
    }
44
45
    #[\Override]
46
    public function getByType(int $typeId): array
47
    {
48
        return $this->findBy([
49
            'type' => $typeId
50
        ], ['sort' => 'asc']);
51
    }
52
53
    #[\Override]
54
    public function getViewable(): array
55
    {
56
        return $this->findBy([
57
            'view' => true
58
        ], ['sort' => 'asc']);
59
    }
60
61 5
    #[\Override]
62
    public function getTradeable(): array
63
    {
64 5
        return $this->findBy([
65 5
            'view' => true,
66 5
            'npc_commodity' => false,
67 5
            'type' => CommodityTypeConstants::COMMODITY_TYPE_STANDARD
68 5
        ], ['sort' => 'asc']);
69
    }
70
71 2
    #[\Override]
72
    public function getTradeableNPC(): array
73
    {
74 2
        return $this->findBy([
75 2
            'view' => true,
76 2
            'cheatable' => false,
77 2
            'type' => CommodityTypeConstants::COMMODITY_TYPE_STANDARD
78 2
        ], ['sort' => 'asc']);
79
    }
80
81
    #[\Override]
82
    public function getTradeableAdmin(): array
83
    {
84
        return $this->findBy([
85
            'view' => true,
86
            'type' => CommodityTypeConstants::COMMODITY_TYPE_STANDARD
87
        ], ['sort' => 'asc']);
88
    }
89
90 1
    #[\Override]
91
    public function getAll(): array
92
    {
93 1
        return $this->getEntityManager()
94 1
            ->createQuery(
95 1
                sprintf(
96 1
                    'SELECT c FROM %s c
97
                    INDEX BY c.id
98 1
                    ORDER BY c.sort ASC',
99 1
                    Commodity::class
100 1
                )
101 1
            )
102 1
            ->getResult();
103
    }
104
}
105