1515namespace Humbug \PhpScoper ;
1616
1717use Humbug \PhpScoper \Console \Application ;
18- use Humbug \PhpScoper \Console \Command \AddPrefixCommand ;
19- use Humbug \PhpScoper \Console \Command \InitCommand ;
20- use Humbug \PhpScoper \PhpParser \TraverserFactory ;
21- use Humbug \PhpScoper \Scoper \Composer \InstalledPackagesScoper ;
22- use Humbug \PhpScoper \Scoper \Composer \JsonFileScoper ;
23- use Humbug \PhpScoper \Scoper \NullScoper ;
24- use Humbug \PhpScoper \Scoper \PatchScoper ;
25- use Humbug \PhpScoper \Scoper \PhpScoper ;
18+ use Humbug \PhpScoper \Console \ApplicationFactory ;
2619use Iterator ;
27- use PackageVersions \Versions ;
2820use PhpParser \Node ;
2921use PhpParser \Node \Identifier ;
3022use PhpParser \Node \Name ;
3123use PhpParser \Parser ;
32- use PhpParser \ParserFactory ;
33- use Roave \BetterReflection \Reflector \ClassReflector ;
34- use Roave \BetterReflection \Reflector \FunctionReflector ;
35- use Roave \BetterReflection \SourceLocator \Ast \Locator ;
36- use Roave \BetterReflection \SourceLocator \Type \MemoizingSourceLocator ;
37- use Roave \BetterReflection \SourceLocator \Type \PhpInternalSourceLocator ;
38- use Symfony \Component \Console \Application as SymfonyApplication ;
39- use Symfony \Component \Filesystem \Filesystem ;
24+ use function array_map ;
25+ use function count ;
26+ use function is_array ;
4027use function is_object ;
28+ use function is_scalar ;
4129use function is_string ;
4230use function method_exists ;
31+ use function serialize ;
32+ use function strlen ;
33+ use function strpos ;
34+ use function substr ;
35+ use function unserialize ;
4336
44- // TODO: register this file to the list of functions if possible to be autoloaded
45-
46- /**
47- * @private
48- */
49- function create_application (): SymfonyApplication
37+ function create_application (): Application
5038{
51- $ app = new Application ('PHP Scoper ' , get_version ());
52-
53- $ app ->addCommands ([
54- new AddPrefixCommand (
55- new Filesystem (),
56- create_scoper ()
57- ),
58- new InitCommand (),
59- ]);
60-
61- return $ app ;
62- }
63-
64- /**
65- * @private
66- */
67- function get_version (): string
68- {
69- if ('phar: ' === substr (__FILE__ , 0 , 5 )) {
70- return '@git_version_placeholder@ ' ;
71- }
72-
73- $ rawVersion = Versions::getVersion ('humbug/php-scoper ' );
74-
75- [$ prettyVersion , $ commitHash ] = explode ('@ ' , $ rawVersion );
76-
77- return (1 === preg_match ('/9{7}/ ' , $ prettyVersion )) ? $ commitHash : $ prettyVersion ;
39+ return (new ApplicationFactory ())->create ();
7840}
7941
8042/**
8143 * @private
44+ *
45+ * @deprecated Will be removed in future releases.
8246 */
8347function create_scoper (): Scoper
8448{
85- return new PatchScoper (
86- new PhpScoper (
87- create_parser (),
88- new JsonFileScoper (
89- new InstalledPackagesScoper (
90- new NullScoper ()
91- )
92- ),
93- new TraverserFactory (create_reflector ())
94- )
95- );
96- }
97-
98- /**
99- * @private
100- */
101- function create_parser (): Parser
102- {
103- return (new ParserFactory ())->create (ParserFactory::ONLY_PHP7 );
104- }
105-
106- function create_reflector (): Reflector
107- {
108- $ phpParser = create_parser ();
109- $ astLocator = new Locator ($ phpParser );
110-
111- $ sourceLocator = new MemoizingSourceLocator (
112- new PhpInternalSourceLocator ($ astLocator )
113- );
114- $ classReflector = new ClassReflector ($ sourceLocator );
115-
116- return new Reflector (
117- $ classReflector ,
118- new FunctionReflector ($ sourceLocator , $ classReflector )
119- );
49+ return (new class () extends ApplicationFactory {
50+ public static function createScoper (): Scoper
51+ {
52+ return parent ::createScoper ();
53+ }
54+ })::createScoper ();
12055}
12156
12257/**
@@ -140,7 +75,7 @@ function get_common_path(array $paths): string
14075 foreach ($ paths as $ path ) {
14176 if (substr ($ path , $ lastOffset , $ dirLen ) !== $ dir ) {
14277 if (0 < strlen ($ common ) && DIRECTORY_SEPARATOR === $ common [strlen ($ common ) - 1 ]) {
143- $ common = substr ($ common , 0 , strlen ( $ common ) - 1 );
78+ $ common = substr ($ common , 0 , - 1 );
14479 }
14580
14681 return $ common ;
@@ -154,7 +89,7 @@ function get_common_path(array $paths): string
15489 $ common = substr ($ common , 0 , -1 );
15590
15691 if (0 < strlen ($ common ) && DIRECTORY_SEPARATOR === $ common [strlen ($ common ) - 1 ]) {
157- $ common = substr ($ common , 0 , strlen ( $ common ) - 1 );
92+ $ common = substr ($ common , 0 , - 1 );
15893 }
15994
16095 return $ common ;
0 commit comments