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

fix: Correctly scope spl_autoload_register singule parameter #887

Merged
merged 2 commits into from
Nov 3, 2023
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
41 changes: 41 additions & 0 deletions specs/string-literal/func-arg-spl-auto-register.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
'FQCN string argument' => <<<'PHP'
<?php

spl_autoload_register('sodiumCompatAutoloader');
spl_autoload_register('Sodium\compatAutoloader');
spl_autoload_register(['Swift', 'autoload']);
spl_autoload_register(['\Swift', 'autoload']);
spl_autoload_register(['Humbug\\Swift', 'autoload']);
Expand All @@ -51,6 +53,8 @@

namespace Humbug;

\spl_autoload_register('Humbug\\sodiumCompatAutoloader');
\spl_autoload_register('Humbug\\Sodium\\compatAutoloader');
\spl_autoload_register(['Humbug\\Swift', 'autoload']);
\spl_autoload_register(['Humbug\\Swift', 'autoload']);
\spl_autoload_register(['Humbug\\Swift', 'autoload']);
Expand Down Expand Up @@ -84,6 +88,23 @@
PHP,
],

'FQCN string argument on exposed function' => [
'expose-functions' => ['sodiumCompatAutoloader'],
'payload' => <<<'PHP'
<?php

spl_autoload_register('sodiumCompatAutoloader');

----
<?php

namespace Humbug;

\spl_autoload_register('Humbug\\sodiumCompatAutoloader');

PHP,
],

'FQCN string argument on class from an excluded namespace' => [
'exclude-namespaces' => [
'Symfony\Component\Yaml',
Expand All @@ -110,6 +131,26 @@
PHP,
],

'FQCN string argument on function from an excluded namespace' => [
'exclude-namespaces' => [
'Sodium',
'/^$/',
],
'payload' => <<<'PHP'
<?php

spl_autoload_register('Sodium\CompatAutoloader');

----
<?php

namespace {
\spl_autoload_register('Sodium\\CompatAutoloader');
}

PHP,
],

'FQCN string argument with global functions not exposed' => [
'expose-global-functions' => false,
'payload' => <<<'PHP'
Expand Down
1 change: 1 addition & 0 deletions src/PhpParser/NodeVisitor/StringScalarPrefixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ final class StringScalarPrefixer extends NodeVisitorAbstract
'interface_exists',
'is_a',
'is_subclass_of',
'spl_autoload_register',
'trait_exists',
];

Expand Down