Completed
Push — master ( cf598b...fa35f0 )
by Gabriel
02:37
created

SessionRepository::findById()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 10
rs 9.4285
cc 3
eloc 7
nc 4
nop 1
1
<?php
2
3
namespace Sinergi\Users\Doctrine\Session;
4
5
use Doctrine\ORM\EntityRepository;
6
use Sinergi\Users\Session\SessionEntityInterface;
7
use Sinergi\Users\Session\SessionRepositoryInterface;
8
9
class SessionRepository extends EntityRepository implements SessionRepositoryInterface
10
{
11
    public function save(SessionEntityInterface $session)
12
    {
13
        $this->getEntityManager()->persist($session);
14
        $this->getEntityManager()->flush($session);
15
    }
16
17
    /** @return SessionEntityInterface */
18
    public function findById(string $id)
19
    {
20
        $result = $this->createQueryBuilder('s')
21
            ->where('s.id = :id')
22
            ->setParameter('id', $id)
23
            ->getQuery()
24
            ->getResult();
25
26
        return $result && $result[0] ? $result[0] : null;
27
    }
28
29
    public function delete(SessionEntityInterface $session)
30
    {
31
        $this->getEntityManager()->remove($session);
32
        $this->getEntityManager()->flush($session);
33
    }
34
}
35