Skip to content

Commit

Permalink
[Core] Fix bootstrap stubs load on PHP 7.2 when vendor/ excluded via …
Browse files Browse the repository at this point in the history
…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 <action@github.com>
  • Loading branch information
samsonasik and actions-user committed May 31, 2022
1 parent cd405e6 commit 5640d51
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 4 deletions.
32 changes: 32 additions & 0 deletions build/target-repository/.github/workflows/e2e_php72.yaml
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions build/target-repository/e2e/reflection-union-php72/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"autoload": {
"psr-4": {
"App\\": "src/"
}
},
"require": {
"php": "7.2.*",
"rector/rector": "dev-main"
}
}
15 changes: 15 additions & 0 deletions build/target-repository/e2e/reflection-union-php72/rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->paths([
__DIR__ . '/src'
]);

$rectorConfig->skip([
__DIR__ . '/vendor',
]);
};
14 changes: 14 additions & 0 deletions build/target-repository/e2e/reflection-union-php72/src/foo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace App;

class Foo {

/**
* @param \DateTime|\DateTimeImmutable $date
* @return string
*/
public function bar($date) {
return $date->format('C');
}
}
12 changes: 8 additions & 4 deletions src/Autoloading/BootstrapFilesIncluder.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@

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;

final class BootstrapFilesIncluder
{
public function __construct(
private readonly ParameterProvider $parameterProvider,
private readonly FilesFinder $filesFinder
private readonly ParameterProvider $parameterProvider
) {
}

Expand Down Expand Up @@ -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();
}
Expand Down

0 comments on commit 5640d51

Please sign in to comment.