Completed
Push — master ( e7d3f8...bbd5c2 )
by Derek Stephen
01:35
created

EmailLink::delete()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 0
cts 5
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
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
     * @throws \Doctrine\ORM\OptimisticLockException
14
     */
15
    public function save(EmailLinkEntity $link)
16
    {
17
        $this->_em->persist($link);
18
        $this->_em->flush();
19
        return $link;
20
    }
21
22
    /**
23
     * @param EmailLinkEntity $link
24
     * @throws \Doctrine\ORM\OptimisticLockException
25
     */
26
    public function delete(EmailLinkEntity $link)
27
    {
28
        $this->_em->remove($link);
29
        $this->_em->flush();
30
    }
31
32
    /**
33
     * @param string $token
34
     * @return EmailLinkEntity|null
35
     */
36
    public function findByToken($token)
37
    {
38
        $qb = $this->createQueryBuilder('el');
39
40
        $qb->where('el.token = :token');
41
        $qb->setParameter('token', $token);
42
43
        $query = $qb->getQuery();
44
        $result = $query->getResult();
45
        return count($result) ? $result[0] : null;
46
    }
47
}
48