diff --git a/composer.json b/composer.json index d98978269..bf6181685 100644 --- a/composer.json +++ b/composer.json @@ -232,7 +232,10 @@ "audit": { "ignore": ["PKSA-z3gr-8qht-p93v"] }, - "sort-packages": true + "sort-packages": true, + "allow-plugins": { + "php-http/discovery": true + } }, "extra": { "hyperf": { diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 719dbc862..1554534ff 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -39,6 +39,9 @@ parameters: - '#Method Redis::eval\(\) invoked with [0-9] parameters, 1-3 required.#' - '#Access to an undefined property Hypervel\\Queue\\Jobs\\DatabaseJobRecord::\$.*#' - '#Access to an undefined property Hypervel\\Queue\\Contracts\\Job::\$.*#' + # NodeTrait methods - mixed in at app level, not on base Model class + - message: '#Call to an undefined method Hyperf\\Database\\Model\\Model::new(ScopedQuery|NestedSetQuery)\(\)#' + path: src/nested-set/* - '#Call to an undefined method Hyperf\\Database\\Query\\Builder::where[a-zA-Z0-9\\\\_]+#' - '#Call to an undefined method Hyperf\\Database\\Query\\Builder::firstOrFail\(\)#' - '#Access to an undefined property Hyperf\\Collection\\HigherOrderCollectionProxy#' diff --git a/src/cache/src/Contracts/Lock.php b/src/cache/src/Contracts/Lock.php index 98a2669a3..c81301b6a 100644 --- a/src/cache/src/Contracts/Lock.php +++ b/src/cache/src/Contracts/Lock.php @@ -6,6 +6,11 @@ interface Lock { + /** + * Attempt to acquire the lock. + */ + public function acquire(): bool; + /** * Attempt to acquire the lock. */ @@ -16,6 +21,11 @@ public function get(?callable $callback = null): mixed; */ public function block(int $seconds, ?callable $callback = null): mixed; + /** + * Specify the number of milliseconds to sleep in between blocked lock acquisition attempts. + */ + public function betweenBlockedAttemptsSleepFor(int $milliseconds): static; + /** * Release the lock. */ diff --git a/src/console/src/Scheduling/CacheEventMutex.php b/src/console/src/Scheduling/CacheEventMutex.php index 8dda537ee..15aab12c2 100644 --- a/src/console/src/Scheduling/CacheEventMutex.php +++ b/src/console/src/Scheduling/CacheEventMutex.php @@ -32,9 +32,11 @@ public function __construct( */ public function create(Event $event): bool { - if ($this->shouldUseLocks($this->cache->store($this->store)->getStore())) { - /* @phpstan-ignore-next-line */ - return $this->cache->store($this->store)->getStore() + $store = $this->cache->store($this->store)->getStore(); + + if ($this->shouldUseLocks($store)) { + /** @var LockProvider&Store $store */ // @phpstan-ignore varTag.nativeType + return $store ->lock($event->mutexName(), $event->expiresAt * 60) ->acquire(); } @@ -51,9 +53,11 @@ public function create(Event $event): bool */ public function exists(Event $event): bool { - if ($this->shouldUseLocks($this->cache->store($this->store)->getStore())) { - /* @phpstan-ignore-next-line */ - return ! $this->cache->store($this->store)->getStore() + $store = $this->cache->store($this->store)->getStore(); + + if ($this->shouldUseLocks($store)) { + /** @var LockProvider&Store $store */ // @phpstan-ignore varTag.nativeType + return ! $store ->lock($event->mutexName(), $event->expiresAt * 60) ->get(fn () => true); } @@ -66,9 +70,11 @@ public function exists(Event $event): bool */ public function forget(Event $event): void { - if ($this->shouldUseLocks($this->cache->store($this->store)->getStore())) { - /* @phpstan-ignore-next-line */ - $this->cache->store($this->store)->getStore() + $store = $this->cache->store($this->store)->getStore(); + + if ($this->shouldUseLocks($store)) { + /** @var LockProvider&Store $store */ // @phpstan-ignore varTag.nativeType + $store ->lock($event->mutexName(), $event->expiresAt * 60) ->forceRelease(); diff --git a/src/filesystem/src/FilesystemManager.php b/src/filesystem/src/FilesystemManager.php index 011773682..4bfc1e7da 100644 --- a/src/filesystem/src/FilesystemManager.php +++ b/src/filesystem/src/FilesystemManager.php @@ -79,7 +79,7 @@ public function drive(?string $name = null): Filesystem /** * Get a filesystem instance. */ - public function disk(?string $name = null): FileSystem + public function disk(?string $name = null): Filesystem { $name = $name ?: $this->getDefaultDriver(); @@ -100,7 +100,7 @@ public function cloud(): Cloud /** * Build an on-demand disk. */ - public function build(array|string $config): FileSystem + public function build(array|string $config): Filesystem { return $this->resolve('ondemand', is_array($config) ? $config : [ 'driver' => 'local', @@ -111,7 +111,7 @@ public function build(array|string $config): FileSystem /** * Attempt to get the disk from the local cache. */ - protected function get(string $name): FileSystem + protected function get(string $name): Filesystem { return $this->disks[$name] ?? $this->resolve($name); } @@ -121,7 +121,7 @@ protected function get(string $name): FileSystem * * @throws InvalidArgumentException */ - protected function resolve(string $name, ?array $config = null): FileSystem + protected function resolve(string $name, ?array $config = null): Filesystem { $config ??= $this->getConfig($name); @@ -163,7 +163,7 @@ protected function resolve(string $name, ?array $config = null): FileSystem /** * Call a custom driver creator. */ - protected function callCustomCreator(array $config): FileSystem + protected function callCustomCreator(array $config): Filesystem { return $this->customCreators[$config['driver']]($this->app, $config); } @@ -171,7 +171,7 @@ protected function callCustomCreator(array $config): FileSystem /** * Create an instance of the local driver. */ - public function createLocalDriver(array $config, string $name = 'local'): FileSystem + public function createLocalDriver(array $config, string $name = 'local'): Filesystem { $visibility = PortableVisibilityConverter::fromArray( $config['permissions'] ?? [], @@ -204,7 +204,7 @@ public function createLocalDriver(array $config, string $name = 'local'): FileSy /** * Create an instance of the ftp driver. */ - public function createFtpDriver(array $config): FileSystem + public function createFtpDriver(array $config): Filesystem { if (! isset($config['root'])) { $config['root'] = ''; @@ -219,7 +219,7 @@ public function createFtpDriver(array $config): FileSystem /** * Create an instance of the sftp driver. */ - public function createSftpDriver(array $config): FileSystem + public function createSftpDriver(array $config): Filesystem { /* @phpstan-ignore-next-line */ $provider = SftpConnectionProvider::fromArray($config); @@ -353,7 +353,7 @@ protected function createGcsClient(array $config): GcsClient /** * Create a scoped driver. */ - public function createScopedDriver(array $config): FileSystem + public function createScopedDriver(array $config): Filesystem { if (empty($config['disk'])) { throw new InvalidArgumentException('Scoped disk is missing "disk" configuration option.'); diff --git a/src/prompts/src/Concerns/Fallback.php b/src/prompts/src/Concerns/Fallback.php index 8c0d68bca..3e2a2c2f3 100644 --- a/src/prompts/src/Concerns/Fallback.php +++ b/src/prompts/src/Concerns/Fallback.php @@ -17,7 +17,7 @@ trait Fallback /** * The fallback implementations. * - * @var array + * @var array */ protected static array $fallbacks = []; diff --git a/src/queue/src/QueueManager.php b/src/queue/src/QueueManager.php index 780bc7358..34936b787 100644 --- a/src/queue/src/QueueManager.php +++ b/src/queue/src/QueueManager.php @@ -161,11 +161,10 @@ protected function resolve(string $name): Queue throw new InvalidArgumentException("The [{$name}] queue connection has not been configured."); } - /** @phpstan-ignore-next-line */ $resolver = fn () => $this->getConnector($config['driver']) ->connect($config) ->setConnectionName($name) - ->setContainer($this->app) + ->setContainer($this->app) // @phpstan-ignore method.notFound ->setConfig($config); if (in_array($config['driver'], $this->poolables)) { diff --git a/src/queue/src/QueueManagerFactory.php b/src/queue/src/QueueManagerFactory.php index ec954db5e..691849345 100644 --- a/src/queue/src/QueueManagerFactory.php +++ b/src/queue/src/QueueManagerFactory.php @@ -22,8 +22,8 @@ public function __invoke(ContainerInterface $container): QueueManager $reportHandler = fn (Throwable $e) => $container->get(ExceptionHandler::class)->report($e); foreach ($connectors as $connector) { try { - $manager->connection($connector) // @phpstan-ignore-line - ->setExceptionCallback($reportHandler); + $manager->connection($connector) + ->setExceptionCallback($reportHandler); // @phpstan-ignore method.notFound } catch (InvalidArgumentException) { // Ignore exception when the connector is not configured. } diff --git a/src/session/src/Middleware/StartSession.php b/src/session/src/Middleware/StartSession.php index 60d299566..049ba9c75 100644 --- a/src/session/src/Middleware/StartSession.php +++ b/src/session/src/Middleware/StartSession.php @@ -11,6 +11,7 @@ use Hyperf\HttpServer\Request; use Hyperf\HttpServer\Router\Dispatched; use Hypervel\Cache\Contracts\Factory as CacheFactoryContract; +use Hypervel\Cache\Contracts\LockProvider; use Hypervel\Cookie\Cookie; use Hypervel\Foundation\Exceptions\Contracts\ExceptionHandler as ExceptionHandlerContract; use Hypervel\Session\Contracts\Session; @@ -82,8 +83,9 @@ protected function handleRequestWhileBlocking(ServerRequestInterface $request, S $waitFor = ($blockingOptions['wait'] ?? $this->manager->defaultRouteBlockWaitSeconds()); - /* @phpstan-ignore-next-line */ - $lock = $this->cache->store($this->manager->blockDriver()) + /** @var \Hypervel\Cache\Contracts\Repository&LockProvider $store */ // @phpstan-ignore varTag.nativeType + $store = $this->cache->store($this->manager->blockDriver()); + $lock = $store ->lock('session:' . $session->getId(), (int) $lockFor) ->betweenBlockedAttemptsSleepFor(50); @@ -92,7 +94,7 @@ protected function handleRequestWhileBlocking(ServerRequestInterface $request, S return $this->handleStatefulRequest($request, $session, $handler); } finally { - $lock?->release(); + $lock->release(); } } diff --git a/src/telescope/src/Storage/DatabaseEntriesRepository.php b/src/telescope/src/Storage/DatabaseEntriesRepository.php index f83ac1261..93c395203 100644 --- a/src/telescope/src/Storage/DatabaseEntriesRepository.php +++ b/src/telescope/src/Storage/DatabaseEntriesRepository.php @@ -72,9 +72,8 @@ public function find(mixed $id): EntryResult */ public function get(?string $type, EntryQueryOptions $options): Collection { - /* @phpstan-ignore-next-line */ return EntryModel::on($this->connection) - ->withTelescopeOptions($type, $options) + ->withTelescopeOptions($type, $options) // @phpstan-ignore method.notFound ->take($options->limit) ->orderByDesc('sequence') ->get()->reject(function ($entry) {