mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-14 01:44:03 +00:00
fix phpstan errors
This commit is contained in:
parent
18a16e6a74
commit
4372e1bef2
20 changed files with 105 additions and 16 deletions
|
|
@ -22,11 +22,17 @@ trait HasTenantOptions
|
|||
], parent::getOptions());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return LazyCollection<int, \Stancl\Tenancy\Contracts\Tenant&\Illuminate\Database\Eloquent\Model>
|
||||
*/
|
||||
protected function getTenants(?array $tenantKeys = null): LazyCollection
|
||||
{
|
||||
return $this->getTenantsQuery($tenantKeys)->cursor();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Builder<\Stancl\Tenancy\Contracts\Tenant&\Illuminate\Database\Eloquent\Model>
|
||||
*/
|
||||
protected function getTenantsQuery(?array $tenantKeys = null): Builder
|
||||
{
|
||||
return tenancy()->query()
|
||||
|
|
|
|||
|
|
@ -13,14 +13,14 @@ trait ParallelCommand
|
|||
{
|
||||
public const MAX_PROCESSES = 24;
|
||||
|
||||
abstract protected function childHandle(...$args): bool;
|
||||
abstract protected function childHandle(mixed ...$args): bool;
|
||||
|
||||
public function addProcessesOption(): void
|
||||
{
|
||||
$this->addOption('processes', 'p', InputOption::VALUE_OPTIONAL, 'How many processes to spawn. Maximum value: ' . static::MAX_PROCESSES . ', recommended value: core count', 1);
|
||||
}
|
||||
|
||||
protected function forkProcess(...$args): int
|
||||
protected function forkProcess(mixed ...$args): int
|
||||
{
|
||||
$pid = pcntl_fork();
|
||||
|
||||
|
|
@ -53,14 +53,25 @@ trait ParallelCommand
|
|||
return $processes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection<int, Collection<int, \Stancl\Tenancy\Contracts\Tenant&\Illuminate\Database\Eloquent\Model>>>
|
||||
*/
|
||||
protected function getTenantChunks(): Collection
|
||||
{
|
||||
$idCol = tenancy()->model()->getTenantKeyName();
|
||||
$tenants = tenancy()->model()->orderBy($idCol, 'asc')->pluck($idCol);
|
||||
|
||||
return $tenants->chunk(ceil($tenants->count() / $this->getProcesses()));
|
||||
return $tenants->chunk((int) ceil($tenants->count() / $this->getProcesses()))->map(function ($chunk) {
|
||||
$chunk = array_values($chunk->all());
|
||||
|
||||
/** @var Collection<int, \Stancl\Tenancy\Contracts\Tenant&\Illuminate\Database\Eloquent\Model> $chunk */
|
||||
return $chunk;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array|ArrayAccess<int, mixed>|null $args
|
||||
*/
|
||||
protected function runConcurrently(array|ArrayAccess|null $args = null): int
|
||||
{
|
||||
$processes = $this->getProcesses();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue