Passed
Pull Request — master (#1918)
by Janko
25:50
created

TutorialStepRepository::findByUserAndViewContext()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 20
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 17
nc 1
nop 2
dl 0
loc 20
ccs 0
cts 13
cp 0
crap 2
rs 9.7
c 0
b 0
f 0
1
<?php
2
3
namespace Stu\Orm\Repository;
4
5
use Doctrine\ORM\EntityRepository;
6
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...
7
use Stu\Module\Control\ViewContext;
8
use Stu\Orm\Entity\TutorialStep;
9
use Stu\Orm\Entity\UserInterface;
10
use Stu\Orm\Entity\UserTutorial;
11
12
/**
13
 * @extends EntityRepository<TutorialStep>
14
 */
15
final class TutorialStepRepository extends EntityRepository implements TutorialStepRepositoryInterface
16
{
17
    #[Override]
18
    public function findByUserAndViewContext(UserInterface $user, ViewContext $viewContext): array
19
    {
20
        return $this->getEntityManager()->createQuery(
21
            sprintf(
22
                'SELECT ts FROM %s ts INDEX BY ts.id
23
                    WHERE EXISTS (SELECT ut FROM %s ut
24
                                    JOIN %1$s ts2
25
                                    WITH ts2.id = ut.tutorial_step_id
26
                                    WHERE ut.user = :user
27
                                    AND ts2.module = :module
28
                                    AND ts.view = :view)',
29
                TutorialStep::class,
30
                UserTutorial::class
31
            )
32
        )->setParameters([
33
            'user' => $user,
34
            'module' => $viewContext->getModule()->value,
35
            'view' => $viewContext->getViewIdentifier(),
36
        ])->getResult();
37
    }
38
39
    #[Override]
40
    public function findAllFirstSteps(): array
41
    {
42
        return $this->getEntityManager()
43
            ->createQuery(
44
                sprintf(
45
                    'SELECT ts FROM %1$s ts
46
                    WHERE NOT EXISTS (SELECT ts2.id FROM %1$s ts2
47
                                        WHERE ts2.next_step_id = ts.id)',
48
                    TutorialStep::class
49
                )
50
            )
51
            ->getResult();
52
    }
53
}
54