Skip to content

Commit 0174725

Browse files
committed
refactor: Rename hasRationalPrimaryKey()
1 parent 4c14510 commit 0174725

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

system/BaseModel.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -966,7 +966,7 @@ public function insertBatch(?array $set = null, ?bool $escape = null, int $batch
966966
*/
967967
public function update($id = null, $row = null): bool
968968
{
969-
if ($this->hasRationalPrimaryKey($id)) {
969+
if ($this->hasAllowedValueId($id)) {
970970
$id = [$id];
971971
}
972972

@@ -1093,7 +1093,7 @@ public function updateBatch(?array $set = null, ?string $index = null, int $batc
10931093
*/
10941094
public function delete($id = null, bool $purge = false)
10951095
{
1096-
if ($this->hasRationalPrimaryKey($id)) {
1096+
if ($this->hasAllowedValueId($id)) {
10971097
$id = [$id];
10981098
}
10991099

@@ -1900,7 +1900,7 @@ protected function convertToReturnType(array $row, string $returnType): array|ob
19001900
*
19011901
* @throws InvalidArgumentException
19021902
*/
1903-
protected function hasRationalPrimaryKey($id): bool
1903+
protected function hasAllowedValueId($id): bool
19041904
{
19051905
if (is_bool($id)) {
19061906
throw new InvalidArgumentException('The ID value should not be boolean.');

system/Model.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ protected function doUpdate($id = null, $row = null): bool
381381

382382
$builder = $this->builder();
383383

384-
if ((is_array($id) && $id !== []) || $this->hasRationalPrimaryKey($id)) {
384+
if ((is_array($id) && $id !== []) || $this->hasAllowedValueId($id)) {
385385
$builder = $builder->whereIn($this->table . '.' . $this->primaryKey, $id);
386386
}
387387

@@ -409,7 +409,7 @@ protected function doDelete($id = null, bool $purge = false)
409409
$set = [];
410410
$builder = $this->builder();
411411

412-
if ((is_array($id) && $id !== []) || $this->hasRationalPrimaryKey($id)) {
412+
if ((is_array($id) && $id !== []) || $this->hasAllowedValueId($id)) {
413413
$builder = $builder->whereIn($this->primaryKey, $id);
414414
}
415415

tests/system/Models/MiscellaneousModelTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,31 +125,31 @@ public function testEmptyDataInTransformDataToArray(): void
125125
$method([], 'insert');
126126
}
127127

128-
public function testHasRationalPrimaryKeyWithBoolean(): void
128+
public function testHasAllowedValueIdWithBoolean(): void
129129
{
130130
$this->expectException(InvalidArgumentException::class);
131131
$this->expectExceptionMessage('The ID value should not be boolean.');
132132

133133
$this->createModel(JobModel::class);
134-
$method = self::getPrivateMethodInvoker($this->model, 'hasRationalPrimaryKey');
134+
$method = self::getPrivateMethodInvoker($this->model, 'hasAllowedValueId');
135135
$method(true); // @phpstan-ignore argument.type
136136
}
137137

138138
/**
139139
* @param float|int|string|null $value
140140
*/
141-
#[DataProvider('provideHasRationalPrimaryKey')]
142-
public function testHasRationalPrimaryKey($value, bool $expected): void
141+
#[DataProvider('provideHasAllowedValueId')]
142+
public function testHasAllowedValueId($value, bool $expected): void
143143
{
144144
$this->createModel(JobModel::class);
145-
$method = self::getPrivateMethodInvoker($this->model, 'hasRationalPrimaryKey');
145+
$method = self::getPrivateMethodInvoker($this->model, 'hasAllowedValueId');
146146
$this->assertSame($method($value), $expected);
147147
}
148148

149149
/**
150150
* @return list<list<bool|float|int|string|null>>
151151
*/
152-
public static function provideHasRationalPrimaryKey(): iterable
152+
public static function provideHasAllowedValueId(): iterable
153153
{
154154
return [
155155
[0, false],

0 commit comments

Comments
 (0)