Test Failed
Branch master (dff1c0)
by Nils
02:42
created

findPreviousMatchdaySameRound()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 18
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 13
nc 3
nop 1
dl 0
loc 18
rs 9.4285
c 0
b 0
f 0
1
<?php
2
namespace Torakel\DatabaseBundle\Repository;
3
4
use Doctrine\ORM\EntityRepository;
0 ignored issues
show
Bug introduced by
The type Doctrine\ORM\EntityRepository 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...
5
use Torakel\DatabaseBundle\Entity\Matchday;
6
7
class MatchdayRepository extends EntityRepository
8
{
9
10
    /**
11
     * findPreviousMatchdaySameRound
12
     *
13
     * @param Matchday $matchday
14
     * @return Matchday
15
     */
16
    public function findPreviousMatchdaySameRound(Matchday $matchday)
17
    {
18
        $currentPosition = $matchday->getPosition();
19
        $round = $matchday->getRound();
20
        $previousPosition = $currentPosition - 1;
21
        if ($currentPosition == 0) {
22
23
            return null;
24
        }
25
        $previousMatchday = $this->getEntityManager()
26
            ->createQuery(
27
                'SELECT m FROM TorakelDatabaseBundle:Matchday m  WHERE m.position = :position AND m.round = :round'
28
            )->setParameter('position', $previousPosition)->setParameter('round', $round)
29
            ->getResult();
30
        if (!$previousMatchday) {
31
            return null;
32
        }
33
        return array_shift($previousMatchday);
34
    }
35
36
    /**
37
     * findNextMatchdaySameRound
38
     *
39
     * @param Matchday $matchday
40
     * @return Matchday
41
     */
42
    public function findNextMatchdaySameRound(Matchday $matchday)
43
    {
44
        $currentPosition = $matchday->getPosition();
45
        $round = $matchday->getRound();
46
        $nextPosition = $currentPosition + 1;
47
        $nextMatchday = $this->getEntityManager()
48
            ->createQuery(
49
                'SELECT m FROM TorakelDatabaseBundle:Matchday m  WHERE m.position = :position AND m.round = :round'
50
            )->setParameter('position', $nextPosition)->setParameter('round', $round)
51
            ->getResult();
52
        if (!$nextMatchday) {
53
            return null;
54
        }
55
56
        return array_shift($nextMatchday);
57
    }
58
59
    /**
60
     * @param Matchday $matchday
61
     * @return Matchday
62
     */
63
    public function findAllMatchdaysForMatchday(Matchday $matchday)
64
    {
65
        return $this->getEntityManager()
66
            ->createQuery(
67
                'SELECT m FROM TorakelDatabaseBundle:Matchday m JOIN TorakelDatabaseBundle:Round r WITH m.round = r WHERE r.event = :event ORDER BY m.position ASC'
68
            )->setParameter('event', $matchday->getRound()->getEvent())
69
            ->getResult();
70
    }
71
}