Skip to content

Removed shouldBeEnvironment method #189

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions src/Operation.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
{
Expand All @@ -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.
*
Expand All @@ -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));
}

/**
Expand Down
20 changes: 1 addition & 19 deletions src/Services/Migrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
use Illuminate\Support\Facades\DB;
use Throwable;

use function in_array;
use function method_exists;
use function realpath;

Expand Down Expand Up @@ -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();
Expand Down