From a7d2330df28b9de2038fa3cb7c51f00cc4575bf8 Mon Sep 17 00:00:00 2001 From: Deeka Wong Date: Wed, 20 Dec 2023 12:21:16 +0800 Subject: [PATCH] Support customized local configuration files for PHPStan and PHPUnit (#502) * Support customized local configuration files for PHPStan and PHPUnit * Optimize * Fix return type declarations in Kafka and Log facades * Refactor array and collection mixins * Update type hint for process method in TaskHandleListener * Update CacheInterface and Cache class * Refactor ParameterParser class by removing unused code * Refactor Etcd and Nacos drivers, and fix EnvWriter return statement * Fix type hinting in exception handling functions * Fix column value retrieval in FastPaginate.php * Refactor validation rules in ValidationAspect.php * Update helper functions and fix deprecated functions * Refactor log writer to use null coalescing operator for default values * Fix code formatting and remove unused code * Update variable type in ResponseSequence class and fix factory function in Functions.php * Fix code inconsistencies and improve code readability * Update phpstan.neon.dist to include phpstan-baseline.neon This commit updates the phpstan.neon.dist file to include the phpstan-baseline.neon file. The previous include statement for vendor/phpstan/phpstan-deprecation-rules/rules.neon has been commented out. This change ensures that the phpstan-baseline.neon file is included in the analysis performed by vendor/bin/phpstan. * Update PHPStan configuration file * Fix isInstanceCall method logic * Refactor access log message formatting --------- Co-authored-by: Deeka Wong <8337659+huangdijia@users.noreply.github.com> --- src/Command/SubscribersCommand.php | 6 ------ src/Command/TriggersCommand.php | 6 ------ src/Consumer.php | 6 +++--- src/Monitor/HealthMonitor.php | 4 +++- src/Mutex/RedisServerMutex.php | 6 +++--- src/Mutex/ServerMutexInterface.php | 2 +- src/Subscriber/TriggerSubscriber.php | 2 +- src/TriggerManager.php | 2 +- 8 files changed, 12 insertions(+), 22 deletions(-) diff --git a/src/Command/SubscribersCommand.php b/src/Command/SubscribersCommand.php index 20a09e4..370dccd 100644 --- a/src/Command/SubscribersCommand.php +++ b/src/Command/SubscribersCommand.php @@ -16,7 +16,6 @@ use FriendsOfHyperf\Trigger\Subscriber\TriggerSubscriber; use Hyperf\Command\Command as HyperfCommand; use Hyperf\Di\Annotation\AnnotationCollector; -use Psr\Container\ContainerInterface; use function Hyperf\Collection\collect; @@ -26,11 +25,6 @@ class SubscribersCommand extends HyperfCommand protected string $description = 'List all subscribers.'; - public function __construct(ContainerInterface $container) - { - parent::__construct(); - } - public function handle() { $subscribers = AnnotationCollector::getClassesByAnnotation(Subscriber::class); diff --git a/src/Command/TriggersCommand.php b/src/Command/TriggersCommand.php index 748c32f..69d8ec9 100644 --- a/src/Command/TriggersCommand.php +++ b/src/Command/TriggersCommand.php @@ -14,7 +14,6 @@ use FriendsOfHyperf\Trigger\Annotation\Trigger; use Hyperf\Command\Command as HyperfCommand; use Hyperf\Di\Annotation\AnnotationCollector; -use Psr\Container\ContainerInterface; use function Hyperf\Collection\collect; use function Hyperf\Support\class_basename; @@ -25,11 +24,6 @@ class TriggersCommand extends HyperfCommand protected string $description = 'List all triggers.'; - public function __construct(ContainerInterface $container) - { - parent::__construct(); - } - public function handle() { $triggers = AnnotationCollector::getClassesByAnnotation(Trigger::class); diff --git a/src/Consumer.php b/src/Consumer.php index 9290538..ff9a3cc 100644 --- a/src/Consumer.php +++ b/src/Consumer.php @@ -45,7 +45,7 @@ class Consumer private bool $stopped = false; public function __construct( - protected subscriberManager $subscriberManager, + protected SubscriberManager $subscriberManager, protected TriggerManager $triggerManager, protected string $connection = 'default', protected array $options = [], @@ -186,9 +186,9 @@ protected function makeReplication(): MySQLReplicationFactory fn (ConfigBuilder $builder) => $builder->withUser($config['user'] ?? 'root') ->withHost($config['host'] ?? '127.0.0.1') ->withPassword($config['password'] ?? 'root') - ->withPort((int) $config['port'] ?? 3306) + ->withPort((int) ($config['port'] ?? 3306)) ->withSlaveId(random_int(100, 999)) - ->withHeartbeatPeriod((float) $config['heartbeat_period'] ?? 3) + ->withHeartbeatPeriod((float) ($config['heartbeat_period'] ?? 3)) ->withDatabasesOnly($databasesOnly) ->withTablesOnly($tablesOnly) ); diff --git a/src/Monitor/HealthMonitor.php b/src/Monitor/HealthMonitor.php index c9b2f21..014cde4 100644 --- a/src/Monitor/HealthMonitor.php +++ b/src/Monitor/HealthMonitor.php @@ -50,7 +50,9 @@ public function __construct(protected ContainerInterface $container, protected C if ($container->has(StdoutLoggerInterface::class)) { $this->logger = $container->get(StdoutLoggerInterface::class); } - $this->timer = new Timer($this->logger); + $this->timer = new Timer( + $this->logger instanceof StdoutLoggerInterface ? $this->logger : null + ); } public function process(): void diff --git a/src/Mutex/RedisServerMutex.php b/src/Mutex/RedisServerMutex.php index a9a6ae4..410ddb3 100644 --- a/src/Mutex/RedisServerMutex.php +++ b/src/Mutex/RedisServerMutex.php @@ -43,13 +43,13 @@ public function __construct( array $options = [], protected ?StdoutLoggerInterface $logger = null ) { - $this->expires = (int) $options['expires'] ?? 60; - $this->keepaliveInterval = (int) $options['keepalive_interval'] ?? 10; + $this->expires = (int) ($options['expires'] ?? 60); + $this->keepaliveInterval = (int) ($options['keepalive_interval'] ?? 10); $this->name = $name ?? sprintf('trigger:server:%s', $this->connection); $this->owner = $owner ?? Util::getInternalIp(); $this->connection = $options['connection']; $this->timer = new Timer($logger); - $this->retryInterval = (int) $options['retry_interval'] ?? 10; + $this->retryInterval = (int) ($options['retry_interval'] ?? 10); } public function attempt(callable $callback = null): void diff --git a/src/Mutex/ServerMutexInterface.php b/src/Mutex/ServerMutexInterface.php index 678c293..6afe143 100644 --- a/src/Mutex/ServerMutexInterface.php +++ b/src/Mutex/ServerMutexInterface.php @@ -13,7 +13,7 @@ interface ServerMutexInterface { - public function attempt(); + public function attempt(callable $callback = null); public function release(bool $force = false); } diff --git a/src/Subscriber/TriggerSubscriber.php b/src/Subscriber/TriggerSubscriber.php index 29dbf6c..c62314d 100644 --- a/src/Subscriber/TriggerSubscriber.php +++ b/src/Subscriber/TriggerSubscriber.php @@ -37,7 +37,7 @@ public function __construct( protected ?StdoutLoggerInterface $logger = null ) { $this->concurrent = new Concurrent( - (int) $consumer->getOption('concurrent.limit') ?? 1 + (int) ($consumer->getOption('concurrent.limit') ?? 1) ); } diff --git a/src/TriggerManager.php b/src/TriggerManager.php index 17576c9..1268da7 100644 --- a/src/TriggerManager.php +++ b/src/TriggerManager.php @@ -41,9 +41,9 @@ public function register(): void } foreach ($queue as $value) { + /** @var Trigger $property */ [$class, $property] = $value; - /** @var Trigger $property */ foreach ($property->events as $eventType) { $config = $this->config->get('trigger.connections.' . $property->connection); $property->table ??= class_basename($class);