From eb08f918940d6023bedc347eb570e6ce920942c4 Mon Sep 17 00:00:00 2001 From: cexll Date: Mon, 3 Oct 2022 16:02:10 +0800 Subject: [PATCH] optimize code --- src/Aspect/MySqlGrammarAspect.php | 3 +-- src/Aspect/ServiceCacheAspect.php | 4 ++-- src/Aspect/ServiceCacheEvictAspect.php | 4 ++-- src/Command/stubs/Request.stub | 1 - src/Lock/RedisLock.php | 5 +++-- src/Middleware/CorsMiddleware.php | 2 +- src/Middleware/JwtAuthMiddleware.php | 2 +- src/Middleware/ResponseMiddleware.php | 2 +- src/Request/ValidateSceneTrait.php | 2 +- 9 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/Aspect/MySqlGrammarAspect.php b/src/Aspect/MySqlGrammarAspect.php index 643f4d7..d125e4e 100644 --- a/src/Aspect/MySqlGrammarAspect.php +++ b/src/Aspect/MySqlGrammarAspect.php @@ -18,8 +18,7 @@ class MySqlGrammarAspect extends AbstractAspect 'Hyperf\Database\Schema\Grammars\MySqlGrammar::compileColumnListing', ]; - public $annotations = [ - ]; + public $annotations = []; /** * Compatible with mysql8. diff --git a/src/Aspect/ServiceCacheAspect.php b/src/Aspect/ServiceCacheAspect.php index 3e9564e..2a17acc 100644 --- a/src/Aspect/ServiceCacheAspect.php +++ b/src/Aspect/ServiceCacheAspect.php @@ -29,12 +29,12 @@ class ServiceCacheAspect extends AbstractAspect /** * @var CacheManager */ - protected $manager; + protected CacheManager $manager; /** * @var AnnotationManager */ - protected $annotationManager; + protected AnnotationManager $annotationManager; public function __construct(CacheManager $manager, AnnotationManager $annotationManager) { diff --git a/src/Aspect/ServiceCacheEvictAspect.php b/src/Aspect/ServiceCacheEvictAspect.php index 91e072e..9f66492 100644 --- a/src/Aspect/ServiceCacheEvictAspect.php +++ b/src/Aspect/ServiceCacheEvictAspect.php @@ -27,12 +27,12 @@ class ServiceCacheEvictAspect extends AbstractAspect /** * @var CacheManager */ - protected $manager; + protected CacheManager $manager; /** * @var AnnotationManager */ - protected $annotationManager; + protected AnnotationManager $annotationManager; public function __construct(CacheManager $manager, AnnotationManager $annotationManager) { diff --git a/src/Command/stubs/Request.stub b/src/Command/stubs/Request.stub index 2adcfed..9c7d0bd 100644 --- a/src/Command/stubs/Request.stub +++ b/src/Command/stubs/Request.stub @@ -11,7 +11,6 @@ class #REQUEST# extends AbstractRequest public function rules(): array { return [ - ]; } } diff --git a/src/Lock/RedisLock.php b/src/Lock/RedisLock.php index 894ff39..32ca23a 100644 --- a/src/Lock/RedisLock.php +++ b/src/Lock/RedisLock.php @@ -38,7 +38,8 @@ public function lock(string $name, int $expire = 5, int $retryTimes = 5, int $us $key = self::REDIS_LOCK_KEY_PREFIX . $name; while ($retryTimes-- > 0) { $kVal = microtime(true) + $expire + Coroutine::id(); - $lock = (bool) $this->getLock($key, $expire, $kVal); // 上锁 + // 上锁 + $lock = (bool) $this->getLock($key, $expire, $kVal); if ($lock) { $this->lockedNames[$key] = $kVal; break; @@ -74,7 +75,7 @@ public function unlock(string $name): bool /** * 获取锁 并执行. */ - public function run(callable $func, string $name, int $expire = 5, int $retryTimes = 10, int $sleep = 100000) + public function run(callable $func, string $name, int $expire = 5, int $retryTimes = 10, int $sleep = 100000): bool { if ($this->lock($name, $expire, $retryTimes, $sleep)) { try { diff --git a/src/Middleware/CorsMiddleware.php b/src/Middleware/CorsMiddleware.php index 558b451..278083a 100644 --- a/src/Middleware/CorsMiddleware.php +++ b/src/Middleware/CorsMiddleware.php @@ -4,7 +4,7 @@ namespace YogCloud\Framework\Middleware; -use Hyperf\Utils\Context; +use Hyperf\Context\Context; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Server\MiddlewareInterface; diff --git a/src/Middleware/JwtAuthMiddleware.php b/src/Middleware/JwtAuthMiddleware.php index 14e15df..0cf542f 100644 --- a/src/Middleware/JwtAuthMiddleware.php +++ b/src/Middleware/JwtAuthMiddleware.php @@ -21,7 +21,7 @@ class JwtAuthMiddleware extends AuthMiddleware * Routing Whitelist. * @var string */ - protected $authWhiteRoutes; + protected string $authWhiteRoutes; protected $guards = ['jwt']; diff --git a/src/Middleware/ResponseMiddleware.php b/src/Middleware/ResponseMiddleware.php index 935abc7..a9eacbf 100644 --- a/src/Middleware/ResponseMiddleware.php +++ b/src/Middleware/ResponseMiddleware.php @@ -25,7 +25,7 @@ class ResponseMiddleware implements MiddlewareInterface * Routing Whitelist. * @var string */ - protected $responseRawRoutes; + protected string $responseRawRoutes; protected ContainerInterface $container; diff --git a/src/Request/ValidateSceneTrait.php b/src/Request/ValidateSceneTrait.php index affa4fb..101b207 100644 --- a/src/Request/ValidateSceneTrait.php +++ b/src/Request/ValidateSceneTrait.php @@ -23,7 +23,7 @@ trait ValidateSceneTrait * scene. * @var string */ - protected $validateScene; + protected string $validateScene; /** * Filter rule scenario.