Skip to content
Merged
Show file tree
Hide file tree
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
10 changes: 4 additions & 6 deletions .github/workflows/build_scoped_rector_php70.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,7 @@ jobs:
# the vendor/phpstan/phpstan/bootstrap.php is statically included by composer, so better add empty file
- run: echo "<?php " > vendor/phpstan/phpstan/bootstrap.php
- run: rm -rf vendor/phpstan/phpstan/phpstan.phar
- run: rm phpstan-for-rector.neon

# THIS MUST WORK
- run: bin/rector downgrade-paths
- run: rm -rf phpstan-for-rector.neon

# 1. copy files to $NESTED_DIRECTORY directory Exclude the scoped/nested directories to prevent rsync from copying in a loop
- run: rsync --exclude rector-build-php70 -av * rector-build-php70 --quiet
Expand All @@ -72,8 +69,9 @@ jobs:
php-version: 7.0
coverage: none
- run: |
cp -R rector-prefixed-downgraded-php70/vendor/rector/* vendor/rector/
cp -R rector-prefixed-downgraded-php70/vendor/symfony/string/* vendor/symfony/string/
rm -rf vendor && mkdir -p vendor
cp -R rector-prefixed-downgraded-php70/vendor/* vendor/
rm -rf php-parallel-lint
composer create-project php-parallel-lint/php-parallel-lint php-parallel-lint --ansi

- run: php-parallel-lint/parallel-lint rector-prefixed-downgraded-php70 --exclude rector-prefixed-downgraded-php70/stubs --exclude rector-prefixed-downgraded-php70/vendor/symfony/error-handler/Resources --exclude rector-prefixed-downgraded-php70/vendor/symfony/http-kernel/Resources --exclude rector-prefixed-downgraded-php70/vendor/rector/rector-nette/tests --exclude rector-prefixed-downgraded-php70/vendor/symfony/polyfill-mbstring/bootstrap80.php --exclude rector-prefixed-downgraded-php70/vendor/tracy/tracy/examples --exclude rector-prefixed-downgraded-php70/vendor/rector/rector-installer/tests --exclude rector-prefixed-downgraded-php70/vendor/symplify/smart-file-system/tests --exclude rector-prefixed-downgraded-php70/vendor/symfony/http-foundation/Session --exclude rector-prefixed-downgraded-php70/vendor/symfony/var-dumper --exclude rector-prefixed-downgraded-php70/vendor/nette/caching --exclude rector-prefixed-downgraded-php70/vendor/rector/rector-nette/src/Rector/LNumber --exclude rector-prefixed-downgraded-php70/vendor/symfony/http-foundation/Test --exclude rector-prefixed-downgraded-php70/vendor/symplify/simple-php-doc-parser/tests --exclude rector-prefixed-downgraded-php70/vendor/tracy/tracy/src/Tracy/Bar/panels/info.panel.phtml --exclude rector-prefixed-downgraded-php70/vendor/symfony/string/Slugger/AsciiSlugger.php
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ private function isNullableParam(Param $param): bool
}

/**
* @param ClassMethod|Function_ $functionLike
* @param ClassMethod|Function_|Closure $functionLike
*/
private function refactorParamType(Param $param, FunctionLike $functionLike): bool
{
Expand All @@ -133,7 +133,7 @@ private function refactorParamType(Param $param, FunctionLike $functionLike): bo
}

/**
* @param ClassMethod|Function_ $functionLike
* @param ClassMethod|Function_|Closure $functionLike
*/
private function decorateWithDocBlock(FunctionLike $functionLike, Param $param): void
{
Expand Down
24 changes: 23 additions & 1 deletion scoper-php70.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,28 @@ function (string $filePath, string $prefix, string $content): string {
);
},

