From 0ff609bb3d5542f3f41798ec3076de9ffa17e5cc Mon Sep 17 00:00:00 2001
From: Filippo Tessarotto <zoeslam@gmail.com>
Date: Thu, 13 Oct 2022 15:16:32 +0200
Subject: [PATCH] Deprecate ::create error-prone API

---
 src/Factory.php       | 4 ++--
 src/HOTPInterface.php | 2 ++
 src/TOTPInterface.php | 2 ++
 src/Url.php           | 6 ++++++
 4 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/src/Factory.php b/src/Factory.php
index dc98c76..d5c60cc 100644
--- a/src/Factory.php
+++ b/src/Factory.php
@@ -62,12 +62,12 @@ final class Factory implements FactoryInterface
     {
         switch ($parsed_url->getHost()) {
             case 'totp':
-                $totp = TOTP::create($parsed_url->getSecret());
+                $totp = TOTP::createFromSecret($parsed_url->getSecret());
                 $totp->setLabel(self::getLabel($parsed_url->getPath()));
 
                 return $totp;
             case 'hotp':
-                $hotp = HOTP::create($parsed_url->getSecret());
+                $hotp = HOTP::createFromSecret($parsed_url->getSecret());
                 $hotp->setLabel(self::getLabel($parsed_url->getPath()));
 
                 return $hotp;
diff --git a/src/HOTPInterface.php b/src/HOTPInterface.php
index 011f86a..aa1f004 100644
--- a/src/HOTPInterface.php
+++ b/src/HOTPInterface.php
@@ -15,6 +15,8 @@ interface HOTPInterface extends OTPInterface
      * Create a new HOTP object.
      *
      * If the secret is null, a random 64 bytes secret will be generated.
+     *
+     * @deprecated Deprecated since v11.1, use ::createFromSecret or ::generate instead
      */
     public static function create(
         null|string $secret = null,
diff --git a/src/TOTPInterface.php b/src/TOTPInterface.php
index 550e9ff..d0f05d3 100644
--- a/src/TOTPInterface.php
+++ b/src/TOTPInterface.php
@@ -10,6 +10,8 @@ interface TOTPInterface extends OTPInterface
      * Create a new TOTP object.
      *
      * If the secret is null, a random 64 bytes secret will be generated.
+     *
+     * @deprecated Deprecated since v11.1, use ::createFromSecret or ::generate instead
      */
     public static function create(
         null|string $secret = null,
diff --git a/src/Url.php b/src/Url.php
index f3dce71..387d54f 100644
--- a/src/Url.php
+++ b/src/Url.php
@@ -13,6 +13,9 @@ use function is_string;
  */
 final class Url
 {
+    /**
+     * @param non-empty-string $secret
+     */
     public function __construct(
         private readonly string $scheme,
         private readonly string $host,
@@ -38,6 +41,9 @@ final class Url
         return $this->path;
     }
 
+    /**
+     * @return non-empty-string
+     */
     public function getSecret(): string
     {
         return $this->secret;
-- 
GitLab