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);