Skip to content

Commit 9afbe0f

Browse files
author
Simon Mönch
authored
Force use statements for global function, constants and classes if they are not colliding (#432)
1 parent e0ecfcd commit 9afbe0f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+221
-95
lines changed

phpcs.xml.dist

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,20 @@
1515

1616
<rule ref="SlevomatCodingStandard.Commenting.InlineDocCommentDeclaration.InvalidFormat"/>
1717
<rule ref="SlevomatCodingStandard.Functions.StaticClosure"/>
18-
<rule ref="SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly.ReferenceViaFallbackGlobalName"/>
19-
<rule ref="SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly.ReferenceViaFullyQualifiedName">
18+
<rule ref="SlevomatCodingStandard.Namespaces.AlphabeticallySortedUses"/>
19+
<rule ref="SlevomatCodingStandard.Namespaces.NamespaceSpacing"/>
20+
<rule ref="SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly">
21+
<properties>
22+
<property name="allowFallbackGlobalConstants" value="false"/>
23+
<property name="allowFallbackGlobalFunctions" value="false"/>
24+
<property name="allowFullyQualifiedGlobalClasses" value="false"/>
25+
<property name="allowFullyQualifiedGlobalConstants" value="false"/>
26+
<property name="allowFullyQualifiedGlobalFunctions" value="false"/>
27+
<property name="allowFullyQualifiedNameForCollidingClasses" value="true"/>
28+
<property name="allowFullyQualifiedNameForCollidingConstants" value="true"/>
29+
<property name="allowFullyQualifiedNameForCollidingFunctions" value="true"/>
30+
<property name="searchAnnotations" value="true"/>
31+
</properties>
2032
<exclude-pattern>src/bootstrap\.php</exclude-pattern>
2133
<exclude-pattern>src/functions\.php</exclude-pattern>
2234
</rule>

src/Autoload/ScoperAutoloadGenerator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@
1414

1515
namespace Humbug\PhpScoper\Autoload;
1616

17+
use Humbug\PhpScoper\Whitelist;
18+
use PhpParser\Node\Name\FullyQualified;
1719
use function array_map;
1820
use function array_unshift;
1921
use function chr;
2022
use function explode;
21-
use Humbug\PhpScoper\Whitelist;
2223
use function implode;
23-
use PhpParser\Node\Name\FullyQualified;
2424
use function sprintf;
2525
use function str_repeat;
2626
use function str_replace;

src/Configuration.php

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,40 @@
1414

1515
namespace Humbug\PhpScoper;
1616

17+
use Humbug\PhpScoper\Patcher\SymfonyPatcher;
18+
use InvalidArgumentException;
19+
use Iterator;
20+
use RuntimeException;
21+
use SplFileInfo;
22+
use Symfony\Component\Filesystem\Filesystem;
23+
use Symfony\Component\Finder\Finder;
24+
use function array_filter;
1725
use function array_key_exists;
26+
use function array_keys;
27+
use function array_map;
28+
use function array_merge;
29+
use function array_reduce;
30+
use function array_unique;
1831
use function array_unshift;
19-
use const DIRECTORY_SEPARATOR;
2032
use function dirname;
2133
use function file_exists;
34+
use function file_get_contents;
2235
use function gettype;
23-
use Humbug\PhpScoper\Patcher\SymfonyPatcher;
24-
use InvalidArgumentException;
36+
use function in_array;
2537
use function is_array;
2638
use function is_bool;
39+
use function is_callable;
40+
use function is_dir;
2741
use function is_file;
2842
use function is_link;
43+
use function is_readable;
2944
use function is_string;
30-
use Iterator;
45+
use function iterator_to_array;
3146
use function readlink;
3247
use function realpath;
33-
use RuntimeException;
34-
use SplFileInfo;
3548
use function sprintf;
36-
use Symfony\Component\Filesystem\Filesystem;
37-
use Symfony\Component\Finder\Finder;
49+
use function trim;
50+
use const DIRECTORY_SEPARATOR;
3851

3952
final class Configuration
4053
{

src/Console/Application.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@
1515
namespace Humbug\PhpScoper\Console;
1616

1717
use Humbug\PhpScoper\Container;
18-
use function Humbug\PhpScoper\get_php_scoper_version;
1918
use Symfony\Component\Console\Application as SymfonyApplication;
19+
use function Humbug\PhpScoper\get_php_scoper_version;
20+
use function sprintf;
21+
use function strpos;
2022
use function trim;
2123

2224
final class Application extends SymfonyApplication

src/Console/Command/AddPrefixCommand.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,9 @@
1414

1515
namespace Humbug\PhpScoper\Console\Command;
1616

17-
use function count;
1817
use Humbug\PhpScoper\Autoload\ScoperAutoloadGenerator;
1918
use Humbug\PhpScoper\Configuration;
2019
use Humbug\PhpScoper\Console\ScoperLogger;
21-
use function Humbug\PhpScoper\get_common_path;
2220
use Humbug\PhpScoper\Scoper;
2321
use Humbug\PhpScoper\Scoper\ConfigurableScoper;
2422
use Humbug\PhpScoper\Throwable\Exception\ParsingException;
@@ -33,6 +31,23 @@
3331
use Symfony\Component\Console\Style\SymfonyStyle;
3432
use Symfony\Component\Filesystem\Filesystem;
3533
use Throwable;
34+
use function array_keys;
35+
use function array_map;
36+
use function bin2hex;
37+
use function count;
38+
use function file_exists;
39+
use function file_get_contents;
40+
use function getcwd;
41+
use function Humbug\PhpScoper\get_common_path;
42+
use function is_dir;
43+
use function is_writable;
44+
use function preg_match;
45+
use function random_bytes;
46+
use function sprintf;
47+
use function str_replace;
48+
use function strlen;
49+
use function usort;
50+
use const DIRECTORY_SEPARATOR;
3651

3752
final class AddPrefixCommand extends BaseCommand
3853
{

src/Console/Command/BaseCommand.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
use Symfony\Component\Console\Exception\RuntimeException;
2020
use Symfony\Component\Console\Input\InputInterface;
2121
use Symfony\Component\Console\Input\InputOption;
22+
use function chdir;
23+
use function file_exists;
24+
use function getcwd;
25+
use function sprintf;
2226

2327
abstract class BaseCommand extends Command
2428
{

src/Console/Command/InitCommand.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121
use Symfony\Component\Console\Style\OutputStyle;
2222
use Symfony\Component\Console\Style\SymfonyStyle;
2323
use Symfony\Component\Filesystem\Filesystem;
24+
use function file_exists;
25+
use function getcwd;
26+
use function sprintf;
27+
use const DIRECTORY_SEPARATOR;
2428

2529
final class InitCommand extends BaseCommand
2630
{

src/Console/ScoperLogger.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@
2020
use Symfony\Component\Console\Output\NullOutput;
2121
use Symfony\Component\Console\Output\OutputInterface;
2222
use Symfony\Component\Console\Style\SymfonyStyle;
23+
use function count;
24+
use function memory_get_peak_usage;
25+
use function memory_get_usage;
26+
use function microtime;
27+
use function round;
28+
use function sprintf;
2329

2430
/**
2531
* @private

src/Patcher/SymfonyPatcher.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
namespace Humbug\PhpScoper\Patcher;
1616

1717
use function preg_replace;
18+
use function sprintf;
1819
use function strpos;
1920

2021
final class SymfonyPatcher

src/PhpParser/NodeTraverser.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@
1414

1515
namespace Humbug\PhpScoper\PhpParser;
1616

17-
use function array_slice;
18-
use function array_values;
19-
use function count;
2017
use Humbug\PhpScoper\PhpParser\Node\NameFactory;
2118
use PhpParser\Node;
2219
use PhpParser\Node\Stmt;
@@ -27,6 +24,12 @@
2724
use PhpParser\Node\Stmt\Use_;
2825
use PhpParser\Node\Stmt\UseUse;
2926
use PhpParser\NodeTraverser as PhpParserNodeTraverser;
27+
use function array_map;
28+
use function array_slice;
29+
use function array_splice;
30+
use function array_values;
31+
use function count;
32+
use function current;
3033

3134
/**
3235
* @private

0 commit comments

Comments
 (0)