Completed
Push — 1.x ( fd103f...647e2f )
by Daniel
23:51 queued 13:50
created

User   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

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

7 Methods

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