From 5640d513d2434ac4cec2d3c946d44a40a7a468d6 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Tue, 31 May 2022 19:38:05 +0700 Subject: [PATCH] [Core] Fix bootstrap stubs load on PHP 7.2 when vendor/ excluded via skip() (#2394) * [Core] Fix bootstrap stubs load on PHP 7.2 when vendor/ excluded via skip() * [ci-review] Rector Rectify * final touch: call ->getRealPath() to ensure got real path value * really final touch: PHPStan * [ci-review] Rector Rectify * Add e2e test for rector/rector under php 7.2 * final touch: remove unneeded comment * really final touch: eol Co-authored-by: GitHub Action --- .../.github/workflows/e2e_php72.yaml | 32 +++++++++++++++++++ .../e2e/reflection-union-php72/composer.json | 11 +++++++ .../e2e/reflection-union-php72/rector.php | 15 +++++++++ .../e2e/reflection-union-php72/src/foo.php | 14 ++++++++ src/Autoloading/BootstrapFilesIncluder.php | 12 ++++--- 5 files changed, 80 insertions(+), 4 deletions(-) create mode 100644 build/target-repository/.github/workflows/e2e_php72.yaml create mode 100644 build/target-repository/e2e/reflection-union-php72/composer.json create mode 100644 build/target-repository/e2e/reflection-union-php72/rector.php create mode 100644 build/target-repository/e2e/reflection-union-php72/src/foo.php diff --git a/build/target-repository/.github/workflows/e2e_php72.yaml b/build/target-repository/.github/workflows/e2e_php72.yaml new file mode 100644 index 00000000000..6a373e19fe1 --- /dev/null +++ b/build/target-repository/.github/workflows/e2e_php72.yaml @@ -0,0 +1,32 @@ +name: End to End tests on PHP 7.2 + +on: + pull_request: null + push: + branches: + - main + +jobs: + end_to_end_on_php72: + runs-on: ubuntu-latest + + name: End to end test - PHP 7.2 with load ReflectionUnionType stub + + steps: + - uses: actions/checkout@v2 + + - uses: shivammathur/setup-php@v2 + with: + php-version: "7.2" + coverage: none + + # wait for deploy to packagist + - run: sleep 70 + + - + run: composer install --ansi + working-directory: e2e/reflection-union-php72 + + - + run: vendor/bin/rector process --ansi + working-directory: e2e/reflection-union-php72 diff --git a/build/target-repository/e2e/reflection-union-php72/composer.json b/build/target-repository/e2e/reflection-union-php72/composer.json new file mode 100644 index 00000000000..17cdb632c2f --- /dev/null +++ b/build/target-repository/e2e/reflection-union-php72/composer.json @@ -0,0 +1,11 @@ +{ + "autoload": { + "psr-4": { + "App\\": "src/" + } + }, + "require": { + "php": "7.2.*", + "rector/rector": "dev-main" + } +} diff --git a/build/target-repository/e2e/reflection-union-php72/rector.php b/build/target-repository/e2e/reflection-union-php72/rector.php new file mode 100644 index 00000000000..6d2eb1e4fde --- /dev/null +++ b/build/target-repository/e2e/reflection-union-php72/rector.php @@ -0,0 +1,15 @@ +paths([ + __DIR__ . '/src' + ]); + + $rectorConfig->skip([ + __DIR__ . '/vendor', + ]); +}; diff --git a/build/target-repository/e2e/reflection-union-php72/src/foo.php b/build/target-repository/e2e/reflection-union-php72/src/foo.php new file mode 100644 index 00000000000..844a77709f1 --- /dev/null +++ b/build/target-repository/e2e/reflection-union-php72/src/foo.php @@ -0,0 +1,14 @@ +format('C'); + } +} diff --git a/src/Autoloading/BootstrapFilesIncluder.php b/src/Autoloading/BootstrapFilesIncluder.php index 1013e69fba1..cf2c75d137e 100644 --- a/src/Autoloading/BootstrapFilesIncluder.php +++ b/src/Autoloading/BootstrapFilesIncluder.php @@ -6,7 +6,9 @@ use Rector\Core\Configuration\Option; use Rector\Core\Exception\ShouldNotHappenException; -use Rector\Core\FileSystem\FilesFinder; +use RecursiveDirectoryIterator; +use RecursiveIteratorIterator; +use SplFileInfo; use Symplify\PackageBuilder\Parameter\ParameterProvider; use Throwable; use Webmozart\Assert\Assert; @@ -14,8 +16,7 @@ final class BootstrapFilesIncluder { public function __construct( - private readonly ParameterProvider $parameterProvider, - private readonly FilesFinder $filesFinder + private readonly ParameterProvider $parameterProvider ) { } @@ -56,7 +57,10 @@ public function includeBootstrapFiles(): void return; } - $stubs = $this->filesFinder->findInDirectoriesAndFiles([$stubsRectorDirectory], ['php']); + $dir = new RecursiveDirectoryIterator($stubsRectorDirectory, RecursiveDirectoryIterator::SKIP_DOTS); + /** @var SplFileInfo[] $stubs */ + $stubs = new RecursiveIteratorIterator($dir); + foreach ($stubs as $stub) { require_once $stub->getRealPath(); }