2018-05-11 16:30:25 +02:00
< ? php declare ( strict_types = 1 );
2018-04-29 18:08:42 +02:00
2018-05-11 16:30:25 +02:00
require_once __DIR__ . '/vendor/autoload.php' ;
2018-04-29 18:08:42 +02:00
use Isolated\Symfony\Component\Finder\Finder ;
2018-05-11 16:30:25 +02:00
use Nette\Loaders\RobotLoader ;
use Nette\Utils\Strings ;
// whitelist all "Rector\*" classes, so they're not prefixed and people can use them in .yml configs and extends
// before this gets solved: https://github.com/humbug/php-scoper/issues/192#issuecomment-382157399
$robotLoader = new RobotLoader ();
$robotLoader -> addDirectory ( __DIR__ . '/src' );
$robotLoader -> addDirectory ( __DIR__ . '/packages' );
$robotLoader -> excludeDirectory ( '*tests*' );
$robotLoader -> rebuild ();
$whitelistedRectorClasses = [];
foreach ( $robotLoader -> getIndexedClasses () as $class => $file ) {
if ( Strings :: startsWith ( $class , 'Rector' )) {
$whitelistedRectorClasses [] = $class ;
}
}
2018-04-29 18:08:42 +02:00
return [
'prefix' => 'RectorPrefixed' ,
'finders' => [
Finder :: create ()
-> files ()
-> ignoreVCS ( true )
2018-05-11 16:30:25 +02:00
// ↓ this is regex!
-> notName ( '#LICENSE|.*\\.md|.*\\.dist|Makefile|composer\\.json|composer\\.lock|.*\\.sh#' )
-> in ( __DIR__ . '/bin' )
-> in ( __DIR__ . '/config' )
-> in ( __DIR__ . '/packages' )
-> in ( __DIR__ . '/src' )
-> in ( __DIR__ . '/vendor' )
2018-04-29 18:08:42 +02:00
-> exclude ([
'docs' ,
2018-05-11 16:30:25 +02:00
'Tests' ,
'tests' ,
'Test' ,
'test'
2018-04-29 18:08:42 +02:00
])
,
2018-05-11 16:30:25 +02:00
// to make "composer dump" work
Finder :: create () -> append ([
'composer.json' ,
2018-05-11 17:01:10 +02:00
// Fixes non-standard php-cs-fixer tests in /src
__DIR__ . '/vendor/friendsofphp/php-cs-fixer/tests/TestCase.php'
]),
// Fixes non-standard php-cs-fixer tests in /src:
// "Could not scan for classes inside "/var/www/rector/build/vendor/friendsofphp/php-cs-fixer/tests/Test/AbstractFixerTestCase.php" which does not appear to be a file nor a folder"
Finder :: create ()
-> files ()
-> in ( __DIR__ . '/vendor/friendsofphp/php-cs-fixer/tests/Test' )
2018-04-29 18:08:42 +02:00
],
2018-05-11 16:30:25 +02:00
'whitelist' => $whitelistedRectorClasses ,
2018-04-29 18:08:42 +02:00
'patchers' => [
function ( string $filePath , string $prefix , string $contents ) : string {
// Change the contents here.
return $contents ;
},
],
];
2018-05-11 16:30:25 +02:00
## Extra notes
// composer.json: "find build/ -type f | xargs sed -i 's/use Symfony/use RectorPrefixed\\\\\\\\Symfony/g'" is needed for:
// https://github.com/symfony/symfony/blob/226e2f3949c5843b67826aca4839c2c6b95743cf/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php#L897