From 83811e6e8a4e74122a4c144993f36dad7dbe5deb Mon Sep 17 00:00:00 2001 From: Matthew Brown Date: Sun, 18 Mar 2018 10:52:54 -0400 Subject: [PATCH] Analyse scoped build with Psalm --- bin/build-phar.sh | 6 +++++ bin/phar.psalm.xml | 60 ++++++++++++++++++++++++++++++++++++++++++++++ scoper.inc.php | 32 ++++++++++++++++++++++++- 3 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 bin/phar.psalm.xml diff --git a/bin/build-phar.sh b/bin/build-phar.sh index aa67c0f52..2cc34f98f 100755 --- a/bin/build-phar.sh +++ b/bin/build-phar.sh @@ -21,6 +21,12 @@ php -d memory_limit=-1 `which php-scoper` add-prefix --prefix='PsalmPhar' --outp # and optimize the loader composer dump-autoload --working-dir=build/psalm --classmap-authoritative --no-dev +chmod 755 build/psalm/psalm + +cp bin/phar.psalm.xml build/psalm/psalm.xml + +./build/psalm/psalm --config=build/psalm/psalm.xml --root=build/psalm + php -d memory_limit=-1 -d phar.readonly=0 `which box` compile # clean up build diff --git a/bin/phar.psalm.xml b/bin/phar.psalm.xml new file mode 100644 index 000000000..ae169b307 --- /dev/null +++ b/bin/phar.psalm.xml @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/scoper.inc.php b/scoper.inc.php index d618d9f2d..c2891800c 100644 --- a/scoper.inc.php +++ b/scoper.inc.php @@ -57,17 +57,47 @@ return [ return $contents; }, + function ($filePath, $prefix, $contents) { + if (strpos($filePath, realpath(__DIR__ . '/src/Psalm')) === 0) { + return str_replace( + [' \\Psalm\\', ' \\PhpParser\\'], + [' \\' . $prefix . '\\Psalm\\', ' \\' . $prefix . '\\PhpParser\\'], + $contents + ); + } + + return $contents; + }, + function ($filePath, $prefix, $contents) { + if (strpos($filePath, realpath(__DIR__ . '/vendor/openlss')) === 0) { + return str_replace( + $prefix . '\\DomDocument', + 'DomDocument', + $contents + ); + } + + return $contents; + }, function ($filePath, $prefix, $contents) { if ($filePath === realpath(__DIR__ . '/src/Psalm/PropertyMap.php') || $filePath === realpath(__DIR__ . '/src/Psalm/CallMap.php') || $filePath === realpath(__DIR__ . '/src/Psalm/Stubs/CoreGenericFunctions.php') || $filePath === realpath(__DIR__ . '/src/Psalm/Stubs/CoreGenericClasses.php') ) { - return str_replace( + $contents = str_replace( ['namespace ' . $prefix . ';', $prefix . '\\\\', $prefix . '\\'], '', $contents ); + + $contents = str_replace( + ['\'phpparser\\\\', 'PhpParser\\\\'], + ['\'' . strtolower($prefix) . '\\\\phpparser\\\\', $prefix . '\\\\PhpParser\\\\'], + $contents + ); + + return str_replace('Psalm\\\\', $prefix . '\\\\Psalm\\\\', $contents); } return $contents;