Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Write cutting edge code and release it to legacy platforms #319

Open
szepeviktor opened this issue Feb 7, 2021 · 14 comments
Open

Write cutting edge code and release it to legacy platforms #319

szepeviktor opened this issue Feb 7, 2021 · 14 comments
Labels

Comments

@szepeviktor
Copy link
Contributor

Problem

We want to write PHP 7.4/8.0 code but users run PHP 5.6

Solution

Use Rector in the release process!

Alternatives you've considered

Sleep.

@jakubmikita
Copy link
Member

Hmm, do you know any WP plugin which is using this?

It looks interesting!

@szepeviktor
Copy link
Contributor Author

I'm not in the WordPress business, just playing with PHP technologies.
Do you think it will somehow fail?

@szepeviktor
Copy link
Contributor Author

szepeviktor commented Feb 7, 2021

https://github.com/rectorphp/rector/issues?q=WordPress 🖱️

<?php

use Rector\Core\Configuration\Option;
use Rector\Set\ValueObject\SetList;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

return static function (ContainerConfigurator $containerConfigurator): void {
    $parameters = $containerConfigurator->parameters();
    $parameters->set(Option::SETS, [
        SetList::DOWNGRADE_PHP74,
        SetList::DOWNGRADE_PHP73,
        SetList::DOWNGRADE_PHP72,
        SetList::DOWNGRADE_PHP71,
        SetList::DOWNGRADE_PHP70,
        SetList::DOWNGRADE_PHP56,
    ]);
};

@jakubmikita
Copy link
Member

WordPress is very specific and bloated, looking at all the problems with ie with PHPUnit I wouldn't be surprised if it fail miserably. I will take a closer look at this package and its usage with WP though

@szepeviktor
Copy link
Contributor Author

szepeviktor commented Feb 7, 2021

You can audit the changes.
Tests must be written for PHPUnit running on PHP 5.6. -> https://github.com/rectorphp/rector/blob/master/packages/set/src/ValueObject/SetList.php#L399-L467

@szepeviktor
Copy link
Contributor Author

Hmm, do you know any WP plugin which is using this?

Found one: https://github.com/leoloso/PoP/blob/master/rector-downgrade-code.php

@szepeviktor
Copy link
Contributor Author

@mircobabini
Copy link
Contributor

Hmm, do you know any WP plugin which is using this?

Found one: https://github.com/leoloso/PoP/blob/master/rector-downgrade-code.php
Another one: https://github.com/szepeviktor/phpstan-higher-order-collections/blob/master/rector.php

These are not Wordpress plugins.

Also, seems like support of autoload and includes (WordPress beloved stuffs) is still a work in progress rectorphp/rector#4330.

@szepeviktor
Copy link
Contributor Author

szepeviktor commented Feb 17, 2021

I think using Composer autoloader (not the tool!) in a WordPress plugin is okay. Please see Yoast SEO for example.
So Rector won't have to rectify that. Composer autoloader is PHP 5.3+ compatible.

@szepeviktor
Copy link
Contributor Author

This is how I try to break away from WordPress legacy technologies.
Theory https://github.com/szepeviktor/small-project/blob/master/MAIN-FILE-PARTS.md
In practice meilisearch/meilisearch-wordpress#20

@jakubmikita
Copy link
Member

We're good with Composer itself because all its loaders are backward compatible. There are problems with a few things:

  • packages are not backward compatible with whatever PHP version we are using (e.g. plugin supports PHP 5.6 but the package we are requiring needs 7.1) - this is where Rector can help
  • other plugins are loading the same packages but in different versions - this is where PHP Scoper or Imposter we are using can help by prefixing the namespaces

I'm looking into using the Rector within this project and I'd like to find out if all the packages processed by Imposter can be rectified to older PHP versions.

@szepeviktor
Copy link
Contributor Author

Highly interesting topic 👀

Time traveling 101!

@szepeviktor
Copy link
Contributor Author

Public testing with Rectorizer 🤖
https://github.com/szepeviktor/rectorize/actions/runs/588606017

@jakubmikita
Copy link
Member

Wow, this truly seems to work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants