瀏覽代碼

refactor(migration): 统一数据库迁移基类为 Phinx\Migration\AbstractMigration,
统一代码风格

runphp 2 周之前
父節點
當前提交
7f3cde8f02

+ 2 - 1
command.php

@@ -1,8 +1,9 @@
 <?php
+
 declare(strict_types=1);
 
 use SixShop\Auth\Command\JWTGenerateSecretCommand;
 
 return [
     'jwt:secret' => JWTGenerateSecretCommand::class,
-];
+];

+ 2 - 1
config.php

@@ -1,4 +1,5 @@
 <?php
+
 declare(strict_types=1);
 
 return [
@@ -67,4 +68,4 @@ return [
         '_fc_drag_tag' => 'switch',
         'value' => true
     ]
-];
+];

+ 2 - 2
database/migrations/20250710063222_extension_auth_permission.php

@@ -1,8 +1,8 @@
 <?php
 
-use think\migration\Migrator;
+use Phinx\Migration\AbstractMigration;
 
-class ExtensionAuthPermission extends Migrator
+class ExtensionAuthPermission extends AbstractMigration
 {
     /**
      * Change Method.

+ 1 - 0
info.php

@@ -1,4 +1,5 @@
 <?php
+
 declare(strict_types=1);
 
 return [

+ 4 - 3
src/Auth.php

@@ -1,4 +1,5 @@
 <?php
+
 declare(strict_types=1);
 
 namespace SixShop\Auth;
@@ -13,9 +14,9 @@ use think\facade\Event;
 
 class Auth implements AuthInterface
 {
-    const string ALGORITHM = 'HS256';
+    public const string ALGORITHM = 'HS256';
 
-    const int SLEEP_WAY = 60;
+    public const int SLEEP_WAY = 60;
 
     private array $config;
 
@@ -81,4 +82,4 @@ class Auth implements AuthInterface
     {
         return $this->userType;
     }
-}
+}

+ 6 - 3
src/Command/JWTGenerateSecretCommand.php

@@ -1,4 +1,5 @@
 <?php
+
 declare(strict_types=1);
 
 namespace SixShop\Auth\Command;
@@ -38,7 +39,8 @@ class JWTGenerateSecretCommand extends Command
             // update existing entry
             file_put_contents($path, str_replace(
                 'JWT_SECRET=' . $this->app->config->get('jwt.secret'),
-                'JWT_SECRET=' . $key, file_get_contents($path)
+                'JWT_SECRET=' . $key,
+                file_get_contents($path)
             ));
         }
 
@@ -63,8 +65,9 @@ class JWTGenerateSecretCommand extends Command
 
     protected function isConfirmed()
     {
-        return $this->output->confirm($this->input,
+        return $this->output->confirm(
+            $this->input,
             'This will invalidate all existing tokens. Are you sure you want to override the secret key?'
         );
     }
-}
+}

+ 2 - 1
src/Config.php

@@ -1,4 +1,5 @@
 <?php
+
 declare(strict_types=1);
 
 namespace SixShop\Auth;
@@ -17,4 +18,4 @@ class Config
     {
         return Extension::EXTENSION_ID;
     }
-}
+}

+ 2 - 1
src/Contracts/AuthInterface.php

@@ -1,4 +1,5 @@
 <?php
+
 declare(strict_types=1);
 
 namespace SixShop\Auth\Contracts;
@@ -31,4 +32,4 @@ interface AuthInterface
      * 获取用户类型
      */
     public function getUserType(): UserTypeEnum;
-}
+}

+ 4 - 2
src/Entity/ExtensionAuthPermissionEntity.php

@@ -1,4 +1,5 @@
 <?php
+
 declare(strict_types=1);
 
 namespace SixShop\Auth\Entity;
@@ -9,13 +10,14 @@ use SixShop\Core\Entity\BaseEntity;
 use think\facade\Cache;
 use think\route\Resource;
 use think\route\Rule;
+
 use function Opis\Closure\init;
+
 /**
  * @mixin ExtensionAuthPermissionModel
  */
 class ExtensionAuthPermissionEntity extends BaseEntity
 {
-
     public function syncPermission(Rule $rule): void
     {
         $route = $rule->getRoute();
@@ -60,4 +62,4 @@ class ExtensionAuthPermissionEntity extends BaseEntity
             return $permission->toArray();
         }, 600);
     }
-}
+}

+ 1 - 1
src/Enum/UserTypeEnum.php

@@ -1,4 +1,5 @@
 <?php
+
 declare(strict_types=1);
 
 namespace SixShop\Auth\Enum;
@@ -18,4 +19,3 @@ enum UserTypeEnum: string
      */
     case ADMIN = 'admin';
 }
-

+ 3 - 3
src/Extension.php

