-
-
Notifications
You must be signed in to change notification settings - Fork 742
Expand file tree
/
Copy pathbootstrap.php
More file actions
53 lines (43 loc) · 1.63 KB
/
bootstrap.php
File metadata and controls
53 lines (43 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
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.
*/
if (
// verify PHPUnit is running
defined('PHPUNIT_COMPOSER_INSTALL')
// no need to preload if Node interface exists
&& ! interface_exists(Node::class, false)
// load preload.php on local PHPUnit installation
&& ! class_exists(Version::class, false)
// load preload.php only on PHPUnit 12+
&& 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;
// already loaded in bin/rector.php
if (defined('__RECTOR_RUNNING__')) {
return;
}
// load prefixed or native class, e.g. for running tests
if (strpos($class, 'RectorPrefix') === 0 || strpos($class, 'Rector\\') === 0) {
if ($composerAutoloader === null) {
// prefixed version autoload
$composerAutoloader = require __DIR__ . '/vendor/autoload.php';
}
// some weird collision with PHPStan custom rule tests
if (! is_int($composerAutoloader)) {
$composerAutoloader->loadClass($class);
}
}
});