Skip to content

Commit

Permalink
Merge pull request #9316 from paulbalandan/implicit-array-creation
Browse files Browse the repository at this point in the history
refactor: fix implicit array creation
  • Loading branch information
samsonasik authored Dec 11, 2024
2 parents 0b0126c + c06d928 commit e9bb603
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 31 deletions.
24 changes: 0 additions & 24 deletions phpstan-baseline.php
Original file line number Diff line number Diff line change
Expand Up @@ -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\\.$#',
Expand Down Expand Up @@ -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\\.$#',
Expand Down Expand Up @@ -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\\.$#',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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']);

Expand Down
2 changes: 2 additions & 0 deletions system/Helpers/url_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down
12 changes: 5 additions & 7 deletions tests/system/DataConverter/DataConverterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down

0 comments on commit e9bb603

Please sign in to comment.