@@ -29,7 +29,7 @@ |
||
29 | 29 | * @throws ReadWriteException |
30 | 30 | * @throws Exception |
31 | 31 | */ |
32 | - public function setValue(string $key, $value, int $expire=0): void; |
|
32 | + public function setValue(string $key, $value, int $expire = 0): void; |
|
33 | 33 | |
34 | 34 | /** |
35 | 35 | * Remove $key from the state storage |
@@ -54,8 +54,8 @@ |
||
54 | 54 | } |
55 | 55 | |
56 | 56 | $envelope = array("expire"=>$expire, |
57 | - "createdAt"=>time(), |
|
58 | - "value"=>$value); |
|
57 | + "createdAt"=>time(), |
|
58 | + "value"=>$value); |
|
59 | 59 | $filename = $this->getFilenameByKey($key); |
60 | 60 | |
61 | 61 | if (!file_put_contents($filename, serialize($envelope))) { |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | /** |
48 | 48 | * @see Tiqr_StateStorage_StateStorageInterface::setValue() |
49 | 49 | */ |
50 | - public function setValue(string $key, $value, int $expire=0): void |
|
50 | + public function setValue(string $key, $value, int $expire = 0): void |
|
51 | 51 | { |
52 | 52 | if (empty($key)) { |
53 | 53 | throw new InvalidArgumentException('Empty key not allowed'); |
@@ -109,8 +109,8 @@ discard block |
||
109 | 109 | |
110 | 110 | private function getPath(): string |
111 | 111 | { |
112 | - if (substr($this->path, -1)!=="/") { |
|
113 | - return $this->path . "/"; |
|
112 | + if (substr($this->path, -1) !== "/") { |
|
113 | + return $this->path."/"; |
|
114 | 114 | } |
115 | 115 | return $this->path; |
116 | 116 | } |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | * The default configuration |
52 | 52 | */ |
53 | 53 | const DEFAULT_HOST = '127.0.0.1'; |
54 | - const DEFAULT_PORT = 11211; |
|
54 | + const DEFAULT_PORT = 11211; |
|
55 | 55 | |
56 | 56 | /** |
57 | 57 | * Get the prefix to use for all keys in memcache. |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | /** |
104 | 104 | * @see Tiqr_StateStorage_StateStorageInterface::setValue() |
105 | 105 | */ |
106 | - public function setValue(string $key, $value, int $expire=0): void |
|
106 | + public function setValue(string $key, $value, int $expire = 0): void |
|
107 | 107 | { |
108 | 108 | if (empty($key)) { |
109 | 109 | throw new InvalidArgumentException('Empty key not allowed'); |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | if ($result === false) { |
158 | 158 | // Memcache interface does not provide error information, either the key does not exists or |
159 | 159 | // there was an error communicating with the memcache |
160 | - $this->logger->info( sprintf('Unable to get key "%s" from memcache StateStorage', $key) ); |
|
160 | + $this->logger->info(sprintf('Unable to get key "%s" from memcache StateStorage', $key)); |
|
161 | 161 | return null; |
162 | 162 | } |
163 | 163 | return $result; |
@@ -36,8 +36,7 @@ |
||
36 | 36 | // response as the client calculated. |
37 | 37 | try { |
38 | 38 | $expected = OCRA::generateOCRA($this->_ocraSuite, $userSecret, "", $challenge, "", $sessionInformation, ""); |
39 | - } |
|
40 | - catch (Exception $e) { |
|
39 | + } catch (Exception $e) { |
|
41 | 40 | $this->logger->warning(sprintf('Error calculating OCRA response for user "%s"', $userId), array('exception'=>$e)); |
42 | 41 | return false; |
43 | 42 | } |
@@ -81,7 +81,7 @@ |
||
81 | 81 | 'verifyResponse for user "%s" failed', |
82 | 82 | $userId |
83 | 83 | ), |
84 | - array( 'exception' => $e) |
|
84 | + array('exception' => $e) |
|
85 | 85 | ); |
86 | 86 | return false; |
87 | 87 | } |
@@ -42,7 +42,7 @@ |
||
42 | 42 | public static function randomBytes(int $length): string |
43 | 43 | { |
44 | 44 | // Get $length cryptographically secure pseudo-random bytes |
45 | - $rnd=\random_bytes($length); |
|
45 | + $rnd = \random_bytes($length); |
|
46 | 46 | |
47 | 47 | if (strlen($rnd) !== $length) { |
48 | 48 | throw new Exception("random_bytes did not return the requested number of bytes"); |
@@ -22,6 +22,6 @@ |
||
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 | } |
@@ -571,17 +571,17 @@ discard block |
||
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 |
||
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 | /** |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | // INVALID_USERID: The client authenticated a different user than the server expected. This error is returned when |
110 | 110 | // the application stated an authentication session specifying the userId and later during the authentication |
111 | 111 | // provides a different userId |
112 | - const AUTH_RESULT_INVALID_USERID = 5; |
|
112 | + const AUTH_RESULT_INVALID_USERID = 5; |
|
113 | 113 | |
114 | 114 | /** |
115 | 115 | * The default OCRA Suite (RFC 6287) to use for authentication in Tiqr |
@@ -244,7 +244,7 @@ discard block |
||
244 | 244 | * @param int $version The tiqr protocol version to use (defaults to the latest) |
245 | 245 | * @throws Exception |
246 | 246 | */ |
247 | - public function __construct(LoggerInterface $logger, array $options=array(), int $version = 2) |
|
247 | + public function __construct(LoggerInterface $logger, array $options = array(), int $version = 2) |
|
248 | 248 | { |
249 | 249 | $this->_options = $options; // Used to later get settings for Tiqr_Message_* |
250 | 250 | $this->logger = $logger; |
@@ -347,7 +347,7 @@ discard block |
||
347 | 347 | case 'APNS': |
348 | 348 | case 'APNS_DIRECT': |
349 | 349 | $apns_version = $this->_options['apns.version'] ?? 2; |
350 | - if ($apns_version !=2) |
|
350 | + if ($apns_version != 2) |
|
351 | 351 | throw new InvalidArgumentException("Unsupported APNS version '$apns_version'"); |
352 | 352 | $message = new Tiqr_Message_APNS2($this->_options, $this->logger); |
353 | 353 | break; |
@@ -364,7 +364,7 @@ discard block |
||
364 | 364 | |
365 | 365 | $this->logger->info(sprintf('Creating and sending a %s push notification', $notificationType)); |
366 | 366 | $message->setId(time()); |
367 | - $message->setText("Please authenticate for " . $this->_name); |
|
367 | + $message->setText("Please authenticate for ".$this->_name); |
|
368 | 368 | $message->setAddress($notificationAddress); |
369 | 369 | $message->setCustomProperty('challenge', $this->_getChallengeUrl($sessionKey)); |
370 | 370 | $message->send(); |
@@ -410,13 +410,13 @@ discard block |
||
410 | 410 | * @return string The authentication sessionKey |
411 | 411 | * @throws Exception when starting the authentication session failed |
412 | 412 | */ |
413 | - public function startAuthenticationSession(string $userId="", string $sessionId="", string $spIdentifier=""): string |
|
413 | + public function startAuthenticationSession(string $userId = "", string $sessionId = "", string $spIdentifier = ""): string |
|
414 | 414 | { |
415 | - if ($sessionId=="") { |
|
415 | + if ($sessionId == "") { |
|
416 | 416 | $sessionId = session_id(); |
417 | 417 | } |
418 | 418 | |
419 | - if ($spIdentifier=="") { |
|
419 | + if ($spIdentifier == "") { |
|
420 | 420 | $spIdentifier = $this->_identifier; |
421 | 421 | } |
422 | 422 | |
@@ -425,7 +425,7 @@ discard block |
||
425 | 425 | |
426 | 426 | $data = array("sessionId"=>$sessionId, "challenge"=>$challenge, "spIdentifier" => $spIdentifier); |
427 | 427 | |
428 | - if ($userId!="") { |
|
428 | + if ($userId != "") { |
|
429 | 429 | $data["userId"] = $userId; |
430 | 430 | } |
431 | 431 | |
@@ -449,9 +449,9 @@ discard block |
||
449 | 449 | * @return String The enrollment key |
450 | 450 | * @throws Exception when start the enrollement session failed |
451 | 451 | */ |
452 | - public function startEnrollmentSession(string $userId, string $displayName, string $sessionId=""): string |
|
452 | + public function startEnrollmentSession(string $userId, string $displayName, string $sessionId = ""): string |
|
453 | 453 | { |
454 | - if ($sessionId=="") { |
|
454 | + if ($sessionId == "") { |
|
455 | 455 | $sessionId = session_id(); |
456 | 456 | } |
457 | 457 | $enrollmentKey = $this->_uniqueSessionKey(); |
@@ -471,9 +471,9 @@ discard block |
||
471 | 471 | * @param string $sessionId The application's session identifier (defaults to php session) |
472 | 472 | * @throws Exception when resetting the session failed |
473 | 473 | */ |
474 | - public function resetEnrollmentSession(string $sessionId=""): void |
|
474 | + public function resetEnrollmentSession(string $sessionId = ""): void |
|
475 | 475 | { |
476 | - if ($sessionId=="") { |
|
476 | + if ($sessionId == "") { |
|
477 | 477 | $sessionId = session_id(); |
478 | 478 | } |
479 | 479 | |
@@ -508,9 +508,9 @@ discard block |
||
508 | 508 | * |
509 | 509 | * @throws Exception when an error communicating with the state storage backend was detected |
510 | 510 | */ |
511 | - public function getEnrollmentStatus(string $sessionId=""): int |
|
511 | + public function getEnrollmentStatus(string $sessionId = ""): int |
|
512 | 512 | { |
513 | - if ($sessionId=="") { |
|
513 | + if ($sessionId == "") { |
|
514 | 514 | $sessionId = session_id(); |
515 | 515 | } |
516 | 516 | $status = $this->_getStateValue(self::PREFIX_ENROLLMENT_STATUS, $sessionId); |
@@ -663,7 +663,7 @@ discard block |
||
663 | 663 | if (NULL === $data) { |
664 | 664 | throw new RuntimeException('Enrollment secret not found'); |
665 | 665 | } |
666 | - if ( !is_array($data) || !is_string($data["userId"] ?? NULL)) { |
|
666 | + if (!is_array($data) || !is_string($data["userId"] ?? NULL)) { |
|
667 | 667 | throw new RuntimeException('Invalid enrollment data'); |
668 | 668 | } |
669 | 669 | |
@@ -703,7 +703,7 @@ discard block |
||
703 | 703 | $this->_setEnrollmentStatus($data["sessionId"], self::ENROLLMENT_STATUS_FINALIZED); |
704 | 704 | } else { |
705 | 705 | $this->logger->error( |
706 | - 'Enrollment status is not finalized, enrollmentsecret was not found in state storage. ' . |
|
706 | + 'Enrollment status is not finalized, enrollmentsecret was not found in state storage. '. |
|
707 | 707 | 'Warning! the method will still return "true" as a result.' |
708 | 708 | ); |
709 | 709 | } |
@@ -761,9 +761,9 @@ discard block |
||
761 | 761 | throw $e; |
762 | 762 | } |
763 | 763 | |
764 | - $sessionId = $state["sessionId"] ?? NULL; // Application's sessionId |
|
765 | - $challenge = $state["challenge"] ?? NULL; // The challenge we sent to the Tiqr client |
|
766 | - if (!is_string($sessionId) || (!is_string($challenge)) ) { |
|
764 | + $sessionId = $state["sessionId"] ?? NULL; // Application's sessionId |
|
765 | + $challenge = $state["challenge"] ?? NULL; // The challenge we sent to the Tiqr client |
|
766 | + if (!is_string($sessionId) || (!is_string($challenge))) { |
|
767 | 767 | throw new RuntimeException('Invalid state for state storage'); |
768 | 768 | } |
769 | 769 | |
@@ -772,7 +772,7 @@ discard block |
||
772 | 772 | $challengeUserId = $state["userId"] ?? NULL; |
773 | 773 | |
774 | 774 | // If the application requested a specific userId, verify that that is that userId that we're now authenticating |
775 | - if ($challengeUserId!==NULL && ($userId !== $challengeUserId)) { |
|
775 | + if ($challengeUserId !== NULL && ($userId !== $challengeUserId)) { |
|
776 | 776 | $this->logger->error( |
777 | 777 | sprintf('Authentication failed: the requested userId "%s" does not match userId "%s" that is being authenticated', |
778 | 778 | $challengeUserId, $userId) |
@@ -820,9 +820,9 @@ discard block |
||
820 | 820 | * |
821 | 821 | * @throws Exception when there was an error communicating with the storage backed |
822 | 822 | */ |
823 | - public function logout(string $sessionId=""): void |
|
823 | + public function logout(string $sessionId = ""): void |
|
824 | 824 | { |
825 | - if ($sessionId=="") { |
|
825 | + if ($sessionId == "") { |
|
826 | 826 | $sessionId = session_id(); |
827 | 827 | } |
828 | 828 | |
@@ -862,9 +862,9 @@ discard block |
||
862 | 862 | * |
863 | 863 | * Does not throw |
864 | 864 | */ |
865 | - public function getAuthenticatedUser(string $sessionId=""): ?string |
|
865 | + public function getAuthenticatedUser(string $sessionId = ""): ?string |
|
866 | 866 | { |
867 | - if ($sessionId=="") { |
|
867 | + if ($sessionId == "") { |
|
868 | 868 | $this->logger->debug('Using the PHP session id, as no session id was provided'); |
869 | 869 | $sessionId = session_id(); |
870 | 870 | } |
@@ -908,22 +908,22 @@ discard block |
||
908 | 908 | $challenge = $state["challenge"] ?? ''; |
909 | 909 | $spIdentifier = $state["spIdentifier"] ?? ''; |
910 | 910 | |
911 | - if ( (strpos($this->_protocolAuth, 'https://') === 0) || (strpos($this->_protocolAuth, 'http://') === 0) ) { |
|
911 | + if ((strpos($this->_protocolAuth, 'https://') === 0) || (strpos($this->_protocolAuth, 'http://') === 0)) { |
|
912 | 912 | // Create universal Link |
913 | - $parameters=array(); |
|
913 | + $parameters = array(); |
|
914 | 914 | if (!is_null($userId)) { |
915 | - $parameters[]='u='.urlencode($userId); |
|
915 | + $parameters[] = 'u='.urlencode($userId); |
|
916 | 916 | } |
917 | - $parameters[]='s='.urlencode($sessionKey); |
|
918 | - $parameters[]='q='.urlencode($challenge); |
|
919 | - $parameters[]='i='.urlencode($this->getIdentifier()); |
|
920 | - $parameters[]='v='.urlencode($this->_protocolVersion); |
|
917 | + $parameters[] = 's='.urlencode($sessionKey); |
|
918 | + $parameters[] = 'q='.urlencode($challenge); |
|
919 | + $parameters[] = 'i='.urlencode($this->getIdentifier()); |
|
920 | + $parameters[] = 'v='.urlencode($this->_protocolVersion); |
|
921 | 921 | return $this->_protocolAuth.'?'.implode('&', $parameters); |
922 | 922 | } |
923 | 923 | |
924 | 924 | // Create custom URL scheme |
925 | 925 | // Last bit is the spIdentifier |
926 | - return $this->_protocolAuth."://".(!is_null($userId)?urlencode($userId).'@':'').$this->getIdentifier()."/".$sessionKey."/".$challenge."/".urlencode($spIdentifier)."/".$this->_protocolVersion; |
|
926 | + return $this->_protocolAuth."://".(!is_null($userId) ?urlencode($userId).'@' : '').$this->getIdentifier()."/".$sessionKey."/".$challenge."/".urlencode($spIdentifier)."/".$this->_protocolVersion; |
|
927 | 927 | } |
928 | 928 | |
929 | 929 | /** |
@@ -934,7 +934,7 @@ discard block |
||
934 | 934 | { |
935 | 935 | // The are two formats see: https://tiqr.org/technical/protocol/ |
936 | 936 | |
937 | - if ( (strpos($this->_protocolEnroll, 'https://') === 0) || (strpos($this->_protocolEnroll, 'http://') === 0) ) { |
|
937 | + if ((strpos($this->_protocolEnroll, 'https://') === 0) || (strpos($this->_protocolEnroll, 'http://') === 0)) { |
|
938 | 938 | // Create universal Link |
939 | 939 | return $this->_protocolEnroll.'?metadata='.urlencode($metadataUrl); |
940 | 940 | } |
@@ -953,7 +953,7 @@ discard block |
||
953 | 953 | protected function _uniqueSessionKey(): string |
954 | 954 | { |
955 | 955 | |
956 | - return bin2hex( Tiqr_Random::randomBytes(self::SESSION_KEY_LENGTH_BYTES) ); |
|
956 | + return bin2hex(Tiqr_Random::randomBytes(self::SESSION_KEY_LENGTH_BYTES)); |
|
957 | 957 | } |
958 | 958 | |
959 | 959 | /** |
@@ -984,7 +984,7 @@ discard block |
||
984 | 984 | */ |
985 | 985 | protected function _setStateValue(string $key_prefix, string $key, $value, int $expire): void { |
986 | 986 | $this->_stateStorage->setValue( |
987 | - $key_prefix . $this->_hashKey($key), |
|
987 | + $key_prefix.$this->_hashKey($key), |
|
988 | 988 | $value, |
989 | 989 | $expire |
990 | 990 | ); |
@@ -1001,7 +1001,7 @@ discard block |
||
1001 | 1001 | |
1002 | 1002 | protected function _getStateValue(string $key_prefix, string $key) { |
1003 | 1003 | return $this->_stateStorage->getValue( |
1004 | - $key_prefix . $this->_hashKey($key) |
|
1004 | + $key_prefix.$this->_hashKey($key) |
|
1005 | 1005 | ); |
1006 | 1006 | } |
1007 | 1007 | |
@@ -1015,7 +1015,7 @@ discard block |
||
1015 | 1015 | */ |
1016 | 1016 | protected function _unsetStateValue(string $key_prefix, string $key): void { |
1017 | 1017 | $this->_stateStorage->unsetValue( |
1018 | - $key_prefix . $this->_hashKey($key) |
|
1018 | + $key_prefix.$this->_hashKey($key) |
|
1019 | 1019 | ); |
1020 | 1020 | } |
1021 | 1021 |
@@ -287,8 +287,7 @@ discard block |
||
287 | 287 | if (isset($options['ocraservice']) && $options['ocraservice']['type'] != 'tiqr') { |
288 | 288 | $options['ocraservice']['ocra.suite'] = $this->_ocraSuite; |
289 | 289 | $this->_ocraService = Tiqr_OcraService::getOcraService($options['ocraservice']['type'], $options['ocraservice'], $logger); |
290 | - } |
|
291 | - else { // Create default ocraservice |
|
290 | + } else { // Create default ocraservice |
|
292 | 291 | $this->_ocraService = Tiqr_OcraService::getOcraService('tiqr', array('ocra.suite' => $this->_ocraSuite), $logger); |
293 | 292 | } |
294 | 293 | } |
@@ -347,8 +346,9 @@ discard block |
||
347 | 346 | case 'APNS': |
348 | 347 | case 'APNS_DIRECT': |
349 | 348 | $apns_version = $this->_options['apns.version'] ?? 2; |
350 | - if ($apns_version !=2) |
|
351 | - throw new InvalidArgumentException("Unsupported APNS version '$apns_version'"); |
|
349 | + if ($apns_version !=2) { |
|
350 | + throw new InvalidArgumentException("Unsupported APNS version '$apns_version'"); |
|
351 | + } |
|
352 | 352 | $message = new Tiqr_Message_APNS2($this->_options, $this->logger); |
353 | 353 | break; |
354 | 354 | |
@@ -514,7 +514,9 @@ discard block |
||
514 | 514 | $sessionId = session_id(); |
515 | 515 | } |
516 | 516 | $status = $this->_getStateValue(self::PREFIX_ENROLLMENT_STATUS, $sessionId); |
517 | - if (is_null($status)) return self::ENROLLMENT_STATUS_IDLE; |
|
517 | + if (is_null($status)) { |
|
518 | + return self::ENROLLMENT_STATUS_IDLE; |
|
519 | + } |
|
518 | 520 | return $status; |
519 | 521 | } |
520 | 522 | |
@@ -871,8 +873,7 @@ discard block |
||
871 | 873 | |
872 | 874 | try { |
873 | 875 | return $this->_getStateValue("authenticated_", $sessionId); |
874 | - } |
|
875 | - catch (Exception $e) { |
|
876 | + } catch (Exception $e) { |
|
876 | 877 | $this->logger->error('getAuthenticatedUser failed', array('exception'=>$e)); |
877 | 878 | return NULL; |
878 | 879 | } |
@@ -89,21 +89,21 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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; |
@@ -110,8 +110,7 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 | } |
@@ -30,13 +30,11 @@ |
||
30 | 30 | notificationtype varchar(10), |
31 | 31 | notificationaddress varchar(256) |
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; |