Skip to content

Commit 15c2b5a

Browse files
committed
fix phpstan
1 parent 011ed36 commit 15c2b5a

3 files changed

Lines changed: 13 additions & 9 deletions

File tree

system/BaseModel.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use CodeIgniter\Database\BaseResult;
1919
use CodeIgniter\Database\Exceptions\DatabaseException;
2020
use CodeIgniter\Database\Exceptions\DataException;
21+
use CodeIgniter\Database\Exceptions\UniqueConstraintViolationException;
2122
use CodeIgniter\Database\Query;
2223
use CodeIgniter\Database\RawSql;
2324
use CodeIgniter\DataCaster\Cast\CastInterface;
@@ -869,6 +870,7 @@ protected function validateID(mixed $id, bool $allowArray = true): void
869870
* @return ($returnID is true ? false|int|string : bool)
870871
*
871872
* @throws ReflectionException
873+
* @throws UniqueConstraintViolationException
872874
*/
873875
public function insert($row = null, bool $returnID = true)
874876
{

system/Model.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -723,6 +723,8 @@ protected function doProtectFieldsForInsert(array $row): array
723723
*
724724
* @param array<string, mixed>|object $attributes
725725
* @param array<string, mixed>|object $values
726+
*
727+
* @return array<string, mixed>|false|object
726728
*/
727729
public function firstOrInsert(array|object $attributes, array|object $values = []): array|false|object
728730
{

tests/system/Models/FirstOrInsertModelTest.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function testReturnsExistingRecord(): void
3939

4040
$row = $this->model->firstOrInsert(['email' => 'derek@world.com']);
4141

42-
$this->assertNotNull($row);
42+
$this->assertIsObject($row);
4343
$this->assertSame('Derek Jones', $row->name);
4444
$this->assertSame('derek@world.com', $row->email);
4545
$this->assertSame('US', $row->country);
@@ -66,7 +66,7 @@ public function testValuesAreIgnoredWhenRecordExists(): void
6666
['name' => 'Should Not Change', 'country' => 'XX'],
6767
);
6868

69-
$this->assertNotFalse($row);
69+
$this->assertIsObject($row);
7070
$this->assertSame('Derek Jones', $row->name);
7171
$this->assertSame('US', $row->country);
7272
}
@@ -81,7 +81,7 @@ public function testInsertsNewRecordWhenNotFound(): void
8181
'country' => 'US',
8282
]);
8383

84-
$this->assertNotFalse($row);
84+
$this->assertIsObject($row);
8585
$this->assertSame('new@example.com', $row->email);
8686
$this->seeInDatabase('user', ['email' => 'new@example.com', 'deleted_at' => null]);
8787
}
@@ -95,7 +95,7 @@ public function testMergesValuesOnInsert(): void
9595
['name' => 'New User', 'country' => 'CA'],
9696
);
9797

98-
$this->assertNotFalse($row);
98+
$this->assertIsObject($row);
9999
$this->assertSame('New User', $row->name);
100100
$this->assertSame('CA', $row->country);
101101
$this->seeInDatabase('user', [
@@ -119,7 +119,7 @@ public function testAcceptsObjectForValues(): void
119119
$values,
120120
);
121121

122-
$this->assertNotFalse($row);
122+
$this->assertIsObject($row);
123123
$this->assertSame('Object User', $row->name);
124124
$this->assertSame('DE', $row->country);
125125
$this->seeInDatabase('user', ['email' => 'object@example.com', 'deleted_at' => null]);
@@ -134,7 +134,7 @@ public function testAcceptsObjectForAttributes(): void
134134

135135
$row = $this->model->firstOrInsert($attributes);
136136

137-
$this->assertNotFalse($row);
137+
$this->assertIsObject($row);
138138
$this->assertSame('Derek Jones', $row->name);
139139
$this->seeNumRecords(4, 'user', ['deleted_at' => null]);
140140
}
@@ -150,7 +150,7 @@ public function testAcceptsObjectForAttributesAndInsertsWhenNotFound(): void
150150

151151
$row = $this->model->firstOrInsert($attributes);
152152

153-
$this->assertNotNull($row);
153+
$this->assertIsObject($row);
154154
$this->assertSame('new@example.com', $row->email);
155155
$this->seeInDatabase('user', ['email' => 'new@example.com', 'deleted_at' => null]);
156156
}
@@ -183,7 +183,7 @@ protected function doInsert(array $row): bool
183183
['name' => 'Race User', 'country' => 'US'],
184184
);
185185

186-
$this->assertNotFalse($row);
186+
$this->assertIsObject($row);
187187
$this->assertSame('race@example.com', $row->email);
188188
// The "other process" inserted exactly one record.
189189
$this->seeNumRecords(1, 'user', ['email' => 'race@example.com', 'deleted_at' => null]);
@@ -218,7 +218,7 @@ protected function doInsert(array $row): bool
218218
['name' => 'Race User', 'country' => 'US'],
219219
);
220220

221-
$this->assertNotFalse($row);
221+
$this->assertIsObject($row);
222222
$this->assertSame('race@example.com', $row->email);
223223
$this->seeNumRecords(1, 'user', ['email' => 'race@example.com', 'deleted_at' => null]);
224224
}

0 commit comments

Comments
 (0)