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

Identity::fetch()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 28
Code Lines 12

Duplication

Lines 28
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 28
loc 28
c 0
b 0
f 0
ccs 0
cts 22
cp 0
rs 8.8571
nc 2
cc 2
eloc 12
nop 1
crap 6
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