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

SessionRepository   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 3
Bugs 0 Features 3
Metric Value
wmc 5
c 3
b 0
f 3
lcom 0
cbo 4
dl 0
loc 26
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A save() 0 5 1
A findById() 0 10 3
A delete() 0 5 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