From 6f1cd6e11a64f8fcd2c8ceb17442f456d310f820 Mon Sep 17 00:00:00 2001
From: Florent Morselli <contact@spomky-labs.com>
Date: Tue, 28 Jan 2020 10:00:03 +0100
Subject: [PATCH] Update composer.json (#137)

* Update composer.json
* PHP 7.4 added to travis-ci
* PHPDoc and Typehint fixed
---
 .travis.yml            |  1 +
 composer.json          | 14 +++++++-------
 src/Factory.php        | 12 ++++++++++++
 src/HOTP.php           |  5 ++++-
 src/OTP.php            |  6 ++++++
 src/OTPInterface.php   |  3 +++
 src/ParameterTrait.php | 14 ++++++++++----
 src/TOTP.php           | 10 ++++++++--
 tests/TOTPTest.php     |  2 ++
 9 files changed, 53 insertions(+), 14 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index f64813f..835b621 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -4,6 +4,7 @@ language: php
 php:
     - 7.2
     - 7.3
+    - 7.4
     - nightly
 
 cache:
diff --git a/composer.json b/composer.json
index 2b32574..8979e8f 100644
--- a/composer.json
+++ b/composer.json
@@ -20,17 +20,17 @@
         "ext-mbstring": "*",
         "paragonie/constant_time_encoding": "^2.0",
         "beberlei/assert": "^3.0",
-        "thecodingmachine/safe": "^0.1.14"
+        "thecodingmachine/safe": "^0.1.14|^1.0"
     },
     "require-dev": {
         "phpunit/phpunit": "^8.0",
         "php-coveralls/php-coveralls": "^2.0",
-        "phpstan/phpstan": "^0.11",
-        "phpstan/phpstan-beberlei-assert": "^0.11.0",
-        "phpstan/phpstan-deprecation-rules": "^0.11",
-        "phpstan/phpstan-phpunit": "^0.11",
-        "phpstan/phpstan-strict-rules": "^0.11",
-        "thecodingmachine/phpstan-safe-rule": "^0.1.0"
+        "phpstan/phpstan": "^0.12",
+        "phpstan/phpstan-beberlei-assert": "^0.12",
+        "phpstan/phpstan-deprecation-rules": "^0.12",
+        "phpstan/phpstan-phpunit": "^0.12",
+        "phpstan/phpstan-strict-rules": "^0.12",
+        "thecodingmachine/phpstan-safe-rule": "^1.0"
     },
     "suggest": {
     },
diff --git a/src/Factory.php b/src/Factory.php
index f5be85c..70df639 100644
--- a/src/Factory.php
+++ b/src/Factory.php
@@ -41,6 +41,9 @@ final class Factory implements FactoryInterface
         return $otp;
     }
 
+    /**
+     * @param array<string, mixed> $data
+     */
     private static function populateParameters(OTPInterface &$otp, array $data): void
     {
         foreach ($data['query'] as $key => $value) {
@@ -48,6 +51,9 @@ final class Factory implements FactoryInterface
         }
     }
 
+    /**
+     * @param array<string, mixed> $data
+     */
     private static function populateOTP(OTPInterface &$otp, array $data): void
     {
         self::populateParameters($otp, $data);
@@ -66,6 +72,9 @@ final class Factory implements FactoryInterface
         $otp->setIssuer($result[0]);
     }
 
