Skip to content

Commit 472d954

Browse files
committed
cs fix
1 parent 3cffd2e commit 472d954

File tree

3 files changed

+29
-28
lines changed

3 files changed

+29
-28
lines changed

system/BaseModel.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -795,7 +795,7 @@ protected function validateID($id, bool $allowArray = true): void
795795
// Check if arrays are allowed
796796
if (! $allowArray) {
797797
throw new InvalidArgumentException(
798-
'Invalid primary key: only a single value is allowed, not an array.'
798+
'Invalid primary key: only a single value is allowed, not an array.',
799799
);
800800
}
801801

@@ -808,7 +808,7 @@ protected function validateID($id, bool $allowArray = true): void
808808
foreach ($id as $key => $valueId) {
809809
if (is_array($valueId)) {
810810
throw new InvalidArgumentException(
811-
sprintf('Invalid primary key at index %s: nested arrays are not allowed.', $key)
811+
sprintf('Invalid primary key at index %s: nested arrays are not allowed.', $key),
812812
);
813813
}
814814

@@ -822,15 +822,16 @@ protected function validateID($id, bool $allowArray = true): void
822822
// Check for invalid single values
823823
if (in_array($id, [null, 0, '0', '', true, false], true)) {
824824
$type = is_bool($id) ? 'boolean ' . var_export($id, true) : var_export($id, true);
825+
825826
throw new InvalidArgumentException(
826-
sprintf('Invalid primary key: %s is not allowed.', $type)
827+
sprintf('Invalid primary key: %s is not allowed.', $type),
827828
);
828829
}
829830

830831
// Only allow int and string at this point
831832
if (! is_int($id) && ! is_string($id)) {
832833
throw new InvalidArgumentException(
833-
sprintf('Invalid primary key: must be int or string, %s given.', get_debug_type($id))
834+
sprintf('Invalid primary key: must be int or string, %s given.', get_debug_type($id)),
834835
);
835836
}
836837
}
@@ -1026,7 +1027,7 @@ public function update($id = null, $row = null): bool
10261027
{
10271028
if ($id !== null) {
10281029
if (! is_array($id)) {
1029-
$id = [$id];
1030+
$id = [$id];
10301031
}
10311032

10321033
$this->validateID($id);

tests/system/Models/DeleteModelTest.php

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ public function testOnlyDeleted(): void
160160
*
161161
* @param int|string|null $emptyValue
162162
*/
163-
#[DataProvider('emptyPkValuesWithWhereClause')]
163+
#[DataProvider('provideDontThrowExceptionWhenSoftDeleteConditionIsSetWithEmptyValue')]
164164
public function testDontThrowExceptionWhenSoftDeleteConditionIsSetWithEmptyValue($emptyValue): void
165165
{
166166
$this->createModel(UserModel::class);
@@ -175,6 +175,24 @@ public function testDontThrowExceptionWhenSoftDeleteConditionIsSetWithEmptyValue
175175
}
176176
}
177177

178+
/**
179+
* Data provider for tests using where() clause.
180+
* These values go into WHERE clause, not through validateID().
181+
*
182+
* @return iterable<array{bool|int|string|null}>
183+
*/
184+
public static function provideDontThrowExceptionWhenSoftDeleteConditionIsSetWithEmptyValue(): iterable
185+
{
186+
return [
187+
[0],
188+
[null],
189+
['0'],
190+
[''],
191+
[true],
192+
[false],
193+
];
194+
}
195+
178196
/**
179197
* @param int|string|null $emptyValue
180198
* @param class-string $exception
@@ -201,7 +219,7 @@ public function testDontDeleteRowsWhenSoftDeleteParamIsEmpty($emptyValue, string
201219

202220
try {
203221
$this->createModel(UserModel::class)->delete($emptyValue);
204-
} catch (DatabaseException | InvalidArgumentException) {
222+
} catch (DatabaseException|InvalidArgumentException) {
205223
// Do nothing - both exceptions are expected for different values.
206224
}
207225

@@ -343,22 +361,4 @@ public static function emptyPkValues(): iterable
343361
],
344362
];
345363
}
346-
347-
/**
348-
* Data provider for tests using where() clause.
349-
* These values go into WHERE clause, not through validateID().
350-
*
351-
* @return iterable<array{bool|int|string|null}>
352-
*/
353-
public static function emptyPkValuesWithWhereClause(): iterable
354-
{
355-
return [
356-
[0],
357-
[null],
358-
['0'],
359-
[''],
360-
[true],
361-
[false],
362-
];
363-
}
364364
}

tests/system/Models/InsertModelTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ public function testInsertBatchWithCasts(): void
418418
public function testInsertWithInvalidPrimaryKeyWhenAutoIncrementDisabled(
419419
$invalidKey,
420420
string $exception,
421-
string $exceptionMessage
421+
string $exceptionMessage,
422422
): void {
423423
$this->expectException($exception);
424424
$this->expectExceptionMessage($exceptionMessage);
@@ -501,12 +501,12 @@ public static function provideInvalidPrimaryKeyValues(): iterable
501501
"array with '0' string" => [
502502
['0'],
503503
InvalidArgumentException::class,
504-
"Invalid primary key: only a single value is allowed, not an array.",
504+
'Invalid primary key: only a single value is allowed, not an array.',
505505
],
506506
'array with empty array' => [
507507
[[]],
508508
InvalidArgumentException::class,
509-
"Invalid primary key: only a single value is allowed, not an array.",
509+
'Invalid primary key: only a single value is allowed, not an array.',
510510
],
511511
];
512512
}

0 commit comments

Comments
 (0)