Skip to content

Commit 02ef667

Browse files
authored
refactor: fix remaining argument.type and method.childParameterType errors (#10502)
1 parent 4a2fef4 commit 02ef667

8 files changed

Lines changed: 21 additions & 83 deletions

File tree

‎system/Cookie/Cookie.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,7 @@ public function offsetGet($offset): bool|int|string
619619
/**
620620
* Offset to set.
621621
*
622-
* @param string $offset
622+
* @param string|null $offset
623623
* @param bool|int|string $value
624624
*
625625
* @throws LogicException

‎system/I18n/TimeTrait.php‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1239,10 +1239,14 @@ public function __isset($name): bool
12391239
/**
12401240
* This is called when we unserialize the Time object.
12411241
*
1242-
* @param array{date: string, timezone: string, timezone_type: int} $data
1242+
* @param array<mixed, mixed> $data
12431243
*/
12441244
public function __unserialize(array $data): void
12451245
{
1246-
parent::__construct($data['date'], new DateTimeZone($data['timezone']));
1246+
$date = $data['date'] ?? null;
1247+
$timezone = $data['timezone'] ?? null;
1248+
assert(is_string($date) && is_string($timezone));
1249+
1250+
parent::__construct($date, new DateTimeZone($timezone));
12471251
}
12481252
}

‎system/Log/Handlers/ChromeLoggerHandler.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ public function __construct(array $config = [])
9999
* will stop. Any handlers that have not run, yet, will not
100100
* be run.
101101
*
102-
* @param string $level
103-
* @param string $message
102+
* @param string $level
103+
* @param object|string $message
104104
*/
105105
public function handle($level, $message): bool
106106
{

‎tests/system/CodeIgniterTest.php‎

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public function testRunClosureRoute(): void
119119

120120
// Inject mock router.
121121
$routes = service('routes');
122-
$routes->add('pages/(:segment)', static function ($segment): void {
122+
$routes->add('pages/(:segment)', static function (string $segment = ''): void {
123123
echo 'You want to see "' . esc($segment) . '" page.';
124124
});
125125
$router = service('router', $routes, service('incomingrequest'));
@@ -231,7 +231,7 @@ public function testControllersCanReturnString(): void
231231
$routes = service('routes');
232232
$routes->add(
233233
'pages/(:segment)',
234-
static fn ($segment): string => 'You want to see "' . esc($segment) . '" page.',
234+
static fn (string $segment = ''): string => 'You want to see "' . esc($segment) . '" page.',
235235
);
236236
$router = service('router', $routes, service('incomingrequest'));
237237
Services::injectMock('router', $router);
@@ -253,12 +253,10 @@ public function testControllersCanReturnResponseObject(): void
253253

254254
// Inject mock router.
255255
$routes = service('routes');
256-
$routes->add('pages/(:segment)', static function ($segment) {
257-
$response = service('response');
258-
$string = "You want to see 'about' page.";
259-
260-
return $response->setBody($string);
261-
});
256+
$routes->add(
257+
'pages/(:segment)',
258+
static fn () => service('response')->setBody("You want to see 'about' page."),
259+
);
262260
$router = service('router', $routes, service('incomingrequest'));
263261
Services::injectMock('router', $router);
264262

@@ -282,11 +280,10 @@ public function testControllersCanReturnDownloadResponseObject(): void
282280

283281
// Inject mock router.
284282
$routes = service('routes');
285-
$routes->add('pages/(:segment)', static function ($segment) {
286-
$response = service('response');
287-
288-
return $response->download('some.txt', 'some text', true);
289-
});
283+
$routes->add(
284+
'pages/(:segment)',
285+
static fn () => service('response')->download('some.txt', 'some text', true),
286+
);
290287
$router = service('router', $routes, service('incomingrequest'));
291288
Services::injectMock('router', $router);
292289

‎tests/system/RESTful/ResourceControllerTest.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ public function testFormat(): void
310310
$resource = new MockResourceController();
311311
$this->assertSame('json', $resource->getFormat());
312312

313-
$resource->setFormat('Nonsense');
313+
$resource->setFormat('Nonsense'); // @phpstan-ignore argument.type (Testing that an invalid format is silently ignored)
314314
$this->assertSame('json', $resource->getFormat());
315315

316316
$resource->setFormat('xml');

‎utils/phpstan-baseline/argument.type.neon‎

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

‎utils/phpstan-baseline/loader.neon‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
# total 24 errors
1+
# total 13 errors
22

33
includes:
4-
- argument.type.neon
54
- arguments.count.neon
65
- assign.propertyType.neon
76
- deadCode.unreachable.neon
87
- function.resultUnused.neon
9-
- method.childParameterType.neon
108
- method.childReturnType.neon
119
- missingType.iterableValue.neon
1210
- property.defaultValue.neon

‎utils/phpstan-baseline/method.childParameterType.neon‎

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

0 commit comments

Comments
 (0)