diff --git a/src/Operation.php b/src/Operation.php index 6bb15a54..9f53d141 100644 --- a/src/Operation.php +++ b/src/Operation.php @@ -22,14 +22,14 @@ abstract class Operation /** * Determines which environment to run on. * - * @deprecated Will be removed in 7.x version. Use `shouldEnvironment` method instead. + * @deprecated Will be removed in 7.x version. Use `shouldRun` method instead. */ protected array|string|null $environment = null; /** * Determines in which environment it should not run. * - * @deprecated Will be removed in 7.x version. Use `shouldEnvironment` method instead. + * @deprecated Will be removed in 7.x version. Use `shouldRun` method instead. */ protected array|string|null $exceptEnvironment = null; @@ -103,7 +103,7 @@ public function transactionAttempts(): int /** * Determines which environment to run on. * - * @deprecated Will be removed in 7.x version. Use `shouldEnvironment` method instead. + * @deprecated Will be removed in 7.x version. Use `shouldRun` method instead. */ public function onEnvironment(): array { @@ -113,20 +113,13 @@ public function onEnvironment(): array /** * Determines in which environment it should not run. * - * @deprecated Will be removed in 7.x version. Use `shouldEnvironment` method instead. + * @deprecated Will be removed in 7.x version. Use `shouldRun` method instead. */ public function exceptEnvironment(): array { return Arr::wrap($this->exceptEnvironment); } - public function shouldBeEnvironment(): bool - { - $env = $this->onEnvironment(); - - return empty($env) || in_array(app()->environment(), $env, true); - } - /** * Determines whether the given operation can be called conditionally. * @@ -142,7 +135,14 @@ public function allow(): bool */ public function shouldRun(): bool { - return $this->allow(); + $env = app()->environment(); + + $on = $this->onEnvironment(); + $except = $this->exceptEnvironment(); + + return $this->allow() + && (empty($on) || in_array($env, $on, true)) + && (empty($except) || ! in_array($env, $except, true)); } /** diff --git a/src/Services/Migrator.php b/src/Services/Migrator.php index d456c188..7914452b 100644 --- a/src/Services/Migrator.php +++ b/src/Services/Migrator.php @@ -18,7 +18,6 @@ use Illuminate\Support\Facades\DB; use Throwable; -use function in_array; use function method_exists; use function realpath; @@ -139,30 +138,13 @@ protected function deleteLog(string $name): void protected function allowOperation(Operation $operation, Options $options): bool { - if (! $this->allowEnvironment($operation)) { + if (! $operation->shouldRun()) { return false; } return ! $this->disallowBefore($operation, $options); } - protected function allowEnvironment(Operation $operation): bool - { - $env = $this->config->environment(); - - return $operation->shouldRun() - && $operation->shouldBeEnvironment() - && $this->exceptEnvironment($env, $operation->exceptEnvironment()); - } - - /** - * @deprecated - */ - protected function exceptEnvironment(?string $env, array $except): bool - { - return empty($except) || ! in_array($env, $except, true); - } - protected function disallowBefore(Operation $operation, Options $options): bool { return $options->before && ! $operation->needBefore();