Skip to content

Commit e57247f

Browse files
authored
refactor: fix property.nonObject errors (#10451)
1 parent 9e990b5 commit e57247f

8 files changed

Lines changed: 29 additions & 65 deletions

File tree

system/Database/BaseResult.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -387,8 +387,6 @@ public function setRow($key, $value = null)
387387

388388
/**
389389
* Returns the "first" row of the current results.
390-
*
391-
* @return array|object|null
392390
*/
393391
public function getFirstRow(string $type = 'object')
394392
{
@@ -399,8 +397,6 @@ public function getFirstRow(string $type = 'object')
399397

400398
/**
401399
* Returns the "last" row of the current results.
402-
*
403-
* @return array|object|null
404400
*/
405401
public function getLastRow(string $type = 'object')
406402
{
@@ -411,8 +407,6 @@ public function getLastRow(string $type = 'object')
411407

412408
/**
413409
* Returns the "next" row of the current results.
414-
*
415-
* @return array|object|null
416410
*/
417411
public function getNextRow(string $type = 'object')
418412
{
@@ -426,8 +420,6 @@ public function getNextRow(string $type = 'object')
426420

427421
/**
428422
* Returns the "previous" row of the current results.
429-
*
430-
* @return array|object|null
431423
*/
432424
public function getPreviousRow(string $type = 'object')
433425
{

system/Database/ResultInterface.php

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,28 +113,44 @@ public function setRow($key, $value = null);
113113
/**
114114
* Returns the "first" row of the current results.
115115
*
116-
* @return array|object|null
116+
* @template T of object
117+
*
118+
* @param 'array'|'object'|class-string<T> $type The type of result object. 'array', 'object' or class name.
119+
*
120+
* @return ($type is 'object' ? stdClass|null : ($type is 'array' ? array|null : T|null))
117121
*/
118122
public function getFirstRow(string $type = 'object');
119123

120124
/**
121125
* Returns the "last" row of the current results.
122126
*
123-
* @return array|object|null
127+
* @template T of object
128+
*
129+
* @param 'array'|'object'|class-string<T> $type The type of result object. 'array', 'object' or class name.
130+
*
131+
* @return ($type is 'object' ? stdClass|null : ($type is 'array' ? array|null : T|null))
124132
*/
125133
public function getLastRow(string $type = 'object');
126134

127135
/**
128136
* Returns the "next" row of the current results.
129137
*
130-
* @return array|object|null
138+
* @template T of object
139+
*
140+
* @param 'array'|'object'|class-string<T> $type The type of result object. 'array', 'object' or class name.
141+
*
142+
* @return ($type is 'object' ? stdClass|null : ($type is 'array' ? array|null : T|null))
131143
*/
132144
public function getNextRow(string $type = 'object');
133145

134146
/**
135147
* Returns the "previous" row of the current results.
136148
*
137-
* @return array|object|null
149+
* @template T of object
150+
*
151+
* @param 'array'|'object'|class-string<T> $type The type of result object. 'array', 'object' or class name.
152+
*
153+
* @return ($type is 'object' ? stdClass|null : ($type is 'array' ? array|null : T|null))
138154
*/
139155
public function getPreviousRow(string $type = 'object');
140156

system/Test/Mock/MockConnection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ public function error(): array
196196

197197
public function insertID(): int
198198
{
199-
return $this->connID->insert_id;
199+
return 0;
200200
}
201201

202202
/**

tests/system/Database/Live/FabricatorLiveTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use CodeIgniter\Test\DatabaseTestTrait;
1919
use CodeIgniter\Test\Fabricator;
2020
use PHPUnit\Framework\Attributes\Group;
21+
use stdClass;
2122
use Tests\Support\Models\UserModel;
2223
use Tests\Support\Models\ValidModel;
2324

@@ -39,6 +40,7 @@ public function testCreateAddsToDatabase(): void
3940
$fabricator->setOverrides(['country' => 'Spain']);
4041

4142
$result = $fabricator->create();
43+
$this->assertInstanceOf(stdClass::class, $result);
4244

4345
$this->seeInDatabase('user', ['name' => $result->name]);
4446
}

tests/system/Database/Live/GetTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
namespace CodeIgniter\Database\Live;
1515

16+
use CodeIgniter\Database\BaseResult;
1617
use CodeIgniter\Database\Exceptions\DatabaseException;
1718
use CodeIgniter\Test\CIUnitTestCase;
1819
use CodeIgniter\Test\DatabaseTestTrait;
@@ -227,13 +228,12 @@ public function testGetAnotherDataSeek(): void
227228
public function testFreeResult(): void
228229
{
229230
$data = $this->db->table('job')->where('id', 4)->get();
231+
$this->assertInstanceOf(BaseResult::class, $data);
230232

231233
$details = $data->getResult();
232-
233234
$this->assertSame('Musician', $details[0]->name);
234235

235236
$data->freeResult();
236-
237237
$this->assertFalse($data->resultID);
238238
}
239239

@@ -292,6 +292,7 @@ public function testGetNextRow(): void
292292
public function testGetPreviousRow(): void
293293
{
294294
$user = $this->db->table('user')->get();
295+
$this->assertInstanceOf(BaseResult::class, $user);
295296

296297
$user->currentRow = 3;
297298

tests/system/Test/FabricatorTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use CodeIgniter\Config\Factories;
1717
use CodeIgniter\Model;
1818
use PHPUnit\Framework\Attributes\Group;
19+
use stdClass;
1920
use Tests\Support\Models\EntityModel;
2021
use Tests\Support\Models\EventModel;
2122
use Tests\Support\Models\FabricatorModel;
@@ -410,6 +411,7 @@ public function testCreateMockSetsDatabaseFields(): void
410411
$fabricator = new Fabricator(FabricatorModel::class);
411412

412413
$result = $fabricator->create(null, true);
414+
$this->assertInstanceOf(stdClass::class, $result);
413415

414416
$this->assertIsInt($result->id);
415417
$this->assertIsInt($result->created_at);

utils/phpstan-baseline/loader.neon

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# total 1446 errors
1+
# total 1434 errors
22

33
includes:
44
- argument.type.neon
@@ -13,7 +13,6 @@ includes:
1313
- missingType.iterableValue.neon
1414
- missingType.parameter.neon
1515
- property.defaultValue.neon
16-
- property.nonObject.neon
1716
- property.notFound.neon
1817
- property.phpDocType.neon
1918
- staticMethod.notFound.neon

utils/phpstan-baseline/property.nonObject.neon

Lines changed: 0 additions & 48 deletions
This file was deleted.

0 commit comments

Comments
 (0)