User   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 9
c 1
b 1
f 0
lcom 1
cbo 5
dl 0
loc 61
rs 10

7 Methods

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