Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: fix implicit array creation #9316

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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']);
Comment on lines +125 to 127
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Late to comment this, I prefer this kind of style.

$filters = [
          'before' => array_intersect($filtersLongest['before'], $filtersShortest['before']),
          'after' => array_intersect($filtersLongest['after'], $filtersShortest['after']),
];

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I realised later on that I can do it that way. You can send a PR to clean that up.


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
Loading