Code Duplication    Length = 22-30 lines in 4 locations

src/Palladium/Mapper/CookieIdentity.php 1 location

@@ 114-135 (lines=22) @@
111
    }
112
113
114
    private function updateCookie(Entity\CookieIdentity $entity)
115
    {
116
        $table = $this->config['accounts']['identities'];
117
        $active = Entity\Identity::STATUS_ACTIVE;
118
119
        $sql = "UPDATE {$table}
120
                   SET status = :status,
121
                       hash = :hash,
122
                       used_on = NOW(),
123
                       expires_on = FROM_UNIXTIME(:expires)
124
                 WHERE identity_id = :id
125
                   AND status = {$active}";
126
127
        $statement = $this->connection->prepare($sql);
128
129
        $statement->bindValue(':id', $entity->getId());
130
        $statement->bindValue(':status', $entity->getStatus());
131
        $statement->bindValue(':hash', $entity->getHash());
132
        $statement->bindValue(':expires', $entity->getExpiresOn());
133
134
        $statement->execute();
135
    }
136
}
137

src/Palladium/Mapper/Identity.php 1 location

@@ 37-64 (lines=28) @@
34
    /**
35
     * @param Entity\Identity $entity
36
     */
37
    public function fetch(Entity\Identity $entity)
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

src/Palladium/Mapper/IdentityCollection.php 1 location

@@ 49-70 (lines=22) @@
46
    /**
47
     * @param Entity\IdentityCollection $collection
48
     */
49
    public function fetch(Entity\IdentityCollection $collection)
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

src/Palladium/Mapper/PasswordIdentity.php 1 location

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