+    /**
+     * @param array<string, mixed> $data
+     */
     private static function checkData(array &$data): void
     {
         foreach (['scheme', 'host', 'path', 'query'] as $key) {
@@ -76,6 +85,9 @@ final class Factory implements FactoryInterface
         Assertion::keyExists($data['query'], 'secret', 'Not a valid OTP provisioning URI');
     }
 
+    /**
+     * @param array<string, mixed> $parsed_url
+     */
     private static function createOTP(array $parsed_url): OTPInterface
     {
         switch ($parsed_url['host']) {
diff --git a/src/HOTP.php b/src/HOTP.php
index 6facca0..a2f4a23 100644
--- a/src/HOTP.php
+++ b/src/HOTP.php
@@ -84,11 +84,14 @@ final class HOTP extends OTP implements HOTPInterface
         return false;
     }
 
+    /**
+     * @return array<string, mixed>
+     */
     protected function getParameterMap(): array
     {
         $v = array_merge(
             parent::getParameterMap(),
-            ['counter' => function ($value) {
+            ['counter' => function ($value): int {
                 Assertion::greaterOrEqualThan((int) $value, 0, 'Counter must be at least 0.');
 
                 return (int) $value;
diff --git a/src/OTP.php b/src/OTP.php
index d117ae6..932bcf9 100644
--- a/src/OTP.php
+++ b/src/OTP.php
@@ -58,6 +58,9 @@ abstract class OTP implements OTPInterface
         return $this->generateOTP($timestamp);
     }
 
+    /**
+     * @param array<string, mixed> $options
+     */
     protected function filterOptions(array &$options): void
     {
         foreach (['algorithm' => 'sha1', 'period' => 30, 'digits' => 6] as $key => $default) {
@@ -69,6 +72,9 @@ abstract class OTP implements OTPInterface
         ksort($options);
     }
 
+    /**
+     * @param array<string, mixed> $options
+     */
     protected function generateURI(string $type, array $options): string
     {
         $label = $this->getLabel();
diff --git a/src/OTPInterface.php b/src/OTPInterface.php
index 40dfd5b..66e163d 100644
--- a/src/OTPInterface.php
+++ b/src/OTPInterface.php
@@ -72,6 +72,9 @@ interface OTPInterface
 
     public function hasParameter(string $parameter): bool;
 
+    /**
+     * @return array<string, mixed>
+     */
     public function getParameters(): array;
 
     /**
diff --git a/src/ParameterTrait.php b/src/ParameterTrait.php
index a65b4b9..69fa774 100644
--- a/src/ParameterTrait.php
+++ b/src/ParameterTrait.php
@@ -21,7 +21,7 @@ use function Safe\sprintf;
 trait ParameterTrait
 {
     /**
-     * @var array
+     * @var array<string, mixed>
      */
     private $parameters = [];
 
@@ -40,6 +40,9 @@ trait ParameterTrait
      */
     private $issuer_included_as_parameter = true;
 
+    /**
+     * @return array<string, mixed>
+     */
     public function getParameters(): array
     {
         $parameters = $this->parameters;
@@ -141,6 +144,9 @@ trait ParameterTrait
         }
     }
 
+    /**
+     * @return array<string, mixed>
+     */
     protected function getParameterMap(): array
     {
         return [
@@ -149,7 +155,7 @@ trait ParameterTrait
 
                 return $value;
             },
-            'secret' => function ($value) {
+            'secret' => function ($value): string {
                 if (null === $value) {
                     $value = Base32::encodeUpper(random_bytes(64));
                 }
@@ -157,13 +163,13 @@ trait ParameterTrait
 
                 return $value;
             },
-            'algorithm' => function ($value) {
+            'algorithm' => function ($value): string {
                 $value = mb_strtolower($value);
                 Assertion::inArray($value, hash_algos(), sprintf('The "%s" digest is not supported.', $value));
 
                 return $value;
             },
-            'digits' => function ($value) {
+            'digits' => function ($value): int {
                 Assertion::greaterThan($value, 0, 'Digits must be at least 1.');
 
                 return (int) $value;
diff --git a/src/TOTP.php b/src/TOTP.php
index 9c0db82..588b37f 100644
--- a/src/TOTP.php
+++ b/src/TOTP.php
@@ -119,17 +119,20 @@ final class TOTP extends OTP implements TOTPInterface
         return (int) floor(($timestamp - $this->getEpoch()) / $this->getPeriod());
     }
 
+    /**
+     * @return array<string, mixed>
+     */
     protected function getParameterMap(): array
     {
         $v = array_merge(
             parent::getParameterMap(),
             [
-                'period' => function ($value) {
+                'period' => function ($value): int {
                     Assertion::greaterThan((int) $value, 0, 'Period must be at least 1.');
 
                     return (int) $value;
                 },
-                'epoch' => function ($value) {
+                'epoch' => function ($value): int {
                     Assertion::greaterOrEqualThan((int) $value, 0, 'Epoch must be greater than or equal to 0.');
 
                     return (int) $value;
@@ -140,6 +143,9 @@ final class TOTP extends OTP implements TOTPInterface
         return $v;
     }
 
+    /**
+     * @param array<string, mixed> $options
+     */
     protected function filterOptions(array &$options): void
     {
         parent::filterOptions($options);
diff --git a/tests/TOTPTest.php b/tests/TOTPTest.php
index 07d4c3d..ce955eb 100644
--- a/tests/TOTPTest.php
+++ b/tests/TOTPTest.php
@@ -218,6 +218,8 @@ final class TOTPTest extends TestCase
     /**
      * @see https://tools.ietf.org/html/rfc6238#appendix-B
      * @see http://www.rfc-editor.org/errata_search.php?rfc=6238
+     *
+     * @return array<int, mixed[]>
      */
     public function dataVectors(): array
     {
-- 
GitLab