Completed
Push — master ( cd27e7...dbd271 )
by Mārtiņš
04:09
created

Identity::fetch()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 27
Code Lines 11

Duplication

Lines 26
Ratio 96.3 %

Code Coverage

Tests 11
CRAP Score 2

Importance

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