User::update()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 4
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