Test Failed
Push — develop ( d86fe4...72ac76 )
by Pieter van der
03:14
created
library/tiqr/Tiqr/StateStorage.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -47,7 +47,7 @@
 block discarded – undo
47 47
      * @throws RuntimeException When the options configuration array misses a required parameter
48 48
      *
49 49
      */
50
-    public static function getStorage(string $type="file", array $options=array(), LoggerInterface $logger)
50
+    public static function getStorage(string $type = "file", array $options = array(), LoggerInterface $logger)
51 51
     {
52 52
         switch ($type) {
53 53
             case "file":
Please login to merge, or discard this patch.
library/tiqr/Tiqr/Exception/ReadWriteException.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -22,6 +22,6 @@
 block discarded – undo
22 22
     {
23 23
         // $code must be int, otherwise this throws with Error("Wrong parameters for ReadWriteException")
24 24
         // PDOException::getCode() can return a sting
25
-        return new self($e->getMessage(), (int)$e->getCode(), $e );
25
+        return new self($e->getMessage(), (int) $e->getCode(), $e);
26 26
     }
27 27
 }
Please login to merge, or discard this patch.
library/tiqr/Tiqr/Service.php 3 patches
Indentation   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -571,17 +571,17 @@  discard block
 block discarded – undo
571 571
         }
572 572
 
573 573
         $metadata = array("service"=>
574
-                               array("displayName"       => $this->_name,
575
-                                     "identifier"        => $this->_identifier,
576
-                                     "logoUrl"           => $this->_logoUrl,
577
-                                     "infoUrl"           => $this->_infoUrl,
578
-                                     "authenticationUrl" => $authenticationUrl,
579
-                                     "ocraSuite"         => $this->_ocraSuite,
580
-                                     "enrollmentUrl"     => $enrollmentUrl
581
-                               ),
582
-                          "identity"=>
583
-                               array("identifier" =>$data["userId"],
584
-                                     "displayName"=>$data["displayName"]));
574
+                                array("displayName"       => $this->_name,
575
+                                        "identifier"        => $this->_identifier,
576
+                                        "logoUrl"           => $this->_logoUrl,
577
+                                        "infoUrl"           => $this->_infoUrl,
578
+                                        "authenticationUrl" => $authenticationUrl,
579
+                                        "ocraSuite"         => $this->_ocraSuite,
580
+                                        "enrollmentUrl"     => $enrollmentUrl
581
+                                ),
582
+                            "identity"=>
583
+                                array("identifier" =>$data["userId"],
584
+                                        "displayName"=>$data["displayName"]));
585 585
 
586 586
         $this->_unsetStateValue(self::PREFIX_ENROLLMENT, $enrollmentKey);
587 587
 
@@ -611,28 +611,28 @@  discard block
 block discarded – undo
611 611
      */
612 612
     public function getEnrollmentSecret(string $enrollmentKey): string
613 613
     {
614
-         $data = $this->_getStateValue(self::PREFIX_ENROLLMENT, $enrollmentKey);
615
-         if (!is_array($data)) {
616
-             $this->logger->error('getEnrollmentSecret: enrollment key not found');
617
-             throw new RuntimeException('enrollment key not found');
618
-         }
619
-         $userId = $data["userId"] ?? NULL;
620
-         $sessionId = $data["sessionId"] ?? NULL;
621
-         if (!is_string($userId) || !(is_string($sessionId))) {
622
-             throw new RuntimeException('getEnrollmentSecret: invalid enrollment data');
623
-         }
624
-         $enrollmentData = [
625
-             "userId" => $userId,
626
-             "sessionId" => $sessionId
627
-         ];
628
-         $enrollmentSecret = $this->_uniqueSessionKey();
629
-         $this->_setStateValue(
630
-             self::PREFIX_ENROLLMENT_SECRET,
631
-             $enrollmentSecret,
632
-             $enrollmentData,
633
-             self::ENROLLMENT_EXPIRE
634
-         );
635
-         return $enrollmentSecret;
614
+            $data = $this->_getStateValue(self::PREFIX_ENROLLMENT, $enrollmentKey);
615
+            if (!is_array($data)) {
616
+                $this->logger->error('getEnrollmentSecret: enrollment key not found');
617
+                throw new RuntimeException('enrollment key not found');
618
+            }
619
+            $userId = $data["userId"] ?? NULL;
620
+            $sessionId = $data["sessionId"] ?? NULL;
621
+            if (!is_string($userId) || !(is_string($sessionId))) {
622
+                throw new RuntimeException('getEnrollmentSecret: invalid enrollment data');
623
+            }
624
+            $enrollmentData = [
625
+                "userId" => $userId,
626
+                "sessionId" => $sessionId
627
+            ];
628
+            $enrollmentSecret = $this->_uniqueSessionKey();
629
+            $this->_setStateValue(
630
+                self::PREFIX_ENROLLMENT_SECRET,
631
+                $enrollmentSecret,
632
+                $enrollmentData,
633
+                self::ENROLLMENT_EXPIRE
634
+            );
635
+            return $enrollmentSecret;
636 636
     }
637 637
 
638 638
     /**
Please login to merge, or discard this patch.
Spacing   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
     // INVALID_USERID: The client authenticated a different user than the server expected. This error is returned when
119 119
     // the application stated an authentication session specifying the userId and later during the authentication
120 120
     // provides a different userId
121
-    const AUTH_RESULT_INVALID_USERID    = 5;
121
+    const AUTH_RESULT_INVALID_USERID = 5;
122 122
     
123 123
     /**
124 124
      * The default OCRA Suite (RFC 6287) to use for authentication in Tiqr
@@ -247,7 +247,7 @@  discard block
 block discarded – undo
247 247
      * @param int $version The tiqr protocol version to use (defaults to the latest)
248 248
      * @throws Exception
249 249
      */
