Closed TomasVotruba closed 3 years ago
@samsonasik Could you complete list with most wide-spread features in PHP world? Feel free to also to start with adding those rules.
I will try
✔️ Remove void type seems implemented at https://github.com/rectorphp/rector/blob/main/rules/DowngradePhp71/Rector/FunctionLike/DowngradeVoidTypeDeclarationRector.php
✔️ Remove scalar type declarations seems implemented at https://github.com/rectorphp/rector/blob/main/rules/DowngradePhp70/Rector/FunctionLike/DowngradeTypeDeclarationRector.php
@samsonasik Could you update the issue description with links to these rules? So we have it one place
@TomasVotruba updated.
@TomasVotruba for Remove anonymous classes, do you think it need to create a new dedicated class and create the instance of it before remove the anonymous class?
I think so :+1:
From PHP 7.1 to PHP 7.0 - remove nullable types
@lulco that already in DowngradeNullableTypeDeclarationRector https://github.com/rectorphp/rector/blob/main/rules/DowngradePhp71/Rector/FunctionLike/DowngradeNullableTypeDeclarationRector.php
I will update the list.
@lulco list updated.
There was a tool that downgraded most common features of PHP 7 to PHP 5 - https://github.com/spatie/7to5 for inspiration. :tada: It also has implemented NodeVisitors - https://github.com/spatie/7to5/tree/master/src/NodeVisitors
@TomasVotruba scoped to 7.0 process got error on adding phpstan-src
composer require phpstan/phpstan-src --ignore-platform-reqs
Using version ^0.12.85 for phpstan/phpstan-src
./composer.json has been updated
PHP Fatal error: Cannot declare class RectorPrefix20210505\Composer\InstalledVersions, because the name is already in use in /home/runner/work/rector/rector/remote-repository-php70/vendor/composer/InstalledVersions.php on line 7
Fatal error: Cannot declare class RectorPrefix20210505\Composer\InstalledVersions, because the name is already in use in /home/runner/work/rector/rector/remote-repository-php70/vendor/composer/InstalledVersions.php on line 7
Error: Process completed with exit code 255.
ref https://github.com/rectorphp/rector/runs/2506182264?check_suite_focus=true#step:19:9
Do you have idea how to solve it?
I think you can avoid scoping InstalledVersions.php
without any harm, and avoiding this issue.
@leoloso ok, let's try on https://github.com/rectorphp/rector/pull/6335, thank you.
@leoloso it seems still same error https://github.com/rectorphp/rector/runs/2507401040#step:19:10 , while it actually already changed in vendor/composer/package-versions-deprecated/src/PackageVersions/Versions.php
:
But you're handling it through a patcher, which operates after doing the scoping. I was suggesting to completely skip scoping that file.
That's what I did my project when I had the same issue as you have now, and now it works well (source):
'files-whitelist' => [
convertRelativeToFullPath('vendor/composer/InstalledVersions.php'),
],
@leoloso thank you. @TomasVotruba the phpstan-src versioning php requirement seems different with phpstan's. It can't be solved with ignore platform reqs as it has different packages requirement, do you have idea how to solve it? Thank you.
The phpstan-src must be downgraded to PHP 7.1
Yes, but getting phpstan-src from php 7.3 is not possible, even with ignore platform reqs due different packages requirements, ref:
Do we need php 7.4 ?
Do we need php 7.4 ?
I think so :+1: the version Rector runs downgrade in is not really relevant. It can be PHP 8 too
@TomasVotruba the phpstan-src is now included, but on downgrading process, it got error:
Run sh build/downgrade-rector-php70.sh rector-build-php70
[NOTE] Running downgrade in 'rector-build-php70' directory
PHP Fatal error: Uncaught Nette\MemberAccessException: Cannot read an undeclared property PHPStan\DependencyInjection\Configurator::$parameters. in /home/runner/work/rector/rector/vendor/nette/utils/src/Utils/ObjectHelpers.php:31
Stack trace:
#0 /home/runner/work/rector/rector/vendor/nette/utils/src/SmartObject.php(76): Nette\Utils\ObjectHelpers::strictGet()
#1 /home/runner/work/rector/rector/vendor/phpstan/phpstan-src/src/DependencyInjection/Configurator.php(42): Nette\Bootstrap\Configurator->__get()
#2 /home/runner/work/rector/rector/vendor/nette/bootstrap/src/Bootstrap/Configurator.php(252): PHPStan\DependencyInjection\Configurator->loadContainer()
#3 /home/runner/work/rector/rector/vendor/phpstan/phpstan-src/src/DependencyInjection/ContainerFactory.php(102): Nette\Bootstrap\Configurator->createContainer()
#4 /home/runner/work/rector/rector/packages/NodeTypeResolver/DependencyInjection/PHPStanServicesFactory.php(43): PHPStan\DependencyInjection\ContainerFactory->create()
#5 /tmp/rector/cache/Container7O4zmPC/HttpKernelRect in /home/runner/work/rector/rector/vendor/nette/utils/src/Utils/ObjectHelpers.php on line 31
Fatal error: Uncaught Nette\MemberAccessException: Cannot read an undeclared property PHPStan\DependencyInjection\Configurator::$parameters. in /home/runner/work/rector/rector/vendor/nette/utils/src/Utils/ObjectHelpers.php:31
Stack trace:
#0 /home/runner/work/rector/rector/vendor/nette/utils/src/SmartObject.php(76): Nette\Utils\ObjectHelpers::strictGet()
#1 /home/runner/work/rector/rector/vendor/phpstan/phpstan-src/src/DependencyInjection/Configurator.php(42): Nette\Bootstrap\Configurator->__get()
#2 /home/runner/work/rector/rector/vendor/nette/bootstrap/src/Bootstrap/Configurator.php(252): PHPStan\DependencyInjection\Configurator->loadContainer()
#3 /home/runner/work/rector/rector/vendor/phpstan/phpstan-src/src/DependencyInjection/ContainerFactory.php(102): Nette\Bootstrap\Configurator->createContainer()
#4 /home/runner/work/rector/rector/packages/NodeTypeResolver/DependencyInjection/PHPStanServicesFactory.php(43): PHPStan\DependencyInjection\ContainerFactory->create()
#5 /tmp/rector/cache/Container7O4zmPC/HttpKernelRect in /home/runner/work/rector/rector/vendor/nette/utils/src/Utils/ObjectHelpers.php on line 31
Error: Process completed with exit code 255.
in https://github.com/rectorphp/rector/runs/2511018616#step:7:8 .
It seems some code are different between in phpstan/phpstan
and phpstan/phpstan-src
, another example is current error:
PHP Fatal error: Interface 'PHPStan\BetterReflection\SourceLocator\Type\SourceLocator' not found
in https://github.com/rectorphp/rector-prefixed-php70/runs/2500555629#step:4:4 which not exists in https://github.com/phpstan/phpstan-src
Btw, just a tip. Instead of pushing to main
and waiting for CI, you can use local script to get feedback much faster.
I did the same for building rector-prefixed in full_build.sh
It might be easier to downgrade phpstan/phpstan-src first as standalone project. And when that is ok add it to Rector.
Scoping PHPStan has own scoper.php
that might be needed 1:1 https://github.com/phpstan/phpstan-src/blob/master/compiler/build/scoper.inc.php
@TomasVotruba thank you, I may need to create full_build_php70.sh
then for excluding the dependencies that cause conflicts, ref:
That removal need to be executing first as composer/xdebug-handler
and phpstan/phpstan
are in require
.
I will check the phpstan's scoper.inc.php if that works to scope phpstan-src first.
We've just launched Sponsorware initiative to make this happen with your help :muscle:
Untill the sponsorware treshold #1 is met, this issue is not a priority. Closing to keep focus on active ones.
After Rector 0.10 with PHP 7.1 downgraded code, we want to go even deeper. Next stop is PHP 5.6, as that's where most legacy projects are stuck. Right before the huge wall of PHP 7.0 :)
This is meta issue to reference downgrade rules. To kick of with few.
From PHP 7.1 to PHP 7.0 -
RFC links: https://wiki.php.net/rfc#php_71
void
type - https://wiki.php.net/rfc/void_return_type ( https://github.com/rectorphp/rector/blob/main/rules/DowngradePhp71/Rector/FunctionLike/DowngradeVoidTypeDeclarationRector.php )From PHP 7.0 to PHP 5.6
RFC link: https://wiki.php.net/rfc#php_70