Code Duplication    Length = 20-28 lines in 4 locations

src/Palladium/Mapper/CookieIdentity.php 1 location

@@ 19-40 (lines=22) @@
16
    /**
17
     * @param Entity\CookieIdentity $entity
18
     */
19
    public function exists(Entity\CookieIdentity $entity)
20
    {
21
        $sql = "SELECT 1
22
                  FROM {$this->table} AS Identities
23
                 WHERE type = :type
24
                   AND user_id = :user
25
                   AND identifier = :series
26
                   AND fingerprint = :fingerprint";
27
28
        $statement = $this->connection->prepare($sql);
29
30
        $statement->bindValue(':type', $entity->getType());
31
        $statement->bindValue(':user', $entity->getUserId());
32
        $statement->bindValue(':series', $entity->getSeries());
33
        $statement->bindValue(':fingerprint', $entity->getFingerprint());
34
35
        $statement->execute();
36
37
        $data = $statement->fetch();
38
39
        return empty($data) === false;
40
    }
41
42
43
    /**

src/Palladium/Mapper/EmailIdentity.php 1 location

@@ 44-71 (lines=28) @@
41
    /**
42
     * @param Entity\EmailIdentity $entity
43
     */
44
    public function fetch(Entity\EmailIdentity $entity)
45
    {
46
        $sql = "SELECT identity_id      AS id,
47
                       user_id          AS userId,
48
                       hash             AS hash,
49
                       status           AS status,
50
                       token            AS token,
51
                       token_action     AS tokenAction,
52
                       token_expires_on AS tokenEndOfLife
53
                  FROM {$this->table}
54
                 WHERE type = :type
55
                   AND fingerprint = :fingerprint
56
                   AND identifier = :identifier";
57
58
        $statement = $this->connection->prepare($sql);
59
60
        $statement->bindValue(':type', $entity->getType());
61
        $statement->bindValue(':identifier', $entity->getIdentifier());
62
        $statement->bindValue(':fingerprint', $entity->getFingerprint());
63
64
        $statement->execute();
65
66
        $data = $statement->fetch();
67
68
        if ($data) {
69
            $this->applyValues($entity, $data);
70
        }
71
    }
72
73
74
    /**

src/Palladium/Mapper/Identity.php 1 location

@@ 35-60 (lines=26) @@
32
    /**
33
     * @param Entity\Identity $entity
34
     */
35
    public function fetch(Entity\Identity $entity)
36
    {
37
        $sql = "SELECT identity_id      AS id,
38
                       user_id          AS userId,
39
                       status           AS status,
40
                       hash             AS hash,
41
                       token_expires_on AS tokenEndOfLife
42
                  FROM {$this->table}
43
                 WHERE token = :token
44
                   AND token_action = :action
45
                   AND token_expires_on > :expires";
46
47
        $statement = $this->connection->prepare($sql);
48
49
        $statement->bindValue(':token', $entity->getToken());
50
        $statement->bindValue(':action', $entity->getTokenAction());
51
        $statement->bindValue(':expires', $entity->getTokenEndOfLife());
52
53
        $statement->execute();
54
55
        $data = $statement->fetch();
56
57
        if ($data) {
58
            $this->applyValues($entity, $data);
59
        }
60
    }
61
}
62

src/Palladium/Mapper/IdentityCollection.php 1 location

@@ 47-66 (lines=20) @@
44
    /**
45
     * @param Entity\IdentityCollection $collection
46
     */
47
    public function fetch(Entity\IdentityCollection $collection)
48
    {
49
        $sql = "SELECT identity_id  AS id
50
                  FROM {$this->table}
51
                 WHERE status = :status
52
                   AND user_id = :user
53
                   AND type = :type";
54
55
        $statement = $this->connection->prepare($sql);
56
57
        $statement->bindValue(':user', $collection->getUserId());
58
        $statement->bindValue(':status', $collection->getStatus());
59
        $statement->bindValue(':type', $collection->getType());
60
61
        $statement->execute();
62
63
        foreach ($statement as $parameters) {
64
            $collection->addBlueprint($parameters);
65
        }
66
    }
67
}
68