250
-    public function __construct(LoggerInterface $logger, array $options=array(), int $version = 2)
250
+    public function __construct(LoggerInterface $logger, array $options = array(), int $version = 2)
251 251
     {
252 252
         $this->_options = $options; // Used to later get settings for Tiqr_Message_*
253 253
         $this->logger = $logger;
@@ -350,7 +350,7 @@  discard block
 block discarded – undo
350 350
                 case 'APNS':
351 351
                 case 'APNS_DIRECT':
352 352
                     $apns_version = $this->_options['apns.version'] ?? 1;
353
-                    if ($apns_version ==2 )
353
+                    if ($apns_version == 2)
354 354
                         $message = new Tiqr_Message_APNS2($this->_options, $this->logger);
355 355
                     else
356 356
                         $message = new Tiqr_Message_APNS($this->_options, $this->logger);
@@ -368,7 +368,7 @@  discard block
 block discarded – undo
368 368
 
369 369
             $this->logger->info(sprintf('Creating and sending a %s push notification', $notificationType));
370 370
             $message->setId(time());
371
-            $message->setText("Please authenticate for " . $this->_name);
371
+            $message->setText("Please authenticate for ".$this->_name);
372 372
             $message->setAddress($notificationAddress);
373 373
             $message->setCustomProperty('challenge', $this->_getChallengeUrl($sessionKey));
374 374
             $message->send();
@@ -414,13 +414,13 @@  discard block
 block discarded – undo
414 414
      * @return string The authentication sessionKey
415 415
      * @throws Exception when starting the authentication session failed
416 416
      */
417
-    public function startAuthenticationSession(string $userId="", string $sessionId="", string $spIdentifier=""): string
417
+    public function startAuthenticationSession(string $userId = "", string $sessionId = "", string $spIdentifier = ""): string
418 418
     {
419
-        if ($sessionId=="") {
419
+        if ($sessionId == "") {
420 420
             $sessionId = session_id();
421 421
         }
422 422
 
423
-        if ($spIdentifier=="") {
423
+        if ($spIdentifier == "") {
424 424
             $spIdentifier = $this->_identifier;
425 425
         }
426 426
 
@@ -429,7 +429,7 @@  discard block
 block discarded – undo
429 429
         
430 430
         $data = array("sessionId"=>$sessionId, "challenge"=>$challenge, "spIdentifier" => $spIdentifier);
431 431
         
432
-        if ($userId!="") {
432
+        if ($userId != "") {
433 433
             $data["userId"] = $userId;
434 434
         }
435 435
         
@@ -453,9 +453,9 @@  discard block
 block discarded – undo
453 453
      * @return String The enrollment key
454 454
      * @throws Exception when start the enrollement session failed
455 455
      */
456
-    public function startEnrollmentSession(string $userId, string $displayName, string $sessionId=""): string
456
+    public function startEnrollmentSession(string $userId, string $displayName, string $sessionId = ""): string
457 457
     {
458
-        if ($sessionId=="") {
458
+        if ($sessionId == "") {
459 459
             $sessionId = session_id();
460 460
         }
461 461
         $enrollmentKey = $this->_uniqueSessionKey();
@@ -475,9 +475,9 @@  discard block
 block discarded – undo
475 475
      * @param string $sessionId The application's session identifier (defaults to php session)
476 476
      * @throws Exception when resetting the session failed
477 477
      */
478
-    public function resetEnrollmentSession(string $sessionId=""): void
478
+    public function resetEnrollmentSession(string $sessionId = ""): void
479 479
     {
480
-        if ($sessionId=="") {
480
+        if ($sessionId == "") {
481 481
             $sessionId = session_id();
482 482
         }
483 483
 
@@ -512,9 +512,9 @@  discard block
 block discarded – undo
512 512
      *
513 513
      * @throws Exception when an error communicating with the state storage backend was detected
514 514
      */
515
-    public function getEnrollmentStatus(string $sessionId=""): int
515
+    public function getEnrollmentStatus(string $sessionId = ""): int
516 516
     { 
517
-        if ($sessionId=="") {
517
+        if ($sessionId == "") {
518 518
             $sessionId = session_id(); 
519 519
         }
520 520
         $status = $this->_getStateValue(self::PREFIX_ENROLLMENT_STATUS, $sessionId);
@@ -667,7 +667,7 @@  discard block
 block discarded – undo
667 667
             if (NULL === $data) {
668 668
                 throw new RuntimeException('Enrollment secret not found');
669 669
             }
670
-            if ( !is_array($data) || !is_string($data["userId"] ?? NULL)) {
670
+            if (!is_array($data) || !is_string($data["userId"] ?? NULL)) {
671 671
                 throw new RuntimeException('Invalid enrollment data');
672 672
             }
673 673
 
@@ -707,7 +707,7 @@  discard block
 block discarded – undo
707 707
                 $this->_setEnrollmentStatus($data["sessionId"], self::ENROLLMENT_STATUS_FINALIZED);
708 708
             } else {
709 709
                 $this->logger->error(
710
-                    'Enrollment status is not finalized, enrollmentsecret was not found in state storage. ' .
710
+                    'Enrollment status is not finalized, enrollmentsecret was not found in state storage. '.
711 711
                     'Warning! the method will still return "true" as a result.'
712 712
                 );
713 713
             }
@@ -765,9 +765,9 @@  discard block
 block discarded – undo
765 765
             throw $e;
766 766
         }
767 767
 
768
-        $sessionId = $state["sessionId"] ?? NULL;   // Application's sessionId
769
-        $challenge = $state["challenge"] ?? NULL;   // The challenge we sent to the Tiqr client
770
-        if (!is_string($sessionId) || (!is_string($challenge)) ) {
768
+        $sessionId = $state["sessionId"] ?? NULL; // Application's sessionId
769
+        $challenge = $state["challenge"] ?? NULL; // The challenge we sent to the Tiqr client
770
+        if (!is_string($sessionId) || (!is_string($challenge))) {
771 771
             throw new RuntimeException('Invalid state for state storage');
772 772
         }
773 773
 
@@ -776,7 +776,7 @@  discard block
 block discarded – undo
776 776
         $challengeUserId = $state["userId"] ?? NULL;
777 777
 
778 778
         // If the application requested a specific userId, verify that that is that userId that we're now authenticating
779
-        if ($challengeUserId!==NULL && ($userId !== $challengeUserId)) {
779
+        if ($challengeUserId !== NULL && ($userId !== $challengeUserId)) {
780 780
             $this->logger->error(
781 781
                 sprintf('Authentication failed: the requested userId "%s" does not match userId "%s" that is being authenticated',
782 782
                 $challengeUserId, $userId)
@@ -824,9 +824,9 @@  discard block
 block discarded – undo
824 824
      *
825 825
      * @throws Exception when there was an error communicating with the storage backed
826 826
      */
827
-    public function logout(string $sessionId=""): void
827
+    public function logout(string $sessionId = ""): void
828 828
     {
829
-        if ($sessionId=="") {
829
+        if ($sessionId == "") {
830 830
             $sessionId = session_id(); 
831 831
         }
832 832
         
@@ -866,9 +866,9 @@  discard block
 block discarded – undo
866 866
      *
867 867
      * Does not throw
868 868
      */
869
-    public function getAuthenticatedUser(string $sessionId=""): ?string
869
+    public function getAuthenticatedUser(string $sessionId = ""): ?string
870 870
     {
871
-        if ($sessionId=="") {
871
+        if ($sessionId == "") {
872 872
             $this->logger->debug('Using the PHP session id, as no session id was provided');
873 873
             $sessionId = session_id(); 
874 874
         }
@@ -912,22 +912,22 @@  discard block
 block discarded – undo
912 912
         $challenge = $state["challenge"] ?? '';
913 913
         $spIdentifier = $state["spIdentifier"] ?? '';
914 914
 
915
-        if ( (strpos($this->_protocolAuth, 'https://') === 0) || (strpos($this->_protocolAuth, 'http://') === 0) ) {
915
+        if ((strpos($this->_protocolAuth, 'https://') === 0) || (strpos($this->_protocolAuth, 'http://') === 0)) {
916 916
             // Create universal Link
917
-            $parameters=array();
917
+            $parameters = array();
918 918
             if (!is_null($userId)) {
919
-                $parameters[]='u='.urlencode($userId);
919
+                $parameters[] = 'u='.urlencode($userId);
920 920
             }
921
-            $parameters[]='s='.urlencode($sessionKey);
922
-            $parameters[]='q='.urlencode($challenge);
923
-            $parameters[]='i='.urlencode($this->getIdentifier());
924
-            $parameters[]='v='.urlencode($this->_protocolVersion);
921
+            $parameters[] = 's='.urlencode($sessionKey);
922
+            $parameters[] = 'q='.urlencode($challenge);
923
+            $parameters[] = 'i='.urlencode($this->getIdentifier());
924
+            $parameters[] = 'v='.urlencode($this->_protocolVersion);
925 925
             return $this->_protocolAuth.'?'.implode('&', $parameters);
926 926
         }
927 927
 
928 928
         // Create custom URL scheme
929 929
         // Last bit is the spIdentifier
930
-        return $this->_protocolAuth."://".(!is_null($userId)?urlencode($userId).'@':'').$this->getIdentifier()."/".$sessionKey."/".$challenge."/".urlencode($spIdentifier)."/".$this->_protocolVersion;
930
+        return $this->_protocolAuth."://".(!is_null($userId) ?urlencode($userId).'@' : '').$this->getIdentifier()."/".$sessionKey."/".$challenge."/".urlencode($spIdentifier)."/".$this->_protocolVersion;
931 931
     }
932 932
 
933 933
     /**
@@ -938,7 +938,7 @@  discard block
 block discarded – undo
938 938
     {
939 939
         // The are two formats see: https://tiqr.org/technical/protocol/
940 940
 
941
-        if ( (strpos($this->_protocolEnroll, 'https://') === 0) || (strpos($this->_protocolEnroll, 'http://') === 0) ) {
941
+        if ((strpos($this->_protocolEnroll, 'https://') === 0) || (strpos($this->_protocolEnroll, 'http://') === 0)) {
942 942
             // Create universal Link
943 943
             return $this->_protocolEnroll.'?metadata='.urlencode($metadataUrl);
944 944
         }
@@ -957,7 +957,7 @@  discard block
 block discarded – undo
957 957
     protected function _uniqueSessionKey(): string
958 958
     {
959 959
 
960
-        return bin2hex( Tiqr_Random::randomBytes(self::SESSION_KEY_LENGTH_BYTES) );
960
+        return bin2hex(Tiqr_Random::randomBytes(self::SESSION_KEY_LENGTH_BYTES));
961 961
     }
962 962
     
963 963
     /**
@@ -988,7 +988,7 @@  discard block
 block discarded – undo
988 988
      */
989 989
     protected function _setStateValue(string $key_prefix, string $key, $value, int $expire): void {
990 990
         $this->_stateStorage->setValue(
991
-            $key_prefix . $this->_hashKey($key),
991
+            $key_prefix.$this->_hashKey($key),
992 992
             $value,
993 993
             $expire
994 994
         );
@@ -1005,7 +1005,7 @@  discard block
 block discarded – undo
1005 1005
 
1006 1006
     protected function _getStateValue(string $key_prefix, string $key) {
1007 1007
         return $this->_stateStorage->getValue(
1008
-            $key_prefix . $this->_hashKey($key)
1008
+            $key_prefix.$this->_hashKey($key)
1009 1009
         );
1010 1010
     }
1011 1011
 
@@ -1019,7 +1019,7 @@  discard block
 block discarded – undo
1019 1019
      */
1020 1020
     protected function _unsetStateValue(string $key_prefix, string $key): void {
1021 1021
         $this->_stateStorage->unsetValue(
1022
-            $key_prefix . $this->_hashKey($key)
1022
+            $key_prefix.$this->_hashKey($key)
1023 1023
         );
1024 1024
     }
1025 1025
 
Please login to merge, or discard this patch.
Braces   +10 added lines, -9 removed lines patch added patch discarded remove patch
@@ -290,8 +290,7 @@  discard block
 block discarded – undo
290 290
         if (isset($options['ocraservice']) && $options['ocraservice']['type'] != 'tiqr') {
291 291
             $options['ocraservice']['ocra.suite'] = $this->_ocraSuite;
292 292
             $this->_ocraService = Tiqr_OcraService::getOcraService($options['ocraservice']['type'], $options['ocraservice'], $logger);
293
-        }
294
-        else { // Create default ocraservice
293
+        } else { // Create default ocraservice
295 294
             $this->_ocraService = Tiqr_OcraService::getOcraService('tiqr', array('ocra.suite' => $this->_ocraSuite), $logger);
296 295
         }
297 296
     }
@@ -350,10 +349,11 @@  discard block
 block discarded – undo
350 349
                 case 'APNS':
351 350
                 case 'APNS_DIRECT':
352 351
                     $apns_version = $this->_options['apns.version'] ?? 1;
353
-                    if ($apns_version ==2 )
354
-                        $message = new Tiqr_Message_APNS2($this->_options, $this->logger);
355
-                    else
356
-                        $message = new Tiqr_Message_APNS($this->_options, $this->logger);
352
+                    if ($apns_version ==2 ) {
353
+                                            $message = new Tiqr_Message_APNS2($this->_options, $this->logger);
354
+                    } else {
355
+                                            $message = new Tiqr_Message_APNS($this->_options, $this->logger);
356
+                    }
357 357
                     break;
358 358
 
359 359
                 case 'GCM':
@@ -518,7 +518,9 @@  discard block
 block discarded – undo
518 518
             $sessionId = session_id(); 
519 519
         }
520 520
         $status = $this->_getStateValue(self::PREFIX_ENROLLMENT_STATUS, $sessionId);
521
-        if (is_null($status)) return self::ENROLLMENT_STATUS_IDLE;
521
+        if (is_null($status)) {
522
+            return self::ENROLLMENT_STATUS_IDLE;
523
+        }
522 524
         return $status;
523 525
     }
524 526
         
@@ -875,8 +877,7 @@  discard block
 block discarded – undo
875 877
         
876 878
         try {
877 879
             return $this->_getStateValue("authenticated_", $sessionId);
878
-        }
879
-        catch (Exception $e) {
880
+        } catch (Exception $e) {
880 881
             $this->logger->error('getAuthenticatedUser failed', array('exception'=>$e));
881 882
             return NULL;
882 883
         }
Please login to merge, or discard this patch.
library/tiqr/Tiqr/UserStorage/Pdo.php 3 patches
Indentation   -2 removed lines patch added patch discarded remove patch
@@ -30,13 +30,11 @@
 block discarded – undo
30 30
     notificationtype varchar(10),
31 31
     notificationaddress varchar(64)
32 32
 );
33
-
34 33
  *
35 34
  * In version 3.0 the format of the tmpblocktimestamp was changed from a datetime format to an integer.
36 35
  * Because it holds a unix timestamp a 64-bit (8-byte) integer. To upgrade the user table to the new format use:
37 36
 
38 37
 ALTER TABLE user MODIFY tmpblocktimestamp BIGINT;
39
-
40 38
  */
41 39
 
42 40
 use Psr\Log\LoggerInterface;
Please login to merge, or discard this patch.
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -89,21 +89,21 @@  discard block
 block discarded – undo
89 89
      */
90 90
     private function _getStringValue(string $columnName, string $userId): string
91 91
     {
92
-        if ( !in_array($columnName, $this->_allowedStringColumns) ) {
92
+        if (!in_array($columnName, $this->_allowedStringColumns)) {
93 93
             throw new InvalidArgumentException('Unsupported column name');
94 94
         }
95 95
 
96 96
         try {
97
-            $sth = $this->handle->prepare('SELECT ' . $columnName . ' FROM ' . $this->tablename . ' WHERE userid = ?');
97
+            $sth = $this->handle->prepare('SELECT '.$columnName.' FROM '.$this->tablename.' WHERE userid = ?');
98 98
             $sth->execute(array($userId));
99
-            $res=$sth->fetchColumn();
99
+            $res = $sth->fetchColumn();
100 100
             if ($res === false) {
101 101
                 // No result
102 102
                 $this->logger->error(sprintf('No result getting "%s" for user "%s"', $columnName, $userId));
103 103
                 throw new RuntimeException('User not found');
104 104
             }
105 105
             if ($res === NULL) {
106
-                return '';  // Value unset
106
+                return ''; // Value unset
107 107
             }
108 108
             if (!is_string($res)) {
109 109
                 $this->logger->error(sprintf('Expected string type while getting "%s" for user "%s"', $columnName, $userId));
@@ -127,28 +127,28 @@  discard block
 block discarded – undo
127 127
      */
128 128
     private function _getIntValue(string $columnName, string $userId): int
129 129
     {
130
-        if ( !in_array($columnName, $this->_allowedIntColumns) ) {
130
+        if (!in_array($columnName, $this->_allowedIntColumns)) {
131 131
             throw new InvalidArgumentException('Unsupported column name');
132 132
         }
133 133
 
134 134
         try {
135
-            $sth = $this->handle->prepare('SELECT ' . $columnName . ' FROM ' . $this->tablename . ' WHERE userid = ?');
135
+            $sth = $this->handle->prepare('SELECT '.$columnName.' FROM '.$this->tablename.' WHERE userid = ?');
136 136
             $sth->execute(array($userId));
137
-            $res=$sth->fetchColumn();
137
+            $res = $sth->fetchColumn();
138 138
             if ($res === false) {
139 139
                 // No result
140 140
                 $this->logger->error(sprintf('No result getting "%s" for user "%s"', $columnName, $userId));
141 141
                 throw new RuntimeException('User not found');
142 142
             }
143 143
             if ($res === NULL) {
144
-                return 0;  // Value unset
144
+                return 0; // Value unset
145 145
             }
146 146
             // Return type for integers depends on the PDO driver, can be string
147 147
             if (!is_numeric($res)) {
148 148
                 $this->logger->error(sprintf('Expected int type while getting "%s" for user "%s"', $columnName, $userId));
149 149
                 throw new RuntimeException('Unexpected return type');
150 150
             }
151
-            return (int)$res;
151
+            return (int) $res;
152 152
         }
153 153
         catch (Exception $e) {
154 154
             $this->logger->error('PDO error getting user', array('exception' => $e, 'userId' => $userId, 'columnName'=>$columnName));
@@ -165,11 +165,11 @@  discard block
 block discarded – undo
165 165
      */
166 166
     private function _setStringValue(string $columnName, string $userId, string $value): void
167 167
     {
168
-        if ( !in_array($columnName, $this->_allowedStringColumns) ) {
168
+        if (!in_array($columnName, $this->_allowedStringColumns)) {
169 169
             throw new InvalidArgumentException('Unsupported column name');
170 170
         }
171 171
         try {
172
-            $sth = $this->handle->prepare('UPDATE ' . $this->tablename . ' SET ' . $columnName . ' = ? WHERE userid = ?');
172
+            $sth = $this->handle->prepare('UPDATE '.$this->tablename.' SET '.$columnName.' = ? WHERE userid = ?');
173 173
             $sth->execute(array($value, $userId));
174 174
             if ($sth->rowCount() == 0) {
175 175
                 // Required for mysql which only returns the number of rows that were actually updated
@@ -193,11 +193,11 @@  discard block
 block discarded – undo
193 193
      */
194 194
     private function _setIntValue(string $columnName, string $userId, int $value): void
195 195
     {
196
-        if ( !in_array($columnName, $this->_allowedIntColumns) ) {
196
+        if (!in_array($columnName, $this->_allowedIntColumns)) {
197 197
             throw new InvalidArgumentException('Unsupported column name');
198 198
         }
199 199
         try {
200
-            $sth = $this->handle->prepare('UPDATE ' . $this->tablename . ' SET ' . $columnName . ' = ? WHERE userid = ?');
200
+            $sth = $this->handle->prepare('UPDATE '.$this->tablename.' SET '.$columnName.' = ? WHERE userid = ?');
201 201
             $sth->execute(array($value, $userId));
202 202
             if ($sth->rowCount() == 0) {
203 203
                 // Required for mysql which only returns the number of rows that were actually updated
@@ -309,17 +309,17 @@  discard block
 block discarded – undo
309 309
     {
310 310
         // Check for blocked
311 311
         if ($this->_getIntValue('blocked', $userId) != 0) {
312
-            return true;   // Blocked
312
+            return true; // Blocked
313 313
         }
314 314
 
315 315
         if (0 == $tempBlockDuration) {
316
-            return false;   // No check for temporary block
316
+            return false; // No check for temporary block
317 317
         }
318 318
 
319 319
         // Check for temporary block
320 320
         $timestamp = $this->getTemporaryBlockTimestamp($userId);
321 321
         // if no temporary block timestamp is set or if the temporary block is expired, return false
322
-        if ( 0 == $timestamp || ($timestamp + $tempBlockDuration * 60) < time()) {
322
+        if (0 == $timestamp || ($timestamp + $tempBlockDuration * 60) < time()) {
323 323
             return false;
324 324
         }
325 325
         return true;
Please login to merge, or discard this patch.
Braces   +6 added lines, -12 removed lines patch added patch discarded remove patch
@@ -110,8 +110,7 @@  discard block
 block discarded – undo
110 110
                 throw new RuntimeException('Unexpected return type');
111 111
             }
112 112
             return $res;
113
-        }
114
-        catch (Exception $e) {
113
+        } catch (Exception $e) {
115 114
             $this->logger->error('PDO error getting user', array('exception' => $e, 'userId' => $userId, 'columnName'=>$columnName));
116 115
             throw ReadWriteException::fromOriginalException($e);
117 116
         }
@@ -149,8 +148,7 @@  discard block
 block discarded – undo
149 148
                 throw new RuntimeException('Unexpected return type');
150 149
             }
151 150
             return (int)$res;
152
-        }
153
-        catch (Exception $e) {
151
+        } catch (Exception $e) {
154 152
             $this->logger->error('PDO error getting user', array('exception' => $e, 'userId' => $userId, 'columnName'=>$columnName));
155 153
             throw ReadWriteException::fromOriginalException($e);
156 154
         }
@@ -177,8 +175,7 @@  discard block
 block discarded – undo
177 175
                     throw new RuntimeException('User not found');
178 176
                 }
179 177
             }
180
-        }
181
-        catch (Exception $e) {
178
+        } catch (Exception $e) {
182 179
             $this->logger->error('PDO error updating user', array('exception' => $e, 'userId' => $userId, 'columnName'=>$columnName));
183 180
             throw ReadWriteException::fromOriginalException($e);
184 181
         }
@@ -205,8 +202,7 @@  discard block
 block discarded – undo
205 202
                     throw new RuntimeException('User not found');
206 203
                 }
207 204
             }
208
-        }
209
-        catch (Exception $e) {
205
+        } catch (Exception $e) {
210 206
             $this->logger->error('PDO error updating user', array('exception' => $e, 'userId' => $userId, 'columnName'=>$columnName));
211 207
             throw ReadWriteException::fromOriginalException($e);
212 208
         }
@@ -223,8 +219,7 @@  discard block
 block discarded – undo
223 219
         try {
224 220
             $sth = $this->handle->prepare("INSERT INTO ".$this->tablename." (displayname,userid) VALUES (?,?)");
225 221
             $sth->execute(array($displayName, $userId));
226
-        }
227
-        catch (Exception $e) {
222
+        } catch (Exception $e) {
228 223
             $this->logger->error(sprintf('Error creating user "%s"', $userId), array('exception'=>$e));
229 224
             throw new ReadWriteException('The user could not be saved in the user storage (PDO)');
230 225
         }
@@ -239,8 +234,7 @@  discard block
 block discarded – undo
239 234
             $sth = $this->handle->prepare("SELECT userid FROM ".$this->tablename." WHERE userid = ?");
240 235
             $sth->execute(array($userId));
241 236
             return (false !== $sth->fetchColumn());
242
-        }
243
-        catch (Exception $e) {
237
+        } catch (Exception $e) {
244 238
             $this->logger->error('PDO error checking user exists', array('exception'=>$e, 'userId'=>$userId));
245 239
             throw ReadWriteException::fromOriginalException($e);
246 240
         }
Please login to merge, or discard this patch.
library/tiqr/Tiqr/Message/APNS2.php 2 patches
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -23,11 +23,11 @@  discard block
 block discarded – undo
23 23
         $options = $this->getOptions();
24 24
         if (isset($options['apns.proxy_host_url'])) {
25 25
             // Override CURL options to connect to a HTTP/1.1 to HTTP/2 proxy
26
-            $curl_options[CURLOPT_URL] = $options['apns.proxy_host_url'] . '/3/device/' . $this->getAddress();
26
+            $curl_options[CURLOPT_URL] = $options['apns.proxy_host_url'].'/3/device/'.$this->getAddress();
27 27
             $curl_options[CURLOPT_PORT] = $options['apns.proxy_host_port'] ?? 443;
28 28
             // Use HTTP/1.1 instead of HTTP/2
29 29
             $curl_options[CURLOPT_HTTP_VERSION] = CURL_HTTP_VERSION_1_1;
30
-            $this->logger->notice(sprintf('Using HTTP/1.1 CURL Proxy URL: "%s" and port "%s"',  $curl_options[CURLOPT_URL], $curl_options[CURLOPT_URL]));
30
+            $this->logger->notice(sprintf('Using HTTP/1.1 CURL Proxy URL: "%s" and port "%s"', $curl_options[CURLOPT_URL], $curl_options[CURLOPT_URL]));
31 31
         }
32 32
         else {
33 33
             $version_info = curl_version();
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
 
39 39
         // Get the UID from the client certificate we use for authentication, this
40 40
         // is set to the bundle ID.
41
-        $options=$this->getOptions();
41
+        $options = $this->getOptions();
42 42
         $cert_filename = $options['apns.certificate'];
43 43
         $cert_file_contents = file_get_contents($cert_filename);
44 44
         if (false === $cert_file_contents) {
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
             );
48 48
         }
49 49
 
50
-        $cert=openssl_x509_parse( $cert_file_contents );
50
+        $cert = openssl_x509_parse($cert_file_contents);
51 51
         if (false === $cert) {
52 52
             throw new RuntimeException('Error parsing APNS client certificate');
53 53
         }
@@ -72,42 +72,42 @@  discard block
 block discarded – undo
72 72
         $authProvider = AuthProvider\Certificate::create($authProviderOptions);
73 73
 
74 74
         // Create the push message
75
-        $alert=Alert::create();
75
+        $alert = Alert::create();
76 76
         $alert->setBody($this->getText());
77 77
         // Note: It is possible to specify a title and a subtitle: $alert->setTitle() && $alert->setSubtitle()
78 78
         //       The tiqr service currently does not implement this.
79
-        $payload=Payload::create()->setAlert($alert);
79
+        $payload = Payload::create()->setAlert($alert);
80 80
         $payload->setSound('default');
81 81
         foreach ($this->getCustomProperties() as $name => $value) {
82 82
             $payload->setCustomValue($name, $value);
83 83
         }
84 84
         $this->logger->debug(sprintf('JSON Payload: %s', $payload->toJson()));
85
-        $notification=new Notification($payload, $this->getAddress());
85
+        $notification = new Notification($payload, $this->getAddress());
86 86
         // Set expiration to 30 seconds from now, same as Message_APNS
87 87
         $now = new DateTime();
88
-        $expirationInstant=$now->add(new DateInterval('PT30S'));
88
+        $expirationInstant = $now->add(new DateInterval('PT30S'));
89 89
         $notification->setExpirationAt($expirationInstant);
90 90
 
91 91
         // Send the push message
92 92
         $client = new Client($authProvider, $options['apns.environment'] == 'production', $curl_options);
93 93
         $client->addNotification($notification);
94
-        $responses=$client->push();
95
-        if ( sizeof($responses) != 1) {
96
-            $this->logger->warning(sprintf('Unexpected number responses. Expected 1, got %d', sizeof($responses)) );
94
+        $responses = $client->push();
95
+        if (sizeof($responses) != 1) {
96
+            $this->logger->warning(sprintf('Unexpected number responses. Expected 1, got %d', sizeof($responses)));
97 97
             if (sizeof($responses) == 0) {
98 98
                 $this->logger->warning('Could not determine whether the notification was sent');
99 99
                 return;
100 100
             }
101 101
         }
102 102
         /** @var \Pushok\Response $response */
103
-        $response = reset($responses);  // Get first response from the array
104
-        $deviceToken=$response->getDeviceToken() ?? '';
103
+        $response = reset($responses); // Get first response from the array
104
+        $deviceToken = $response->getDeviceToken() ?? '';
105 105
         // A canonical UUID that is the unique ID for the notification. E.g. 123e4567-e89b-12d3-a456-4266554400a0
106
-        $apnsId=$response->getApnsId() ?? '';
106
+        $apnsId = $response->getApnsId() ?? '';
107 107
         // Status code. E.g. 200 (Success), 410 (The device token is no longer active for the topic.)
108
-        $statusCode=$response->getStatusCode();
108
+        $statusCode = $response->getStatusCode();
109 109
         $this->logger->info(sprintf('Got response with ApnsId "%s", status %s for deviceToken "%s"', $apnsId, $statusCode, $deviceToken));
110
-        if ( strcasecmp($deviceToken, $this->getAddress()) ) {
110
+        if (strcasecmp($deviceToken, $this->getAddress())) {
111 111
         $this->logger->warning(sprintf('Unexpected deviceToken in response. Expected: "%s"; got: "%s"', $this->getAddress(), $deviceToken));
112 112
         }
113 113
         if ($statusCode == 200) {
@@ -115,9 +115,9 @@  discard block
 block discarded – undo
115 115
             return;
116 116
         }
117 117
 
118
-        $reasonPhrase=$response->getReasonPhrase(); // E.g. The device token is no longer active for the topic.
119
-        $errorReason=$response->getErrorReason(); // E.g. Unregistered
120
-        $errorDescription=$response->getErrorDescription(); // E.g. The device token is inactive for the specified topic.
118
+        $reasonPhrase = $response->getReasonPhrase(); // E.g. The device token is no longer active for the topic.
119
+        $errorReason = $response->getErrorReason(); // E.g. Unregistered
120
+        $errorDescription = $response->getErrorDescription(); // E.g. The device token is inactive for the specified topic.
121 121
 
122 122
         $this->logger->error(sprintf('Error sending APNS2 push notification. APNS ID: "%s"; deviceToken: "%s"; Error: "%s" "%s" "%s"', $apnsId, $deviceToken, $reasonPhrase, $errorReason, $errorDescription));
123 123
         throw new RuntimeException(
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -28,8 +28,7 @@
 block discarded – undo
28 28
             // Use HTTP/1.1 instead of HTTP/2
29 29
             $curl_options[CURLOPT_HTTP_VERSION] = CURL_HTTP_VERSION_1_1;
30 30
             $this->logger->notice(sprintf('Using HTTP/1.1 CURL Proxy URL: "%s" and port "%s"',  $curl_options[CURLOPT_URL], $curl_options[CURLOPT_URL]));
31
-        }
32
-        else {
31
+        } else {
33 32
             $version_info = curl_version();
34 33
             if ($version_info['features'] & CURL_VERSION_HTTP2 == 0) {
35 34
                 throw new RuntimeException('APNS2 requires HTTP/2 support in curl');
Please login to merge, or discard this patch.
library/tiqr/Tiqr/StateStorage/Pdo.php 3 patches
Braces   +5 added lines, -10 removed lines patch added patch discarded remove patch
@@ -80,8 +80,7 @@  discard block
 block discarded – undo
80 80
             $sth = $this->handle->prepare('SELECT `key` FROM ' . $this->tablename . ' WHERE `key` = ?');
81 81
             $sth->execute(array($key));
82 82
             return $sth->fetchColumn() !== false;
83
-        }
84
-        catch (Exception $e) {
83
+        } catch (Exception $e) {
85 84
             $this->logger->error(
86 85
                 sprintf('Error checking for key "%s" in PDO StateStorage', $key),
87 86
                 array('exception' => $e)
@@ -103,8 +102,7 @@  discard block
 block discarded – undo
103 102
             $this->logger->notice(
104 103
                 sprintf("Deleted %d expired keys", $deletedRows)
105 104
             );
106
-        }
107
-        catch (Exception $e) {
105
+        } catch (Exception $e) {
108 106
             $this->logger->error(
109 107
                 sprintf("Deleting expired keys failed: %s", $e->getMessage()),
110 108
                 array('exception', $e)
@@ -134,8 +132,7 @@  discard block
 block discarded – undo
134 132
         }
135 133
         try {
136 134
             $sth->execute(array(serialize($value), $expire, $key));
137
-        }
138
-        catch (Exception $e) {
135
+        } catch (Exception $e) {
139 136
             $this->logger->error(
140 137
                 sprintf('Unable to store key "%s" in PDO StateStorage', $key),
141 138
                 array('exception' => $e)
@@ -155,8 +152,7 @@  discard block
 block discarded – undo
155 152
         try {
156 153
             $sth = $this->handle->prepare("DELETE FROM " . $this->tablename . " WHERE `key` = ?");
157 154
             $sth->execute(array($key));
158
-        }
159
-        catch (Exception $e) {
155
+        } catch (Exception $e) {
160 156
             $this->logger->error(
161 157
                 sprintf('Error deleting key "%s" from PDO StateStorage', $key),
162 158
                 array('exception' => $e)
@@ -185,8 +181,7 @@  discard block
 block discarded – undo
185 181
         try {
186 182
             $sth = $this->handle->prepare('SELECT `value` FROM ' . $this->tablename . ' WHERE `key` = ? AND (`expire` >= ? OR `expire` = 0)');
187 183
             $sth->execute(array($key, time()));
188
-        }
189
-        catch (Exception $e) {
184
+        } catch (Exception $e) {
190 185
             $this->logger->error(
191 186
                 sprintf('Error getting value for key "%s" from PDO StateStorage', $key),
192 187
                 array('exception' => $e)
Please login to merge, or discard this patch.
Indentation   -1 removed lines patch added patch discarded remove patch
@@ -59,7 +59,6 @@
 block discarded – undo
59 59
 );
60 60
 
61 61
 CREATE INDEX IF NOT EXISTS index_tiqrstate_expire ON tiqrstate (expire);
62
-
63 62
  * @see Tiqr_StateStorage::getStorage()
64 63
  * @see Tiqr_StateStorage_StateStorageInterface
65 64
  *
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
             throw new InvalidArgumentException('Empty key not allowed');
122 122
         }
123 123
         try {
124
-            $sth = $this->handle->prepare('SELECT `key` FROM ' . $this->tablename . ' WHERE `key` = ?');
124
+            $sth = $this->handle->prepare('SELECT `key` FROM '.$this->tablename.' WHERE `key` = ?');
125 125
             $sth->execute(array($key));
126 126
             return $sth->fetchColumn() !== false;
127 127
         }
@@ -141,9 +141,9 @@  discard block
 block discarded – undo
141 141
      */
142 142
     private function cleanExpired(): void {
143 143
         try {
144
-            $sth = $this->handle->prepare("DELETE FROM " . $this->tablename . " WHERE `expire` < ? AND NOT `expire` = 0");
144
+            $sth = $this->handle->prepare("DELETE FROM ".$this->tablename." WHERE `expire` < ? AND NOT `expire` = 0");
145 145
             $sth->execute(array(time()));
146
-            $deletedRows=$sth->rowCount();
146
+            $deletedRows = $sth->rowCount();
147 147
             $this->logger->notice(
148 148
                 sprintf("Deleted %d expired keys", $deletedRows)
149 149
             );
@@ -159,12 +159,12 @@  discard block
 block discarded – undo
159 159
     /**
160 160
      * @see Tiqr_StateStorage_StateStorageInterface::setValue()
161 161
      */
162
-    public function setValue(string $key, $value, int $expire=0): void
162
+    public function setValue(string $key, $value, int $expire = 0): void
163 163
     {
164 164
         if (empty($key)) {
165 165
             throw new InvalidArgumentException('Empty key not allowed');
166 166
         }
167
-        if (((float) rand() /(float) getrandmax()) < $this->cleanupProbability) {
167
+        if (((float) rand() / (float) getrandmax()) < $this->cleanupProbability) {
168 168
             $this->cleanExpired();
169 169
         }
170 170
         if ($this->keyExists($key)) {
@@ -174,7 +174,7 @@  discard block
 block discarded – undo
174 174
         }
175 175
         // $expire == 0 means never expire
176 176
         if ($expire != 0) {
177
-            $expire+=time();    // Store unix timestamp after which the key expires
177
+            $expire += time(); // Store unix timestamp after which the key expires
178 178
         }
179 179
         try {
180 180
             $sth->execute(array(serialize($value), $expire, $key));
@@ -197,7 +197,7 @@  discard block
 block discarded – undo
197 197
             throw new InvalidArgumentException('Empty key not allowed');
198 198
         }
199 199
         try {
200
-            $sth = $this->handle->prepare("DELETE FROM " . $this->tablename . " WHERE `key` = ?");
200
+            $sth = $this->handle->prepare("DELETE FROM ".$this->tablename." WHERE `key` = ?");
201 201
             $sth->execute(array($key));
202 202
         }
203 203
         catch (Exception $e) {
@@ -227,7 +227,7 @@  discard block
 block discarded – undo
227 227
         }
228 228
 
229 229
         try {
230
-            $sth = $this->handle->prepare('SELECT `value` FROM ' . $this->tablename . ' WHERE `key` = ? AND (`expire` >= ? OR `expire` = 0)');
230
+            $sth = $this->handle->prepare('SELECT `value` FROM '.$this->tablename.' WHERE `key` = ? AND (`expire` >= ? OR `expire` = 0)');
231 231
             $sth->execute(array($key, time()));
232 232
         }
233 233
         catch (Exception $e) {
@@ -241,9 +241,9 @@  discard block
 block discarded – undo
241 241
         if (false === $result) {
242 242
             // Occurs normally
243 243
             $this->logger->info(sprintf('getValue: Key "%s" not found in PDO StateStorage', $key));
244
-            return NULL;    // Key not found
244
+            return NULL; // Key not found
245 245
         }
246
-        $result=unserialize($result, array('allowed_classes' => false));
246
+        $result = unserialize($result, array('allowed_classes' => false));
247 247
         if (false === $result) {
248 248
             throw new RuntimeException(sprintf('getValue: unserialize error for key "%s" in PDO StateStorage', $key));
249 249
         }
Please login to merge, or discard this patch.
library/tiqr/Tiqr/UserSecretStorage.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -74,7 +74,7 @@
 block discarded – undo
74 74
                 $password = $options['password'];
75 75
 
76 76
                 try {
77
-                    $handle = new PDO($dsn, $userName, $password, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION) );
77
+                    $handle = new PDO($dsn, $userName, $password, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
78 78
                 } catch (PDOException $e) {
79 79
                     $logger->error(
80 80
                         sprintf('Unable to establish a PDO connection. Error message from PDO: %s', $e->getMessage())
Please login to merge, or discard this patch.