diff --git a/phpstan.neon b/phpstan.neon index fafcc146..c4c667b1 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -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#' diff --git a/src/Concerns/ParallelCommand.php b/src/Concerns/ParallelCommand.php index 1da3e7d9..84bc0658 100644 --- a/src/Concerns/ParallelCommand.php +++ b/src/Concerns/ParallelCommand.php @@ -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); } diff --git a/src/Overrides/TenancyUrlGenerator.php b/src/Overrides/TenancyUrlGenerator.php index af307021..7c0a7879 100644 --- a/src/Overrides/TenancyUrlGenerator.php +++ b/src/Overrides/TenancyUrlGenerator.php @@ -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); }