@@ -1,16 +1,16 @@
 <?php
+
 declare(strict_types=1);
 
 namespace SixShop\Auth;
 
-
 use SixShop\Auth\Hook\AuthHook;
 use SixShop\Core\ExtensionAbstract;
 use SixShop\Auth\Hook\AppStatusHook;
 
 class Extension extends ExtensionAbstract
 {
-    const EXTENSION_ID = 'auth';
+    public const EXTENSION_ID = 'auth';
 
     public function getHooks(): array
     {
@@ -24,4 +24,4 @@ class Extension extends ExtensionAbstract
     {
         return dirname(__DIR__);
     }
-}
+}

+ 3 - 5
src/Hook/AppStatusHook.php

@@ -1,4 +1,5 @@
 <?php
+
 declare(strict_types=1);
 
 namespace SixShop\Auth\Hook;
@@ -10,12 +11,10 @@ use Symfony\Component\HttpClient\Exception\ClientException;
 use Symfony\Component\HttpClient\HttpClient;
 use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
 use Symfony\Contracts\HttpClient\HttpClientInterface;
-use think\Env;
 use think\facade\Log;
 
 class AppStatusHook
 {
-
     private const string BASE_URL = 'https://apix.jd29.com';
 
     private const string PACKAGIST_DOMAIN = 'packagist.jd29.com';
@@ -23,8 +22,7 @@ class AppStatusHook
     private HttpClientInterface $httpClient;
     public function __construct(
         private readonly Config $config,
-    )
-    {
+    ) {
         try {
             $authConfigSource = Factory::createConfig()->getAuthConfigSource();
             $authFile = $authConfigSource->getName();
@@ -57,4 +55,4 @@ class AppStatusHook
             Log::error(json_encode($e->getResponse()->toArray(false)));
         }
     }
-}
+}

+ 3 - 3
src/Hook/AuthHook.php

@@ -1,4 +1,5 @@
 <?php
+
 declare(strict_types=1);
 
 namespace SixShop\Auth\Hook;
@@ -9,8 +10,7 @@ use think\Cache;
 
 class AuthHook
 {
-
-    const string TOKEN_REVOKE = 'token_revoke:';
+    public const string TOKEN_REVOKE = 'token_revoke:';
 
     public function __construct(private Cache $cache)
     {
@@ -33,4 +33,4 @@ class AuthHook
     {
         $this->cache->remember(self::TOKEN_REVOKE . $payload->jti, time(), $payload->exp - time() + Auth::SLEEP_WAY);
     }
-}
+}

+ 3 - 2
src/Middleware/AuthMiddleware.php

@@ -1,4 +1,5 @@
 <?php
+
 declare(strict_types=1);
 
 namespace SixShop\Auth\Middleware;
@@ -26,10 +27,10 @@ readonly class AuthMiddleware
                     return abort(401, $e->getMessage());
                 }
             }
-        } else if ($isLogin) {
+        } elseif ($isLogin) {
             return abort(401, 'Authorization header is required');
         }
 
         return $next($request);
     }
-}
+}

+ 2 - 1
src/Middleware/PermissionMiddleware.php

@@ -1,4 +1,5 @@
 <?php
+
 declare(strict_types=1);
 
 namespace SixShop\Auth\Middleware;
@@ -23,4 +24,4 @@ class PermissionMiddleware
         }
         return $next($request);
     }
-}
+}

+ 3 - 1
src/Model/ExtensionAuthPermissionModel.php

@@ -1,5 +1,7 @@
 <?php
+
 declare(strict_types=1);
+
 namespace SixShop\Auth\Model;
 
 use think\Model;
@@ -20,4 +22,4 @@ class ExtensionAuthPermissionModel extends Model
 {
     protected $name = 'extension_auth_permission';
     protected $pk = 'id';
-}
+}

+ 2 - 1
src/helper.php

@@ -1,4 +1,5 @@
 <?php
+
 declare(strict_types=1);
 
 
@@ -44,4 +45,4 @@ if (!function_exists('decrypt_data')) {
         // 解密数据
         return openssl_decrypt($ciphertext, 'aes-256-cbc', $key, OPENSSL_RAW_DATA, $iv);
     }
-}
+}

+ 4 - 2
test/Hook/AppStatusHookTest.php

@@ -1,5 +1,7 @@
 <?php
+
 declare(strict_types=1);
+
 namespace SixShop\Auth\Hook;
 
 use PHPUnit\Framework\TestCase;
@@ -14,6 +16,6 @@ class AppStatusHookTest extends TestCase
 
     public function testPostAppStatus(): void
     {
-        $this->appStatusHook->postAppStatus(['test'=>'test']);
+        $this->appStatusHook->postAppStatus(['test' => 'test']);
     }
-}
+}