Skip to content

Commit d4977d0

Browse files
committed
update phpstan baseline
1 parent 0383f06 commit d4977d0

11 files changed

Lines changed: 199 additions & 1041 deletions

system/Superglobals.php

Lines changed: 70 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,38 @@
3030
*/
3131
final class Superglobals
3232
{
33+
/**
34+
* @var array<string, array|float|int|string>
35+
*/
3336
private array $server;
37+
38+
/**
39+
* @var array<string, array|string>
40+
*/
3441
private array $get;
42+
43+
/**
44+
* @var array<string, array|string>
45+
*/
3546
private array $post;
47+
48+
/**
49+
* @var array<string, array|string>
50+
*/
3651
private array $cookie;
52+
53+
/**
54+
* @var array<string, array|string>
55+
*/
3756
private array $request;
3857

58+
/**
59+
* @param array<string, array|float|int|string>|null $server
60+
* @param array<string, array|string>|null $get
61+
* @param array<string, array|string>|null $post
62+
* @param array<string, array|string>|null $cookie
63+
* @param array<string, array|string>|null $request
64+
*/
3965
public function __construct(
4066
?array $server = null,
4167
?array $get = null,
@@ -52,6 +78,8 @@ public function __construct(
5278

5379
/**
5480
* Get a value from $_SERVER
81+
*
82+
* @return array<array-key, mixed>|float|int|string|null
5583
*/
5684
public function server(string $key): array|float|int|string|null
5785
{
@@ -60,6 +88,8 @@ public function server(string $key): array|float|int|string|null
6088

6189
/**
6290
* Set a value in $_SERVER
91+
*
92+
* @param array<array-key, mixed>|float|int|string $value
6393
*/
6494
public function setServer(string $key, array|float|int|string $value): void
6595
{
@@ -77,6 +107,8 @@ public function unsetServer(string $key): void
77107

78108
/**
79109
* Get all $_SERVER values
110+
*
111+
* @return array<string, array|float|int|string>
80112
*/
81113
public function getServerArray(): array
82114
{
@@ -85,6 +117,8 @@ public function getServerArray(): array
85117

86118
/**
87119
* Set the entire $_SERVER array
120+
*
121+
* @param array<string, array|float|int|string> $array
88122
*/
89123
public function setServerArray(array $array): void
90124
{
@@ -94,6 +128,8 @@ public function setServerArray(array $array): void
94128

95129
/**
96130
* Get a value from $_GET
131+
*
132+
* @return array<array-key, mixed>|string|null
97133
*/
98134
public function get(string $key): array|string|null
99135
{
@@ -102,6 +138,8 @@ public function get(string $key): array|string|null
102138

103139
/**
104140
* Set a value in $_GET
141+
*
142+
* @param array<array-key, mixed>|string $value
105143
*/
106144
public function setGet(string $key, array|string $value): void
107145
{
@@ -119,6 +157,8 @@ public function unsetGet(string $key): void
119157

120158
/**
121159
* Get all $_GET values
160+
*
161+
* @return array<string, array|string>
122162
*/
123163
public function getGetArray(): array
124164
{
@@ -127,6 +167,8 @@ public function getGetArray(): array
127167

128168
/**
129169
* Set the entire $_GET array
170+
*
171+
* @param array<string, array|string> $array
130172
*/
131173
public function setGetArray(array $array): void
132174
{
@@ -136,6 +178,8 @@ public function setGetArray(array $array): void
136178

137179
/**
138180
* Get a value from $_POST
181+
*
182+
* @return array<array-key, mixed>|string|null
139183
*/
140184
public function post(string $key): array|string|null
141185
{
@@ -144,6 +188,8 @@ public function post(string $key): array|string|null
144188

145189
/**
146190
* Set a value in $_POST
191+
*
192+
* @param array<array-key, mixed>|string $value
147193
*/
148194
public function setPost(string $key, array|string $value): void
149195
{
@@ -161,6 +207,8 @@ public function unsetPost(string $key): void
161207

162208
/**
163209
* Get all $_POST values
210+
*
211+
* @return array<string, array|string>
164212
*/
165213
public function getPostArray(): array
166214
{
@@ -169,6 +217,8 @@ public function getPostArray(): array
169217

170218
/**
171219
* Set the entire $_POST array
220+
*
221+
* @param array<string, array|string> $array
172222
*/
173223
public function setPostArray(array $array): void
174224
{
@@ -178,6 +228,8 @@ public function setPostArray(array $array): void
178228

179229
/**
180230
* Get a value from $_COOKIE
231+
*
232+
* @return array<array-key, mixed>|string|null
181233
*/
182234
public function cookie(string $key): array|string|null
183235
{
@@ -186,6 +238,8 @@ public function cookie(string $key): array|string|null
186238

187239
/**
188240
* Set a value in $_COOKIE
241+
*
242+
* @param array<array-key, mixed>|string $value
189243
*/
190244
public function setCookie(string $key, array|string $value): void
191245
{
@@ -203,6 +257,8 @@ public function unsetCookie(string $key): void
203257

204258
/**
205259
* Get all $_COOKIE values
260+
*
261+
* @return array<string, array|string>
206262
*/
207263
public function getCookieArray(): array
208264
{
@@ -211,6 +267,8 @@ public function getCookieArray(): array
211267

212268
/**
213269
* Set the entire $_COOKIE array
270+
*
271+
* @param array<string, array|string> $array
214272
*/
215273
public function setCookieArray(array $array): void
216274
{
@@ -220,6 +278,8 @@ public function setCookieArray(array $array): void
220278

221279
/**
222280
* Get a value from $_REQUEST
281+
*
282+
* @return array<array-key, mixed>|string|null
223283
*/
224284
public function request(string $key): array|string|null
225285
{
@@ -228,6 +288,8 @@ public function request(string $key): array|string|null
228288

229289
/**
230290
* Set a value in $_REQUEST
291+
*
292+
* @param array<array-key, mixed>|string $value
231293
*/
232294
public function setRequest(string $key, array|string $value): void
233295
{
@@ -245,6 +307,8 @@ public function unsetRequest(string $key): void
245307

246308
/**
247309
* Get all $_REQUEST values
310+
*
311+
* @return array<string, array|string>
248312
*/
249313
public function getRequestArray(): array
250314
{
@@ -253,6 +317,8 @@ public function getRequestArray(): array
253317

254318
/**
255319
* Set the entire $_REQUEST array
320+
*
321+
* @param array<string, array|string> $array
256322
*/
257323
public function setRequestArray(array $array): void
258324
{
@@ -264,6 +330,8 @@ public function setRequestArray(array $array): void
264330
* Get a superglobal array by name
265331
*
266332
* @param string $name The superglobal name (server, get, post, cookie, request)
333+
*
334+
* @return array<string, array|float|int|string>
267335
*/
268336
public function getGlobalArray(string $name): array
269337
{
@@ -280,8 +348,8 @@ public function getGlobalArray(string $name): array
280348
/**
281349
* Set a superglobal array by name
282350
*
283-
* @param string $name The superglobal name (server, get, post, cookie, request)
284-
* @param array $array The array to set
351+
* @param string $name The superglobal name (server, get, post, cookie, request)
352+
* @param array<string, array|float|int|string> $array The array to set
285353
*/
286354
public function setGlobalArray(string $name, array $array): void
287355
{

tests/system/Config/BaseConfigTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ public function testSetsDefaultValues(): void
201201
public function testSetsDefaultValuesEncryptionUsingHex2Bin(): void
202202
{
203203
putenv('encryption.key');
204-
unset($_ENV['encryption.key']); // @phpstan-ignore codeigniter.superglobalAccess
204+
unset($_ENV['encryption.key']);
205205
service('superglobals')->unsetServer('encryption.key');
206206

207207
$dotenv = new DotEnv($this->fixturesFolder, 'encryption.env');
@@ -218,7 +218,7 @@ public function testSetsDefaultValuesEncryptionUsingHex2Bin(): void
218218
public function testSetDefaultValuesEncryptionUsingBase64(): void
219219
{
220220
putenv('encryption.key');
221-
unset($_ENV['encryption.key']); // @phpstan-ignore codeigniter.superglobalAccess
221+
unset($_ENV['encryption.key']);
222222
service('superglobals')->unsetServer('encryption.key');
223223

224224
$dotenv = new DotEnv($this->fixturesFolder, 'base64encryption.env');

tests/system/SuperglobalsTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public function testServerSetWithFloat(): void
6666
{
6767
$this->superglobals->setServer('REQUEST_TIME_FLOAT', 1234567890.123);
6868

69-
$this->assertSame(1234567890.123, $this->superglobals->server('REQUEST_TIME_FLOAT'));
69+
$this->assertEqualsWithDelta(1234567890.123, $this->superglobals->server('REQUEST_TIME_FLOAT'), PHP_FLOAT_EPSILON);
7070
}
7171

7272
public function testServerUnset(): void

utils/phpstan-baseline/argument.type.neon

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# total 84 errors
1+
# total 85 errors
22

33
parameters:
44
ignoreErrors:
@@ -122,6 +122,11 @@ parameters:
122122
count: 1
123123
path: ../../tests/system/HTTP/HeaderTest.php
124124

125+
-
126+
message: '#^Parameter \#1 \$array of method CodeIgniter\\Superglobals\:\:setServerArray\(\) expects array\<string, array\|float\|int\|string\>, array\<string, string\|null\> given\.$#'
127+
count: 1
128+
path: ../../tests/system/HTTP/MessageTest.php
129+
125130
-
126131
message: '#^Parameter \#3 \$expire of method CodeIgniter\\HTTP\\Response\:\:setCookie\(\) expects int, string given\.$#'
127132
count: 1

utils/phpstan-baseline/codeigniter.getReassignArray.neon

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
1-
# total 18 errors
1+
# total 9 errors
22

33
parameters:
44
ignoreErrors:
55
-
66
message: '#^Re\-assigning arrays to \$_GET directly is discouraged\.$#'
7-
count: 3
8-
path: ../../tests/system/CommonFunctionsTest.php
9-
10-
-
11-
message: '#^Re\-assigning arrays to \$_GET directly is discouraged\.$#'
12-
count: 2
7+
count: 1
138
path: ../../tests/system/Filters/InvalidCharsTest.php
149

1510
-
@@ -22,11 +17,6 @@ parameters:
2217
count: 1
2318
path: ../../tests/system/HTTP/IncomingRequestTest.php
2419

25-
-
26-
message: '#^Re\-assigning arrays to \$_GET directly is discouraged\.$#'
27-
count: 1
28-
path: ../../tests/system/HTTP/RedirectResponseTest.php
29-
3020
-
3121
message: '#^Re\-assigning arrays to \$_GET directly is discouraged\.$#'
3222
count: 1
@@ -54,5 +44,5 @@ parameters:
5444

5545
-
5646
message: '#^Re\-assigning arrays to \$_GET directly is discouraged\.$#'
57-
count: 5
58-
path: ../../tests/system/Pager/PagerTest.php
47+
count: 1
48+
path: ../../tests/system/SuperglobalsTest.php

0 commit comments

Comments
 (0)