Skip to content

Commit 7e3cc7e

Browse files
committed
refactor: replace empty()
1 parent 07f7a8d commit 7e3cc7e

File tree

5 files changed

+20
-13
lines changed

5 files changed

+20
-13
lines changed

system/Test/CIUnitTestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ abstract class CIUnitTestCase extends TestCase
123123

124124
/**
125125
* The namespace(s) to help us find the migration classes.
126-
* Empty is equivalent to running `spark migrate --all`.
126+
* `null` is equivalent to running `spark migrate --all`.
127127
* Note that running "all" runs migrations in date order,
128128
* but specifying namespaces runs them in namespace order (then date)
129129
*

system/Test/DatabaseTestTrait.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ protected function regressDatabase()
120120
}
121121

122122
// If no namespace was specified then rollback all
123-
if (empty($this->namespace)) {
123+
if ($this->namespace === null) {
124124
$this->migrations->setNamespace(null);
125125
$this->migrations->regress(0, 'tests');
126126
}
@@ -146,7 +146,7 @@ protected function migrateDatabase()
146146
}
147147

148148
// If no namespace was specified then migrate all
149-
if (empty($this->namespace)) {
149+
if ($this->namespace === null) {
150150
$this->migrations->setNamespace(null);
151151
$this->migrations->latest('tests');
152152
self::$doneMigration = true;
@@ -182,8 +182,8 @@ protected function setUpSeed()
182182
*/
183183
protected function runSeeds()
184184
{
185-
if (! empty($this->seed)) {
186-
if (! empty($this->basePath)) {
185+
if ($this->seed !== '') {
186+
if ($this->basePath !== '') {
187187
$this->seeder->setPath(rtrim($this->basePath, '/') . '/Seeds');
188188
}
189189

system/Test/TestResponse.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,10 @@ public function isOK(): bool
136136
return false;
137137
}
138138

139+
$body = (string) $this->response->getBody();
140+
139141
// Empty bodies are not considered valid, unless in redirects
140-
return ! ($status < 300 && empty($this->response->getBody()));
142+
return ! ($status < 300 && $body === '');
141143
}
142144

143145
/**

system/Validation/CreditCardRules.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ public function valid_cc_number(?string $ccNumber, string $type): bool
185185
}
186186

187187
// If empty, it's not a card type we recognize, or invalid type.
188-
if (empty($info)) {
188+
if ($info === null) {
189189
return false;
190190
}
191191

system/Validation/Rules.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ public function is_not_unique(?string $str, string $field, array $data): bool
105105
->limit(1);
106106

107107
if (
108-
! empty($whereField) && ! empty($whereValue)
108+
$whereField !== null && $whereField !== ''
109+
&& $whereValue !== null && $whereValue !== ''
109110
&& ! preg_match('/^\{(\w+)\}$/', $whereValue)
110111
) {
111112
$row = $row->where($whereField, $whereValue);
@@ -150,7 +151,8 @@ public function is_unique(?string $str, string $field, array $data): bool
150151
->limit(1);
151152

152153
if (
153-
! empty($ignoreField) && ! empty($ignoreValue)
154+
$ignoreField !== null && $ignoreField !== ''
155+
&& $ignoreValue !== null && $ignoreValue !== ''
154156
&& ! preg_match('/^\{(\w+)\}$/', $ignoreValue)
155157
) {
156158
$row = $row->where("{$ignoreField} !=", $ignoreValue);
@@ -276,8 +278,10 @@ public function required_with($str = null, ?string $fields = null, array $data =
276278

277279
foreach (explode(',', $fields) as $field) {
278280
if (
279-
(array_key_exists($field, $data) && ! empty($data[$field]))
280-
|| (strpos($field, '.') !== false && ! empty(dot_array_search($field, $data)))
281+
(array_key_exists($field, $data)
282+
&& ! empty($data[$field])) // @phpstan-ignore-line Use empty()
283+
|| (strpos($field, '.') !== false
284+
&& ! empty(dot_array_search($field, $data))) // @phpstan-ignore-line Use empty()
281285
) {
282286
$requiredFields[] = $field;
283287
}
@@ -323,7 +327,8 @@ public function required_without(
323327
foreach (explode(',', $otherFields) as $otherField) {
324328
if (
325329
(strpos($otherField, '.') === false)
326-
&& (! array_key_exists($otherField, $data) || empty($data[$otherField]))
330+
&& (! array_key_exists($otherField, $data)
331+
|| empty($data[$otherField])) // @phpstan-ignore-line Use empty()
327332
) {
328333
return false;
329334
}
@@ -338,7 +343,7 @@ public function required_without(
338343
$fieldKey = $fieldSplitArray[1];
339344

340345
if (is_array($fieldData)) {
341-
return ! empty(dot_array_search($otherField, $data)[$fieldKey]);
346+
return ! empty(dot_array_search($otherField, $data)[$fieldKey]); // @phpstan-ignore-line Use empty()
342347
}
343348
$nowField = str_replace('*', $fieldKey, $otherField);
344349
$nowFieldVaule = dot_array_search($nowField, $data);

0 commit comments

Comments
 (0)