User   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 6
dl 0
loc 66
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A findByEmail() 0 10 1
A findByUsername() 0 10 1
A findById() 0 10 1
A getTableName() 0 4 1
A setTableName() 0 4 1
A insert() 0 8 1
A update() 0 8 2
1
<?php
2
3
namespace LmcUser\Mapper;
4
5
use LmcUser\Entity\UserInterface as UserEntityInterface;
6
use Laminas\Hydrator\HydratorInterface;
7
8
class User extends AbstractDbMapper implements UserInterface
9
{
10
    protected $tableName  = 'user';
11
12
13
    public function findByEmail($email)
14
    {
15
        $select = $this->getSelect()
16
            ->where(array('email' => $email));
17
        $entity = $this->select($select)->current();
18
19
        $this->getEventManager()->trigger('find', $this, array('entity' => $entity));
20
21
        return $entity;
22
    }
23
24
    public function findByUsername($username)
25
    {
26
        $select = $this->getSelect()
27
            ->where(array('username' => $username));
28
        $entity = $this->select($select)->current();
29
30
        $this->getEventManager()->trigger('find', $this, array('entity' => $entity));
31
32
        return $entity;
33
    }
34
35
    public function findById($id)
36
    {
37
        $select = $this->getSelect()
38
            ->where(array('user_id' => $id));
39
        $entity = $this->select($select)->current();
40
41
        $this->getEventManager()->trigger('find', $this, array('entity' => $entity));
42
43
        return $entity;
44
    }
45
46
    public function getTableName()
47
    {
48
        return $this->tableName;
49
    }
50
51
    public function setTableName($tableName)
52
    {
53
        $this->tableName = $tableName;
54
    }
55
56
    public function insert(UserEntityInterface $entity, $tableName = null, HydratorInterface $hydrator = null)
57
    {
58
        $result = parent::insert($entity, $tableName, $hydrator);
59
60
        $entity->setId($result->getGeneratedValue());
61
62
        return $result;
63
    }
64
65
    public function update(UserEntityInterface $entity, $where = null, $tableName = null, HydratorInterface $hydrator = null)
66
    {
67
        if (!$where) {
68
            $where = array('user_id' => $entity->getId());
69
        }
70
71
        return parent::update($entity, $where, $tableName, $hydrator);
72
    }
73
}
74