Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions build/target-repository/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,34 @@

declare(strict_types=1);

use PHPParser\Node;
use PHPUnit\Runner\Version;

/**
* The preload.php contains 2 dependencies
* - phpstan/phpdoc-parser
* - nikic/php-parser
*
* They need to be loaded early to avoid conflict version between rector prefixed vendor and Project vendor
* For example, a project may use phpstan/phpdoc-parser v1, while rector uses phpstan/phpdoc-parser uses v2, that will error as class or logic are different.
*/
$isGlobalPHPUnit = class_exists(Version::class, false);
if (
// verify PHPUnit is running
defined('PHPUNIT_COMPOSER_INSTALL')

// no need to preload if Node interface exists
&& ! interface_exists(Node::class, false)

&& ! $isGlobalPHPUnit

// ensure force autoload version with class_exists() with true argument as not yet loaded
// for phpunit 12+ only
&& class_exists(Version::class, true) && (int) Version::id() >= 12
) {
require_once __DIR__ . '/preload.php';
}

// inspired by https://github.com/phpstan/phpstan/blob/master/bootstrap.php
spl_autoload_register(function (string $class): void {
static $composerAutoloader;
Expand Down