Completed
Push — master ( 585d40...a6f122 )
by Derek Stephen
02:36
created

EmailLink::findByToken()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 11
ccs 0
cts 9
cp 0
rs 9.4285
cc 2
eloc 7
nc 2
nop 1
crap 6
1
<?php
2
3
namespace Del\Repository;
4
5
use Del\Entity\EmailLink as EmailLinkEntity;
6
use Doctrine\ORM\EntityRepository;
7
8
class EmailLink extends EntityRepository
9
{
10
    /**
11
     * @param EmailLinkEntity $link
12
     * @return EmailLinkEntity
13
     */
14
    public function save(EmailLinkEntity $link)
15
    {
16
        $this->_em->persist($link);
17
        $this->_em->flush();
18
        return $link;
19
    }
20
    /**
21
     * @param EmailLinkEntity $link
22
     */
23
    public function delete(EmailLinkEntity $link)
24
    {
25
        $this->_em->remove($link);
26
        $this->_em->flush();
27
    }
28
29
    /**
30
     * @param string $token
31
     * @return EmailLinkEntity|null
32
     */
33
    public function findByToken($token)
34
    {
35
        $qb = $this->createQueryBuilder('el');
36
37
        $qb->where('el.token = :token');
38
        $qb->setParameter('token', $token);
39
40
        $query = $qb->getQuery();
41
        $result = $query->getResult();
42
        return empty($result) ? null : $result[0];
43
    }
44
}
45