Skip to content

Commit 2f6f61a

Browse files
authored
refactor: fix phpstan errors in BaseBuilder (#10466)
1 parent 69796fc commit 2f6f61a

16 files changed

Lines changed: 170 additions & 617 deletions

File tree

system/Database/BaseBuilder.php

Lines changed: 89 additions & 76 deletions
Large diffs are not rendered by default.

system/Database/OCI8/Builder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class Builder extends BaseBuilder
3434
/**
3535
* ORDER BY random keyword
3636
*
37-
* @var array
37+
* @var list<string>
3838
*/
3939
protected $randomKeyword = [
4040
'"DBMS_RANDOM"."RANDOM"',

system/Database/Postgre/Builder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class Builder extends BaseBuilder
3030
/**
3131
* ORDER BY random keyword
3232
*
33-
* @var array
33+
* @var list<string>
3434
*/
3535
protected $randomKeyword = [
3636
'RANDOM()',
@@ -140,7 +140,7 @@ public function decrement(string $column, int $value = 1)
140140
* we simply do a DELETE and an INSERT on the first key/value
141141
* combo, assuming that it's either the primary key or a unique key.
142142
*
143-
* @param array|null $set An associative array of insert values
143+
* @param array<string, mixed>|null $set An associative array of insert values
144144
*
145145
* @return BaseResult|false|Query|string
146146
*

system/Database/SQLSRV/Builder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class Builder extends BaseBuilder
3636
/**
3737
* ORDER BY random keyword
3838
*
39-
* @var array
39+
* @var list<string>
4040
*/
4141
protected $randomKeyword = [
4242
'NEWID()',
@@ -644,7 +644,7 @@ protected function compileSelect($selectOverride = false): string
644644
* Compiles the select statement based on the other functions called
645645
* and runs the query
646646
*
647-
* @return ResultInterface
647+
* @return false|ResultInterface|string
648648
*/
649649
public function get(?int $limit = null, int $offset = 0, bool $reset = true)
650650
{

system/Database/SQLite3/Builder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class Builder extends BaseBuilder
4444
/**
4545
* ORDER BY random keyword
4646
*
47-
* @var array
47+
* @var list<string>
4848
*/
4949
protected $randomKeyword = [
5050
'RANDOM()',

tests/system/Database/Builder/UnionTest.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,6 @@
2525
#[Group('Others')]
2626
final class UnionTest extends CIUnitTestCase
2727
{
28-
/**
29-
* @var MockConnection
30-
*/
31-
protected $db;
32-
3328
protected function setUp(): void
3429
{
3530
parent::setUp();

tests/system/Database/Builder/WhenTest.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,6 @@
2525
#[Group('Others')]
2626
final class WhenTest extends CIUnitTestCase
2727
{
28-
/**
29-
* @var MockConnection
30-
*/
31-
protected $db;
32-
3328
protected function setUp(): void
3429
{
3530
parent::setUp();

tests/system/Database/Builder/WhereTest.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,6 @@
3030
#[Group('Others')]
3131
final class WhereTest extends CIUnitTestCase
3232
{
33-
/**
34-
* @var MockConnection
35-
*/
36-
protected $db;
37-
3833
protected function setUp(): void
3934
{
4035
parent::setUp();
@@ -407,6 +402,9 @@ public function testWhereInvalidKeyThrowInvalidArgumentException($key): void
407402
$builder->whereIn($key, ['Politician', 'Accountant']);
408403
}
409404

405+
/**
406+
* @return iterable<string, array{string|null}>
407+
*/
410408
public static function provideWhereInvalidKeyThrowInvalidArgumentException(): iterable
411409
{
412410
return [
@@ -427,6 +425,9 @@ public function testWhereInEmptyValuesThrowInvalidArgumentException($values): vo
427425
$builder->whereIn('name', $values);
428426
}
429427

428+
/**
429+
* @return iterable<string, array{mixed}>
430+
*/
430431
public static function provideWhereInEmptyValuesThrowInvalidArgumentException(): iterable
431432
{
432433
return [

tests/system/Database/Live/SQLite3/GetIndexDataTest.php

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

1414
namespace CodeIgniter\Database\Live\SQLite3;
1515

16-
use CodeIgniter\Database\SQLite3\Connection;
1716
use CodeIgniter\Database\SQLite3\Forge;
1817
use CodeIgniter\Test\CIUnitTestCase;
1918
use Config\Database;
@@ -26,11 +25,6 @@
2625
#[Group('DatabaseLive')]
2726
final class GetIndexDataTest extends CIUnitTestCase
2827
{
29-
/**
30-
* @var Connection
31-
*/
32-
protected $db;
33-
3428
private Forge $forge;
3529

3630
protected function setUp(): void

utils/phpstan-baseline/argument.type.neon

Lines changed: 11 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,7 @@
1-
# total 54 errors
1+
# total 33 errors
22

33
parameters:
44
ignoreErrors:
5-
-
6-
message: '#^Parameter \#3 \.\.\.\$arrays of function array_map expects array, int\|string given\.$#'
7-
count: 1
8-
path: ../../system/Database/BaseBuilder.php
9-
10-
-
11-
message: '#^Parameter \#3 \.\.\.\$arrays of function array_map expects array, int\|string given\.$#'
12-
count: 1
13-
path: ../../system/Database/OCI8/Builder.php
14-
15-
-
16-
message: '#^Parameter \#3 \.\.\.\$arrays of function array_map expects array, int\|string given\.$#'
17-
count: 1
18-
path: ../../system/Database/Postgre/Builder.php
19-
20-
-
21-
message: '#^Parameter \#3 \.\.\.\$arrays of function array_map expects array, int\|string given\.$#'
22-
count: 1
23-
path: ../../system/Database/SQLite3/Builder.php
24-
255
-
266
message: '#^Parameter \#2 \$to of method CodeIgniter\\Router\\RouteCollection\:\:add\(\) expects array\<mixed\>\|\(Closure\(mixed \.\.\.\)\: \(CodeIgniter\\HTTP\\ResponseInterface\|string\|void\)\)\|string, Closure\(mixed\)\: CodeIgniter\\HTTP\\ResponseInterface given\.$#'
277
count: 1
@@ -52,21 +32,6 @@ parameters:
5232
count: 2
5333
path: ../../tests/system/Config/FactoriesTest.php
5434

55-
-
56-
message: '#^Parameter \#1 \$from of method CodeIgniter\\Database\\BaseBuilder\<CodeIgniter\\Database\\BaseConnection\>\:\:from\(\) expects array\|string, null given\.$#'
57-
count: 1
58-
path: ../../tests/system/Database/Builder/FromTest.php
59-
60-
-
61-
message: '#^Parameter \#3 \$subject of function str_replace expects array\<string\>\|string, CodeIgniter\\Database\\ResultInterface given\.$#'
62-
count: 10
63-
path: ../../tests/system/Database/Builder/GetTest.php
64-
65-
-
66-
message: '#^Parameter \#3 \$subject of function str_replace expects array\<string\>\|string, CodeIgniter\\Database\\ResultInterface\|false given\.$#'
67-
count: 6
68-
path: ../../tests/system/Database/Builder/GetTest.php
69-
7035
-
7136
message: '#^Parameter \#1 \$fields of method CodeIgniter\\Database\\Forge\<CodeIgniter\\Database\\BaseConnection\>\:\:addField\(\) expects array\<string, array\|string\>\|string, array\<int, string\> given\.$#'
7237
count: 2
@@ -127,6 +92,16 @@ parameters:
12792
count: 1
12893
path: ../../tests/system/Test/FeatureTestTraitTest.php
12994

95+
-
96+
message: '#^Parameter \#1 \$body of method CodeIgniter\\HTTP\\Response\:\:setJSON\(\) expects array\<mixed\>\|object\|string, false given\.$#'
97+
count: 1
98+
path: ../../tests/system/Test/TestResponseTest.php
99+
100+
-
101+
message: '#^Parameter \#1 \$body of method CodeIgniter\\HTTP\\Response\:\:setJSON\(\) expects array\<mixed\>\|object\|string, true given\.$#'
102+
count: 1
103+
path: ../../tests/system/Test/TestResponseTest.php
104+
130105
-
131106
message: '#^Parameter \#2 \$context of method CodeIgniter\\View\\Parser\:\:setData\(\) expects ''attr''\|''css''\|''html''\|''js''\|''raw''\|''url''\|null, ''unknown'' given\.$#'
132107
count: 3
@@ -151,13 +126,3 @@ parameters:
151126
message: '#^Parameter \#2 \$resultID of class CodeIgniter\\View\\DBResultDummy constructor expects mysqli_result, null given\.$#'
152127
count: 2
153128
path: ../../tests/system/View/TableTest.php
154-
155-
-
156-
message: '#^Parameter \#1 \$body of method CodeIgniter\\HTTP\\Response\:\:setJSON\(\) expects array\<mixed\>\|object\|string, false given\.$#'
157-
count: 1
158-
path: ../../tests/system/Test/TestResponseTest.php
159-
160-
-
161-
message: '#^Parameter \#1 \$body of method CodeIgniter\\HTTP\\Response\:\:setJSON\(\) expects array\<mixed\>\|object\|string, true given\.$#'
162-
count: 1
163-
path: ../../tests/system/Test/TestResponseTest.php

0 commit comments

Comments
 (0)