1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2025-12-12 12:54:05 +00:00

phpstan fixes

This commit is contained in:
Samuel Štancl 2024-09-27 23:16:39 +02:00
parent 39bcbda5d0
commit b01c16f4fc
3 changed files with 20 additions and 5 deletions

View file

@ -16,6 +16,7 @@ parameters:
ignoreErrors:
-
identifier: missingType.iterableValue
- '#FFI#'
- '#Return type(.*?) of method Stancl\\Tenancy\\Database\\Models\\Tenant\:\:newCollection\(\) should be compatible with return type#'
- '#Method Stancl\\Tenancy\\Database\\Models\\Tenant\:\:newCollection\(\) should return#'
- '#Cannot access offset (.*?) on Illuminate\\Contracts\\Foundation\\Application#'

View file

@ -80,8 +80,12 @@ trait ParallelCommand
// We use the logical core count as it should work best for I/O bound code
return match (PHP_OS_FAMILY) {
'Windows' => (int) getenv('NUMBER_OF_PROCESSORS'),
'Linux' => substr_count(file_get_contents('/proc/cpuinfo'), 'processor'),
'Linux' => substr_count(
file_get_contents('/proc/cpuinfo') ?: throw new Exception('Could not open /proc/cpuinfo for core count detection, please specify -p manually.'),
'processor',
),
'Darwin', 'BSD' => $this->sysctlGetLogicalCoreCount(PHP_OS_FAMILY === 'Darwin'),
default => throw new Exception('Core count detection not implemented for ' . PHP_OS_FAMILY . ', please specify -p manually.'),
};
}
@ -111,8 +115,8 @@ trait ParallelCommand
}
if ($processes > 1 && ! function_exists('pcntl_fork')) {
exit(1);
$this->components->error('The pcntl extension is required for parallel migrations to work.');
exit(1);
}
return $processes;
@ -143,7 +147,7 @@ trait ParallelCommand
$success = true;
$pids = [];
if (count($args) < $processes) {
if ($args !== null && count($args) < $processes) {
$processes = count($args);
}

View file

@ -4,8 +4,10 @@ declare(strict_types=1);
namespace Stancl\Tenancy\Overrides;
use BackedEnum;
use Illuminate\Routing\UrlGenerator;
use Illuminate\Support\Arr;
use InvalidArgumentException;
use Stancl\Tenancy\Resolvers\PathTenantResolver;
/**
@ -51,7 +53,11 @@ class TenancyUrlGenerator extends UrlGenerator
*/
public function route($name, $parameters = [], $absolute = true)
{
[$name, $parameters] = $this->prepareRouteInputs($name, Arr::wrap($parameters));
if ($name instanceof BackedEnum && ! is_string($name = $name->value)) { // @phpstan-ignore function.impossibleType
throw new InvalidArgumentException('Attribute [name] expects a string backed enum.');
}
[$name, $parameters] = $this->prepareRouteInputs($name, Arr::wrap($parameters)); // @phpstan-ignore argument.type
return parent::route($name, $parameters, $absolute);
}
@ -62,7 +68,11 @@ class TenancyUrlGenerator extends UrlGenerator
*/
public function temporarySignedRoute($name, $expiration, $parameters = [], $absolute = true)
{
[$name, $parameters] = $this->prepareRouteInputs($name, Arr::wrap($parameters));
if ($name instanceof BackedEnum && ! is_string($name = $name->value)) { // @phpstan-ignore function.impossibleType
throw new InvalidArgumentException('Attribute [name] expects a string backed enum.');
}
[$name, $parameters] = $this->prepareRouteInputs($name, Arr::wrap($parameters)); // @phpstan-ignore argument.type
return parent::temporarySignedRoute($name, $expiration, $parameters, $absolute);
}