Completed
Branch master (8a300a)
by Mārtiņš
02:17
created
src/Palladium/Service/Authentication/Identification.php 2 patches
Unused Use Statements   -6 removed lines patch added patch discarded remove patch
@@ -6,20 +6,14 @@
 block discarded – undo
6 6
  * Retrieval and handling of identities for registered users
7 7
  */
8 8
 
9
-use RuntimeException;
10
-
11
-use Palladium\Component\MapperFactory;
12 9
 use Palladium\Mapper\Authentication as Mapper;
13 10
 use Palladium\Entity\Authentication as Entity;
14
-
15
-use Palladium\Exception\Authentication\IdentityDuplicated;
16 11
 use Palladium\Exception\Authentication\IdentityNotFound;
17 12
 use Palladium\Exception\Authentication\EmailNotFound;
18 13
 use Palladium\Exception\Authentication\PasswordNotMatch;
19 14
 use Palladium\Exception\Authentication\CompromisedCookie;
20 15
 use Palladium\Exception\Authentication\DenialOfServiceAttempt;
21 16
 use Palladium\Exception\Authentication\IdentityExpired;
22
-use Palladium\Exception\Community\UserNotFound;
23 17
 
24 18
 
25 19
 class Identification extends Locator
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -137,7 +137,7 @@
 block discarded – undo
137 137
 
138 138
         $mapper = $this->mapperFactory->create(Mapper\CookieIdentity::class);
139 139
 
140
-        if ($identity->getExpiresOn() <  time()) {
140
+        if ($identity->getExpiresOn() < time()) {
141 141
             $identity->setStatus(Entity\Identity::STATUS_EXPIRED);
142 142
             $mapper->store($identity);
143 143
             $this->logger->info('cookie expired', [
Please login to merge, or discard this patch.
src/Palladium/Component/Collection.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
     /** code that does the actualy population of data from the given array in blueprint */
54 54
     private function populateEntity($instance, $parameters)
55 55
     {
56
-        foreach ((array)$parameters as $key => $value) {
56
+        foreach ((array) $parameters as $key => $value) {
57 57
             $method = 'set' . str_replace('_', '', $key);
58 58
             if (method_exists($instance, $method)) {
59 59
                 $instance->{$method}($value);
@@ -233,7 +233,7 @@  discard block
 block discarded – undo
233 233
 
234 234
     public function offsetGet($offset)
235 235
     {
236
-        if (isset($this->indexed[$offset])){
236
+        if (isset($this->indexed[$offset])) {
237 237
             return $this->indexed[$offset];
238 238
         }
239 239
 
Please login to merge, or discard this patch.
src/Palladium/Component/DataMapper.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -13,7 +13,7 @@
 block discarded – undo
13 13
      */
14 14
     public function applyValues($instance, array $parameters)
15 15
     {
16
-        foreach ((array)$parameters as $key => $value) {
16
+        foreach ((array) $parameters as $key => $value) {
17 17
             $method = 'set' . str_replace('_', '', $key);
18 18
             if (method_exists($instance, $method)) {
19 19
                 $instance->{$method}($value);
Please login to merge, or discard this patch.
src/Palladium/Entity/Authentication/CookieIdentity.php 1 patch
Indentation   +143 added lines, -143 removed lines patch added patch discarded remove patch
@@ -1,162 +1,162 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
- namespace Palladium\Entity\Authentication;
3
+    namespace Palladium\Entity\Authentication;
4 4
 
5
- use Palladium\Exception\Authentication\InvalidCookieToken;
5
+    use Palladium\Exception\Authentication\InvalidCookieToken;
6 6
 
7
- class CookieIdentity extends Identity
8
- {
7
+    class CookieIdentity extends Identity
8
+    {
9 9
 
10
-     const SERIES_SIZE = 16;
11
-     const KEY_SIZE = 32;
10
+        const SERIES_SIZE = 16;
11
+        const KEY_SIZE = 32;
12 12
 
13 13
 
14
-     private $series;
15
-     private $key;
16
-     private $hash;
14
+        private $series;
15
+        private $key;
16
+        private $hash;
17 17
 
18
-     protected $type = Identity::TYPE_COOKIE;
18
+        protected $type = Identity::TYPE_COOKIE;
19 19
 
20 20
 
21
-     public function setSeries($series)
22
-     {
23
-         if (empty($series) && 0 !== $series) {
24
-             $this->series = null;
25
-             return;
26
-         }
21
+        public function setSeries($series)
22
+        {
23
+            if (empty($series) && 0 !== $series) {
24
+                $this->series = null;
25
+                return;
26
+            }
27 27
 
28
-         $this->series = (string) $series;
29
-     }
28
+            $this->series = (string) $series;
29
+        }
30 30
 
31 31
 
32
-     /**
33
-      * @codeCoverageIgnore
34
-      */
35
-     public function getSeries()
36
-     {
37
-         return $this->series;
38
-     }
32
+        /**
33
+         * @codeCoverageIgnore
34
+         */
35
+        public function getSeries()
36
+        {
37
+            return $this->series;
38
+        }
39 39
 
40 40
 
41
-     /**
42
-      * Produces a hash from series to obscure it for storage.
43
-      *
44
-      * @return string
45
-      */
46
-     public function getFingerprint()
47
-     {
48
-         return hash('sha384', $this->series);
49
-     }
41
+        /**
42
+         * Produces a hash from series to obscure it for storage.
43
+         *
44
+         * @return string
45
+         */
46
+        public function getFingerprint()
47
+        {
48
+            return hash('sha384', $this->series);
49
+        }
50 50
 
51 51
 
52
-     public function generateNewSeries()
53
-     {
54
-         $this->series = bin2hex(random_bytes(self::SERIES_SIZE));
55
-     }
52
+        public function generateNewSeries()
53
+        {
54
+            $this->series = bin2hex(random_bytes(self::SERIES_SIZE));
55
+        }
56 56
 
57 57
 
58
-     /**
59
-      * Assignes a new identification key and resets a the hash.
60
-      *
61
-      * @param string $key
62
-      */
63
-     public function setKey($key)
64
-     {
65
-         $this->hash = null;
66
-
67
-         if (empty($key) && 0 !== $key) {
68
-             $this->key = null;
69
-             return;
70
-         }
71
-
72
-         $key = (string) $key;
73
-
74
-         $this->key = $key;
75
-         $this->hash = $this->makeHash($key);
76
-     }
77
-
78
-
79
-     /**
80
-      * @codeCoverageIgnore
81
-      * @return string
82
-      */
83
-     public function getKey()
84
-     {
85
-         return $this->key;
86
-     }
87
-
88
-
89
-     /**
90
-      * Sets a new key and resets the hash.
91
-      */
92
-      public function generateNewKey()
93
-      {
94
-          $key = bin2hex(random_bytes(self::KEY_SIZE));
95
-          $this->key = $key;
96
-          $this->hash = $this->makeHash($key);
97
-      }
98
-
99
-
100
-      /**
101
-       * @codeCoverageIgnore
102
-       */
103
-     public function getHash()
104
-     {
105
-         return $this->hash;
106
-     }
107
-
108
-
109
-     private function makeHash($key)
110
-     {
111
-         return hash('sha384', $key);
112
-     }
113
-
114
-
115
-     public function setHash($hash)
116
-     {
117
-         if (empty($hash) && 0 !== $hash) {
118
-             $this->hash = null;
119
-             return;
120
-         }
121
-
122
-         $this->hash = (string) $hash;
123
-     }
124
-
125
-
126
-     public function matchKey($key)
127
-     {
128
-         return  $this->makeHash($key) === $this->hash;
129
-     }
130
-
131
-
132
-     /**
133
-      * Retrieves the identification token in a compact form.
134
-      *
135
-      * @return string|null
136
-      */
137
-     public function getCollapsedValue()
138
-     {
139
-         if (null === $this->getId()) {
140
-             return null;
141
-         }
142
-         return $this->getUserId() . '|' . $this->getSeries() . '|' . $this->getKey();
143
-     }
144
-
145
-
146
-     /**
147
-      * Populates the instance from the identification token.
148
-      *
149
-      * @param string $value
150
-      */
151
-     public function setCollapsedValue($value)
152
-     {
153
-         if (empty($value) || substr_count($value, '|') !== 2) {
154
-             throw new InvalidCookieToken;
155
-         }
156
-
157
-         list($userId, $series, $key) = explode('|', $value);
158
-         $this->setUserId($userId);
159
-         $this->setSeries($series);
160
-         $this->setKey($key);
161
-     }
162
- }
58
+        /**
59
+         * Assignes a new identification key and resets a the hash.
60
+         *
61
+         * @param string $key
62
+         */
63
+        public function setKey($key)
64
+        {
65
+            $this->hash = null;
66
+
67
+            if (empty($key) && 0 !== $key) {
68
+                $this->key = null;
69
+                return;
70
+            }
71
+
72
+            $key = (string) $key;
73
+
74
+            $this->key = $key;
75
+            $this->hash = $this->makeHash($key);
76
+        }
77
+
78
+
79
+        /**
80
+         * @codeCoverageIgnore
81
+         * @return string
82
+         */
83
+        public function getKey()
84
+        {
85
+            return $this->key;
86
+        }
87
+
88
+
89
+        /**
90
+         * Sets a new key and resets the hash.
91
+         */
92
+        public function generateNewKey()
93
+        {
94
+            $key = bin2hex(random_bytes(self::KEY_SIZE));
95
+            $this->key = $key;
96
+            $this->hash = $this->makeHash($key);
97
+        }
98
+
99
+
100
+        /**
101
+         * @codeCoverageIgnore
102
+         */
103
+        public function getHash()
104
+        {
105
+            return $this->hash;
106
+        }
107
+
108
+
109
+        private function makeHash($key)
110
+        {
111
+            return hash('sha384', $key);
112
+        }
113
+
114
+
115
+        public function setHash($hash)
116
+        {
117
+            if (empty($hash) && 0 !== $hash) {
118
+                $this->hash = null;
119
+                return;
120
+            }
121
+
122
+            $this->hash = (string) $hash;
123
+        }
124
+
125
+
126
+        public function matchKey($key)
127
+        {
128
+            return  $this->makeHash($key) === $this->hash;
129
+        }
130
+
131
+
132
+        /**
133
+         * Retrieves the identification token in a compact form.
134
+         *
135
+         * @return string|null
136
+         */
137
+        public function getCollapsedValue()
138
+        {
139
+            if (null === $this->getId()) {
140
+                return null;
141
+            }
142
+            return $this->getUserId() . '|' . $this->getSeries() . '|' . $this->getKey();
143
+        }
144
+
145
+
146
+        /**
147
+         * Populates the instance from the identification token.
148
+         *
149
+         * @param string $value
150
+         */
151
+        public function setCollapsedValue($value)
152
+        {
153
+            if (empty($value) || substr_count($value, '|') !== 2) {
154
+                throw new InvalidCookieToken;
155
+            }
156
+
157
+            list($userId, $series, $key) = explode('|', $value);
158
+            $this->setUserId($userId);
159
+            $this->setSeries($series);
160
+            $this->setKey($key);
161
+        }
162
+    }
Please login to merge, or discard this patch.
src/Palladium/Entity/Authentication/Identity.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -22,10 +22,10 @@
 block discarded – undo
22 22
     const ACTION_RESET = 2;
23 23
 
24 24
     const STATUS_ANY = null;
25
-    const STATUS_NEW = 1;       // not veriefoed user
26
-    const STATUS_ACTIVE = 2;    // this is the "good" state
25
+    const STATUS_NEW = 1; // not veriefoed user
26
+    const STATUS_ACTIVE = 2; // this is the "good" state
27 27
     const STATUS_DISCARDED = 3; // user logged out or changed password
28
-    const STATUS_BLOCKED = 4;   // someone tried to us an invalid auth cookie
28
+    const STATUS_BLOCKED = 4; // someone tried to us an invalid auth cookie
29 29
     const STATUS_EXPIRED = 5;
30 30
 
31 31
     const TYPE_ANY = null;
Please login to merge, or discard this patch.
src/Palladium/Mapper/Authentication/IdentityCollection.php 1 patch
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -56,16 +56,16 @@
 block discarded – undo
56 56
                    AND user_id = :user
57 57
                    AND type = :type";
58 58
 
59
-       $statement = $this->connection->prepare($sql);
59
+        $statement = $this->connection->prepare($sql);
60 60
 
61
-       $statement->bindValue(':user', $collection->getUserId());
62
-       $statement->bindValue(':status', $collection->getStatus());
63
-       $statement->bindValue(':type', $collection->getType());
61
+        $statement->bindValue(':user', $collection->getUserId());
62
+        $statement->bindValue(':status', $collection->getStatus());
63
+        $statement->bindValue(':type', $collection->getType());
64 64
 
65
-       $statement->execute();
65
+        $statement->execute();
66 66
 
67
-       foreach ($statement as $parameters) {
68
-           $collection->addBlueprint($parameters);
69
-       }
67
+        foreach ($statement as $parameters) {
68
+            $collection->addBlueprint($parameters);
69
+        }
70 70
     }
71 71
 }
Please login to merge, or discard this patch.
src/Palladium/Mapper/Authentication/PasswordIdentity.php 1 patch
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -126,16 +126,16 @@
 block discarded – undo
126 126
                        token_expires_on = FROM_UNIXTIME(:token_eol)
127 127
                  WHERE identity_id = :id";
128 128
 
129
-         $statement = $this->connection->prepare($sql);
129
+            $statement = $this->connection->prepare($sql);
130 130
 
131
-         $statement->bindValue(':id', $entity->getId());
132
-         $statement->bindValue(':hash', $entity->getHash());
133
-         $statement->bindValue(':status', $entity->getStatus());
134
-         $statement->bindValue(':expires', $entity->getExpiresOn());
135
-         $statement->bindValue(':token', $entity->getToken());
136
-         $statement->bindValue(':action', $entity->getTokenAction());
137
-         $statement->bindValue(':token_eol', $entity->getTokenEndOfLife());
131
+            $statement->bindValue(':id', $entity->getId());
132
+            $statement->bindValue(':hash', $entity->getHash());
133
+            $statement->bindValue(':status', $entity->getStatus());
134
+            $statement->bindValue(':expires', $entity->getExpiresOn());
135
+            $statement->bindValue(':token', $entity->getToken());
136
+            $statement->bindValue(':action', $entity->getTokenAction());
137
+            $statement->bindValue(':token_eol', $entity->getTokenEndOfLife());
138 138
 
139
-         $statement->execute();
139
+            $statement->execute();
140 140
     }
141 141
 }
Please login to merge, or discard this patch.