Skip to content

Commit 9de6ca4

Browse files
Merge pull request #189 from TheDragonCode/6.x
Removed `shouldBeEnvironment` method
2 parents 5073eff + 115c3db commit 9de6ca4

File tree

2 files changed

+13
-31
lines changed

2 files changed

+13
-31
lines changed

src/Operation.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ abstract class Operation
2222
/**
2323
* Determines which environment to run on.
2424
*
25-
* @deprecated Will be removed in 7.x version. Use `shouldEnvironment` method instead.
25+
* @deprecated Will be removed in 7.x version. Use `shouldRun` method instead.
2626
*/
2727
protected array|string|null $environment = null;
2828

2929
/**
3030
* Determines in which environment it should not run.
3131
*
32-
* @deprecated Will be removed in 7.x version. Use `shouldEnvironment` method instead.
32+
* @deprecated Will be removed in 7.x version. Use `shouldRun` method instead.
3333
*/
3434
protected array|string|null $exceptEnvironment = null;
3535

@@ -103,7 +103,7 @@ public function transactionAttempts(): int
103103
/**
104104
* Determines which environment to run on.
105105
*
106-
* @deprecated Will be removed in 7.x version. Use `shouldEnvironment` method instead.
106+
* @deprecated Will be removed in 7.x version. Use `shouldRun` method instead.
107107
*/
108108
public function onEnvironment(): array
109109
{
@@ -113,20 +113,13 @@ public function onEnvironment(): array
113113
/**
114114
* Determines in which environment it should not run.
115115
*
116-
* @deprecated Will be removed in 7.x version. Use `shouldEnvironment` method instead.
116+
* @deprecated Will be removed in 7.x version. Use `shouldRun` method instead.
117117
*/
118118
public function exceptEnvironment(): array
119119
{
120120
return Arr::wrap($this->exceptEnvironment);
121121
}
122122

123-
public function shouldBeEnvironment(): bool
124-
{
125-
$env = $this->onEnvironment();
126-
127-
return empty($env) || in_array(app()->environment(), $env, true);
128-
}
129-
130123
/**
131124
* Determines whether the given operation can be called conditionally.
132125
*
@@ -142,7 +135,14 @@ public function allow(): bool
142135
*/
143136
public function shouldRun(): bool
144137
{
145-
return $this->allow();
138+
$env = app()->environment();
139+
140+
$on = $this->onEnvironment();
141+
$except = $this->exceptEnvironment();
142+
143+
return $this->allow()
144+
&& (empty($on) || in_array($env, $on, true))
145+
&& (empty($except) || ! in_array($env, $except, true));
146146
}
147147

148148
/**

src/Services/Migrator.php

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
use Illuminate\Support\Facades\DB;
1919
use Throwable;
2020

21-
use function in_array;
2221
use function method_exists;
2322
use function realpath;
2423

@@ -139,30 +138,13 @@ protected function deleteLog(string $name): void
139138

140139
protected function allowOperation(Operation $operation, Options $options): bool
141140
{
142-
if (! $this->allowEnvironment($operation)) {
141+
if (! $operation->shouldRun()) {
143142
return false;
144143
}
145144

146145
return ! $this->disallowBefore($operation, $options);
147146
}
148147

149-
protected function allowEnvironment(Operation $operation): bool
150-
{
151-
$env = $this->config->environment();
152-
153-
return $operation->shouldRun()
154-
&& $operation->shouldBeEnvironment()
155-
&& $this->exceptEnvironment($env, $operation->exceptEnvironment());
156-
}
157-
158-
/**
159-
* @deprecated
160-
*/
161-
protected function exceptEnvironment(?string $env, array $except): bool
162-
{
163-
return empty($except) || ! in_array($env, $except, true);
164-
}
165-
166148
protected function disallowBefore(Operation $operation, Options $options): bool
167149
{
168150
return $options->before && ! $operation->needBefore();

0 commit comments

Comments
 (0)