Completed
Push — master ( 561bb0...6a0ab6 )
by Mārtiņš
05:13
created

Identity   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 60
Duplicated Lines 70 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 42
loc 60
ccs 0
cts 33
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
B fetch() 28 28 2
A store() 14 14 1
A exists() 0 1 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Palladium\Mapper;
4
5
/**
6
 * SQL code for locating identity data by token and updating last usage.
7
 */
8
9
use Palladium\Component\SqlMapper;
10
use Palladium\Entity\Authentication as Entity;
11
use Palladium\Contract\CanPersistIdentity;
12
13
class Identity extends SqlMapper implements CanPersistIdentity
14
{
15
16
    /**
17
     * @param Entity\Identity $entity
18
     */
19 View Code Duplication
    public function store(Entity\Identity $entity)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
20
    {
21
        $table = $this->config['accounts']['identities'];
22
23
        $sql = "UPDATE $table
24
                   SET used_on = FROM_UNIXTIME(:used)
25
                 WHERE identity_id = :id";
26
27
        $statement = $this->connection->prepare($sql);
28
29
        $statement->bindValue(':id', $entity->getId());
30
        $statement->bindValue(':used', $entity->getLastUsed());
31
        $statement->execute();
32
    }
33
34
35
    /**
36
     * @param Entity\Identity $entity
37
     */
38 View Code Duplication
    public function fetch(Entity\Identity $entity)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
39
    {
40
        $table = $this->config['accounts']['identities'];
41
42
        $sql = "SELECT identity_id                      AS id,
43
                       user_id                          AS userId,
44
                       status                           AS status,
45
                       hash                             AS hash,
46
                       UNIX_TIMESTAMP(token_expires_on) AS tokenEndOfLife
47
                  FROM $table
48
                 WHERE token = :token
49
                   AND token_action = :action
50
                   AND token_expires_on > FROM_UNIXTIME(:expires)";
51
52
        $statement = $this->connection->prepare($sql);
53
54
        $statement->bindValue(':token', $entity->getToken());
55
        $statement->bindValue(':action', $entity->getTokenAction());
56
        $statement->bindValue(':expires', $entity->getTokenEndOfLife());
57
58
        $statement->execute();
59
60
        $data = $statement->fetch();
61
62
        if ($data) {
63
            $this->applyValues($entity, $data);
64
        }
65
    }
66
67
68
    /**
69
     * @param Entity\Identity $entity
70
     */
71
    public function exists(Entity\Identity $entity) {}
72
}
73