function (string $filePath, string $prefix, string $content): string {
if (! Strings::contains($filePath, 'vendor/')) {
return $content;
}

// see https://regex101.com/r/PDGN3K/1
$content = Strings::replace(
$content, '
#: \?\\\\.*#',
''
);

// see https://regex101.com/r/P7nbpU/1
$content = Strings::replace(
$content, '
#\(\?\\.*\s+#',
'('
);

return $content;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This must be handled by Rector. If not, there is a bug somewhere

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this for handilng phpstan's vendor of ondrejmirtes/better-reflection/src that somehow not downgrade the code.

Copy link
Member

@TomasVotruba TomasVotruba May 7, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All packages must be downgraded by Rector. scoper.php is only for tweaking class names for autoload edge cases.

We need to figure out why this downgrade is missed. Maybe its in exlcuded paths in downgrade config for Rector?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some probably caused by exclude config :

'vendor/symfony/http-kernel/HttpKernelBrowser.php',
'vendor/symfony/http-foundation/Session/*',
'vendor/symfony/string/Slugger/AsciiSlugger.php',
'vendor/symfony/cache/*',
'nette/caching/src/Bridges/*',
// This class has an issue for PHP 7.1:
// https://github.com/rectorphp/rector/issues/4816#issuecomment-743209526
// It doesn't happen often, and Rector doesn't use it, so then
// we simply skip downgrading this class
'vendor/symfony/dependency-injection/ExpressionLanguage.php',
'vendor/symfony/dependency-injection/ExpressionLanguageProvider.php',
'vendor/symfony/var-dumper/Caster/*',

other probably need re-sort the directories.

I will check more.

},

// get version for prefixed version
function (string $filePath, string $prefix, string $content): string {
if (! Strings::endsWith($filePath, 'src/Configuration/Configuration.php')) {
Expand Down Expand Up @@ -151,7 +173,7 @@ function (string $filePath, string $prefix, string $content): string {
},

function (string $filePath, string $prefix, string $content): string {
if (! Strings::endsWith($filePath, 'vendor/symplify/autowire-array-parameter/src/Skipper/ParameterSkipper.php')) {
if (! Strings::contains($filePath, 'vendor/')) {
return $content;
}

Expand Down
16 changes: 16 additions & 0 deletions utils/compiler/src/Command/DowngradePathsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,29 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$downgradePaths = array_merge([
// must be separated to cover container get() trait + psr container contract get()
'config',
'vendor/phpstan/phpdoc-parser/src',
'vendor/symfony/error-handler',
'vendor/symfony/dependency-injection',
'vendor/symfony/console',
'vendor/symfony vendor/psr',
'vendor/symplify vendor/nikic bin src packages rector.php',
'rules',
], $downgradePaths);

if (file_exists(getcwd() . '/vendor/phpstan/phpstan-extracted/vendor')) {
$downgradePaths[] = 'vendor/phpstan/phpstan-extracted/vendor';
$downgradePaths[] = 'vendor/phpstan/phpstan-extracted/src';
$downgradePaths[] = 'vendor/phpstan/phpstan-extracted/vendor/phpstan/phpdoc-parser/src';
$downgradePaths[] = 'vendor/phpstan/phpstan-extracted/vendor/ondrejmirtes/better-reflection/src';
$downgradePaths[] = 'vendor/phpstan/phpstan-extracted/vendor/nette/di/src';
$downgradePaths[] = 'vendor/phpstan/phpstan-extracted/vendor/nette/php-generator/src';
$downgradePaths[] = 'vendor/phpstan/phpstan-extracted/vendor/nette/utils/src';
$downgradePaths[] = 'vendor/phpstan/phpstan-extracted/vendor/nette/schema/src';
$downgradePaths[] = 'vendor/phpstan/phpstan-extracted/vendor/nette/finder/src';
$downgradePaths[] = 'vendor/phpstan/phpstan-extracted/vendor/nette/robot-loader/src';
$downgradePaths[] = 'vendor/phpstan/phpstan-extracted/vendor/ondram/ci-detector/src';
$downgradePaths[] = 'vendor/phpstan/phpstan-extracted/vendor/symfony/finder';
$downgradePaths[] = 'vendor/phpstan/phpstan-extracted/vendor/symfony/console';
}

// bash format
Expand Down