getUnregistrationByIdAndKey()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 6

Duplication

Lines 8
Ratio 100 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 8
loc 8
rs 9.4285
cc 2
eloc 6
nc 2
nop 2
1
<?php
2
3
/**
4
 * @author    Markus Tacker <[email protected]>
5
 * @copyright 2013-2016 Verein zur Förderung der Netzkultur im Rhein-Main-Gebiet e.V. | http://netzkultur-rheinmain.de/
6
 */
7
8
namespace BCRM\BackendBundle\Entity\Event;
9
10
use Doctrine\ORM\EntityRepository;
11
use Doctrine\ORM\Query\ResultSetMapping;
12
use Doctrine\ORM\Query\ResultSetMappingBuilder;
13
use PhpOption\None;
14
use PhpOption\Some;
15
16
class DoctrineUnregistrationRepository extends EntityRepository implements UnregistrationRepository
17
{
18
    /**
19
     * @return Unregistration[]
20
     */
21
    public function getNewUnregistrations()
22
    {
23
        $qb = $this->createQueryBuilder('u');
24
        $qb->andWhere('u.confirmed=0');
25
        $qb->andWhere('u.confirmationKey IS NULL');
26
        $qb->groupBy('u.email');
27
        return $qb->getQuery()->getResult();
28
    }
29
30
    /**
31
     * @param Event $event
32
     *
33
     * @return Unregistration[]
34
     */
35
    public function getUnprocessedUnregistrations(Event $event)
36
    {
37
        $rsm = new ResultSetMappingBuilder($this->_em);
38
        $rsm->addRootEntityFromClassMetadata('BCRM\BackendBundle\Entity\Event\Unregistration', 'u');
39
        $eventId         = $event->getId();
40
        $unregistrations = "SELECT MAX(id) FROM unregistration WHERE confirmed = 1 AND event_id = $eventId AND processed = 0 GROUP BY event_id, email ORDER BY created ASC, id ASC";
41
        $sql             = "SELECT * FROM unregistration WHERE id IN ($unregistrations)";
42
        $query           = $this->_em->createNativeQuery(
43
            $sql,
44
            $rsm
45
        );
46
        return $query->getResult();
47
    }
48
49
    /**
50
     * @param string $id
51
     * @param string $key
52
     *
53
     * @return \PhpOption\Option
54
     */
55 View Code Duplication
    public function getUnregistrationByIdAndKey($id, $key)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
56
    {
57
        $qb = $this->createQueryBuilder('u');
58
        $qb->andWhere('u.id = :id')->setParameter('id', $id);
59
        $qb->andWhere('u.confirmationKey = :key')->setParameter('key', $key);
60
        $result = $qb->getQuery()->getOneOrNullResult();
61
        return $result === null ? None::create() : new Some($result);
62
    }
63
64
    /**
65
     * @param Event $event
66
     *
67
     * @return Unregistration[]
68
     */
69
    public function getUnregistrationsForEvent(Event $event)
70
    {
71
        return $this->createQueryBuilder('r')
72
            ->andWhere('r.event = :event')->setParameter('event', $event)
73
            ->getQuery()
74
            ->getResult();
75
    }
76
77
78
}
79