Completed
Push — master ( 7348eb...8d7aac )
by Mārtiņš
02:10
created

Identity::exists()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 1
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 1
ccs 0
cts 0
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
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
    public function store(Entity\Identity $entity)
19
    {
20
        $table = $this->config['accounts']['identities'];
21
22
        $sql = "UPDATE $table
23
                   SET used_on = :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
                       token_expires_on AS tokenEndOfLife
46
                  FROM $table
47
                 WHERE token = :token
48
                   AND token_action = :action
49
                   AND token_expires_on > :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