Completed
Branch master (53fdb9)
by Mārtiņš
04:03 queued 01:53
created

Identity::fetch()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 28
Code Lines 12

Duplication

Lines 28
Ratio 100 %

Importance

Changes 0
Metric Value
dl 28
loc 28
rs 8.8571
c 0
b 0
f 0
cc 2
eloc 12
nc 2
nop 1
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
12
class Identity extends SqlMapper
13
{
14
15
    /**
16
     * @param Entity\Identity $entity
17
     */
18
    public function store(Entity\Identity $entity)
19
    {
20
        $table = $this->config['accounts']['identities'];
21
22
        $sql = "UPDATE $table
23
                   SET used_on = FROM_UNIXTIME(:used)
24
                 WHERE identity_id = :id";
25
26
        $statement = $this->connection->prepare($sql);
27
28
        $statement->bindValue(':id', $entity->getId());
29
        $statement->bindValue(':used', $entity->getLastUsed());
30
        $statement->execute();
31
    }
32
33
34
    /**
35
     * @param Entity\Identity $entity
36
     */
37 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...
38
    {
39
        $table = $this->config['accounts']['identities'];
40
41
        $sql = "SELECT identity_id                      AS id,
42
                       user_id                          AS userId,
43
                       status                           AS status,
44
                       hash                             AS hash,
45
                       UNIX_TIMESTAMP(token_expires_on) AS tokenEndOfLife
46
                  FROM $table
47
                 WHERE token = :token
48
                   AND token_action = :action
49
                   AND token_expires_on > FROM_UNIXTIME(:expires)";
50
51
        $statement = $this->connection->prepare($sql);
52
53
        $statement->bindValue(':token', $entity->getToken());
54
        $statement->bindValue(':action', $entity->getTokenAction());
55
        $statement->bindValue(':expires', $entity->getTokenEndOfLife());
56
57
        $statement->execute();
58
59
        $data = $statement->fetch();
60
61
        if ($data) {
62
            $this->applyValues($entity, $data);
63
        }
64
    }
65
}
66