From c06d9281d9fde54b8fcb13fe4722ddfb53d320ba Mon Sep 17 00:00:00 2001 From: "John Paul E. Balandan, CPA" Date: Thu, 12 Dec 2024 00:46:54 +0800 Subject: [PATCH] refactor: fix implicit array creation --- phpstan-baseline.php | 24 ------------------- .../AutoRouterImproved/AutoRouteCollector.php | 1 + system/Helpers/url_helper.php | 2 ++ .../DataConverter/DataConverterTest.php | 12 ++++------ 4 files changed, 8 insertions(+), 31 deletions(-) diff --git a/phpstan-baseline.php b/phpstan-baseline.php index 0688da8c787e..7be3e519494d 100644 --- a/phpstan-baseline.php +++ b/phpstan-baseline.php @@ -889,12 +889,6 @@ 'count' => 3, 'path' => __DIR__ . '/system/Commands/Utilities/Routes.php', ]; -$ignoreErrors[] = [ - // identifier: variable.implicitArray - 'message' => '#^Implicit array creation is not allowed \\- variable \\$filters might not exist\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Commands/Utilities/Routes/AutoRouterImproved/AutoRouteCollector.php', -]; $ignoreErrors[] = [ // identifier: missingType.iterableValue 'message' => '#^Method CodeIgniter\\\\Commands\\\\Utilities\\\\Routes\\\\AutoRouterImproved\\\\AutoRouteCollector\\:\\:addFilters\\(\\) has parameter \\$routes with no value type specified in iterable type array\\.$#', @@ -7351,18 +7345,6 @@ 'count' => 1, 'path' => __DIR__ . '/system/Helpers/url_helper.php', ]; -$ignoreErrors[] = [ - // identifier: variable.implicitArray - 'message' => '#^Implicit array creation is not allowed \\- variable \\$atts might not exist\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Helpers/url_helper.php', -]; -$ignoreErrors[] = [ - // identifier: variable.undefined - 'message' => '#^Variable \\$atts might not be defined\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Helpers/url_helper.php', -]; $ignoreErrors[] = [ // identifier: empty.notAllowed 'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#', @@ -12739,12 +12721,6 @@ 'count' => 1, 'path' => __DIR__ . '/tests/system/Cookie/CookieTest.php', ]; -$ignoreErrors[] = [ - // identifier: variable.implicitArray - 'message' => '#^Implicit array creation is not allowed \\- variable \\$array does not exist\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/tests/system/DataConverter/DataConverterTest.php', -]; $ignoreErrors[] = [ // identifier: missingType.callable 'message' => '#^Method CodeIgniter\\\\DataConverter\\\\DataConverterTest\\:\\:createDataConverter\\(\\) has parameter \\$extractor with no signature specified for Closure\\.$#', diff --git a/system/Commands/Utilities/Routes/AutoRouterImproved/AutoRouteCollector.php b/system/Commands/Utilities/Routes/AutoRouterImproved/AutoRouteCollector.php index 4c705fd439b1..afd231d59999 100644 --- a/system/Commands/Utilities/Routes/AutoRouterImproved/AutoRouteCollector.php +++ b/system/Commands/Utilities/Routes/AutoRouterImproved/AutoRouteCollector.php @@ -122,6 +122,7 @@ private function addFilters($routes) $filtersShortest = $filterCollector->get($route['method'], $routePath . $sampleUri); // Get common array elements + $filters = []; $filters['before'] = array_intersect($filtersLongest['before'], $filtersShortest['before']); $filters['after'] = array_intersect($filtersLongest['after'], $filtersShortest['after']); diff --git a/system/Helpers/url_helper.php b/system/Helpers/url_helper.php index 4fd6b4f7e42b..28bb2cf4c2a1 100644 --- a/system/Helpers/url_helper.php +++ b/system/Helpers/url_helper.php @@ -211,6 +211,8 @@ function anchor_popup($uri = '', string $title = '', $attributes = false, ?App $ $windowName = '_blank'; } + $atts = []; + foreach (['width' => '800', 'height' => '600', 'scrollbars' => 'yes', 'menubar' => 'no', 'status' => 'yes', 'resizable' => 'yes', 'screenx' => '0', 'screeny' => '0'] as $key => $val) { $atts[$key] = $attributes[$key] ?? $val; unset($attributes[$key]); diff --git a/tests/system/DataConverter/DataConverterTest.php b/tests/system/DataConverter/DataConverterTest.php index c8975fc114fd..c57e8593af86 100644 --- a/tests/system/DataConverter/DataConverterTest.php +++ b/tests/system/DataConverter/DataConverterTest.php @@ -667,13 +667,11 @@ public function testExtractWithClosure(): void 'created_at' => 'datetime', 'updated_at' => 'datetime', ]; - $extractor = static function ($obj): array { - $array['id'] = $obj->id; - $array['name'] = $obj->name; - $array['created_at'] = $obj->created_at; - - return $array; - }; + $extractor = static fn ($obj): array => [ + 'id' => $obj->id, + 'name' => $obj->name, + 'created_at' => $obj->created_at, + ]; $converter = $this->createDataConverter($types, [], db_connect(), null, $extractor); $phpData = [