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

IdentityCollection::fetch()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 22
Code Lines 11

Duplication

Lines 22
Ratio 100 %

Importance

Changes 0
Metric Value
dl 22
loc 22
rs 9.2
c 0
b 0
f 0
cc 2
eloc 11
nc 2
nop 1
1
<?php
2
3
namespace Palladium\Mapper;
4
5
/**
6
 * SQL code repsonsible for locating all of the identities, that have been associated
7
 * to a given user and discarding them in bulk.
8
 * Used mostly in case of password reset or, if cookie has been compromised.
9
 */
10
11
12
use Palladium\Component\SqlMapper;
13
use Palladium\Entity\Authentication as Entity;
14
15
class IdentityCollection extends SqlMapper
16
{
17
18
    /**
19
     * @param Entity\IdentityCollection $collection
20
     */
21
    public function store(Entity\IdentityCollection $collection)
22
    {
23
        if ($collection->getUserId() !== null) {
24
            $this->updateStatus($collection);
25
        }
26
    }
27
28
29
    private function updateStatus(Entity\IdentityCollection $collection)
30
    {
31
        $table = $this->config['accounts']['identities'];
32
33
        $sql = "UPDATE {$table}
34
                   SET status = :status
35
                 WHERE identity_id = :id";
36
        $statement = $this->connection->prepare($sql);
37
38
        foreach ($collection as $entity) {
39
            $statement->bindValue(':id', $entity->getId());
40
            $statement->bindValue(':status', $entity->getStatus());
41
            $statement->execute();
42
        }
43
    }
44
45
46
    /**
47
     * @param Entity\IdentityCollection $collection
48
     */
49 View Code Duplication
    public function fetch(Entity\IdentityCollection $collection)
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...
50
    {
51
        $table = $this->config['accounts']['identities'];
52
53
        $sql = "SELECT identity_id  AS id
54
                  FROM {$table}
55
                 WHERE status = :status
56
                   AND user_id = :user
57
                   AND type = :type";
58
59
       $statement = $this->connection->prepare($sql);
60
61
       $statement->bindValue(':user', $collection->getUserId());
62
       $statement->bindValue(':status', $collection->getStatus());
63
       $statement->bindValue(':type', $collection->getType());
64
65
       $statement->execute();
66
67
       foreach ($statement as $parameters) {
68
           $collection->addBlueprint($parameters);
69
       }
70
    }
71
}
72