Passed
Push — dev ( 97fee6...d16c83 )
by Nico
15:13
created

FactionRepository   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Test Coverage

Coverage 66.67%

Importance

Changes 0
Metric Value
eloc 25
dl 0
loc 40
ccs 16
cts 24
cp 0.6667
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getByChooseable() 0 5 1
A save() 0 6 1
A getPlayableFactionsPlayerCount() 0 22 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\Module\PlayerSetting\Lib\UserEnum;
0 ignored issues
show
Bug introduced by
The type Stu\Module\PlayerSetting\Lib\UserEnum 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\Faction;
11
use Stu\Orm\Entity\FactionInterface;
12
use Stu\Orm\Entity\User;
13
14
/**
15
 * @extends EntityRepository<Faction>
16
 */
17
final class FactionRepository extends EntityRepository implements FactionRepositoryInterface
18
{
19
    #[Override]
20
    public function getByChooseable(bool $chooseable): array
21
    {
22
        return $this->findBy([
23
            'chooseable' => $chooseable
24
        ]);
25
    }
26
27 1
    #[Override]
28
    public function getPlayableFactionsPlayerCount(): array
29
    {
30 1
        return $this
31 1
            ->getEntityManager()
32 1
            ->createQuery(
33 1
                sprintf(
34 1
                    'SELECT
35
                        f as faction, COUNT(u.id) as count
36
                    FROM %s f INDEX BY f.id LEFT JOIN %s u WITH u.race = f.id AND u.id >= :firstUserId
37
                    WHERE f.chooseable = :chooseable
38
                    GROUP BY f.id
39 1
                    ORDER BY f.id',
40 1
                    Faction::class,
41 1
                    User::class
42 1
                )
43 1
            )
44 1
            ->setParameters([
45 1
                'chooseable' => true,
46 1
                'firstUserId' => UserEnum::USER_FIRST_ID
47 1
            ])
48 1
            ->getResult();
49
    }
50
51
    #[Override]
52
    public function save(FactionInterface $faction): void
53
    {
54
        $em = $this->getEntityManager();
55
        $em->persist($faction);
56
        $em->flush();
57
    }
58
}
59