Skip to content

Commit 0ed469c

Browse files
committed
refactor: replace empty()
1 parent e6fca6e commit 0ed469c

File tree

4 files changed

+18
-15
lines changed

4 files changed

+18
-15
lines changed

system/API/ResponseTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ protected function format($data = null)
318318

319319
// Determine correct response type through content negotiation if not explicitly declared
320320
if (
321-
(empty($this->format) || ! in_array($this->format, ['json', 'xml'], true))
321+
! in_array($this->format, ['json', 'xml'], true)
322322
&& $this->request instanceof IncomingRequest
323323
) {
324324
$mime = $this->request->negotiate(

system/Autoloader/FileLocator.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public function locateFile(string $file, ?string $folder = null, string $ext = '
6767
$segments = explode('\\', $file);
6868

6969
// The first segment will be empty if a slash started the filename.
70-
if (empty($segments[0])) {
70+
if ($segments[0] === '') {
7171
unset($segments[0]);
7272
}
7373

@@ -89,7 +89,7 @@ public function locateFile(string $file, ?string $folder = null, string $ext = '
8989
}
9090

9191
// if no namespaces matched then quit
92-
if (empty($paths)) {
92+
if ($paths === []) {
9393
return false;
9494
}
9595

@@ -272,7 +272,7 @@ public function findQualifiedNameFromPath(string $path)
272272
foreach ($this->getNamespaces() as $namespace) {
273273
$namespace['path'] = realpath($namespace['path']) ?: $namespace['path'];
274274

275-
if (empty($namespace['path'])) {
275+
if ($namespace['path'] === '') {
276276
continue;
277277
}
278278

system/BaseModel.php

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ public function find($id = null)
567567
'singleton' => $singleton,
568568
]);
569569

570-
if (! empty($eventData['returnData'])) {
570+
if (isset($eventData['returnData']) && $eventData['returnData'] === true) {
571571
return $eventData['data'];
572572
}
573573
}
@@ -629,7 +629,7 @@ public function findAll(int $limit = 0, int $offset = 0)
629629
'singleton' => false,
630630
]);
631631

632-
if (! empty($eventData['returnData'])) {
632+
if (isset($eventData['returnData']) && $eventData['returnData'] === true) {
633633
return $eventData['data'];
634634
}
635635
}
@@ -667,7 +667,7 @@ public function first()
667667
'singleton' => true,
668668
]);
669669

670-
if (! empty($eventData['returnData'])) {
670+
if (isset($eventData['returnData']) && $eventData['returnData'] === true) {
671671
return $eventData['data'];
672672
}
673673
}
@@ -703,7 +703,7 @@ public function first()
703703
*/
704704
public function save($row): bool
705705
{
706-
if (empty($row)) {
706+
if ((array) $row === []) {
707707
return true;
708708
}
709709

@@ -729,7 +729,9 @@ public function save($row): bool
729729
*/
730730
protected function shouldUpdate($row): bool
731731
{
732-
return ! empty($this->getIdValue($row));
732+
$id = $this->getIdValue($row);
733+
734+
return ! ($id === null || $id === []);
733735
}
734736

735737
/**
@@ -1510,15 +1512,15 @@ public function validate($row): bool
15101512
{
15111513
$rules = $this->getValidationRules();
15121514

1513-
if ($this->skipValidation || $rules === [] || empty($row)) {
1514-
return true;
1515-
}
1516-
15171515
// Validation requires array, so cast away.
15181516
if (is_object($row)) {
15191517
$row = (array) $row;
15201518
}
15211519

1520+
if ($this->skipValidation || $rules === [] || $row === []) {
1521+
return true;
1522+
}
1523+
15221524
$rules = $this->cleanValidationRules ? $this->cleanValidationRules($rules, $row) : $rules;
15231525

15241526
// If no data existed that needs validation
@@ -1632,7 +1634,7 @@ public function allowCallbacks(bool $val = true)
16321634
protected function trigger(string $event, array $eventData)
16331635
{
16341636
// Ensure it's a valid event
1635-
if (! isset($this->{$event}) || empty($this->{$event})) {
1637+
if (! isset($this->{$event}) || $this->{$event} === []) {
16361638
return $eventData;
16371639
}
16381640

@@ -1772,7 +1774,7 @@ protected function transformDataToArray($row, string $type): array
17721774
throw new InvalidArgumentException(sprintf('Invalid type "%s" used upon transforming data to array.', $type));
17731775
}
17741776

1775-
if (! $this->allowEmptyInserts && empty($row)) {
1777+
if (! $this->allowEmptyInserts && ($row === null || (array) $row === [])) {
17761778
throw DataException::forEmptyDataset($type);
17771779
}
17781780

system/RESTful/ResourceController.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ public function delete($id = null)
105105
* Set/change the expected response representation for returned objects
106106
*
107107
* @param string $format json/xml
108+
* @phpstan-param 'json'|'xml' $format
108109
*
109110
* @return void
110111
*/

0 commit comments

Comments
 (0)