pressbooks / pressbooks

Open publishing. Open web. Open source.
https://pressbooks.org/
GNU General Public License v3.0
420 stars 133 forks source link

Fix code to be PHP 8 compatible #2636

Closed arzola closed 2 years ago

arzola commented 2 years ago

Four errors in current CI tests matrix when running against PHP8:

Example:

1) SamesiteTest::test_login
PHPUnit\Framework\Exception: PHP Deprecated:  Required parameter $object_type follows optional parameter $group_slug in /home/runner/work/pressbooks-lti-provider-1p3/pressbooks/symbionts/custom-metadata/custom_metadata.php on line 772
PHP Warning:  The magic method Pressbooks\Book::__wakeup() must have public visibility in /home/runner/work/pressbooks-lti-provider-1p3/pressbooks/inc/class-book.php on line 62
dac514 commented 2 years ago

The complaint is from a file in Pressbooks, not this plugin.

https://github.com/pressbooks/pressbooks/blob/dev/symbionts/custom-metadata/custom_metadata.php#L772

It doesn't like the order of params

function is_registered_field( $field_slug, $group_slug = '', $object_type ) {

Optional params ($group_slug = '') must come last.

dac514 commented 2 years ago

The fix is probably removing the = '' part. Cursory glance I don't see how is_registered_field can work with less than all 3 params.

beckej13820 commented 2 years ago

I didn't know that PHP 8 wasn't supported in Pressbooks.

There is another error with PHP 8 compatibility. The import of documents often (but not always) has an event stream error with the progress slidebar.

dac514 commented 2 years ago

I upgraded a legacy projet with Rector recently. (because my wife's blog still runs on one of my old projects):

This was the config I used:

return static function (RectorConfig $rectorConfig): void {
    $rectorConfig->paths([
        __DIR__ . '/sux0r2',
    ]);

    // Directories to skip, rules I don't agree with...
    $rectorConfig->skip([
        __DIR__ . '/sux0r2/includes/symbionts',
        __DIR__ . '/sux0r2/data',
        __DIR__ . '/sux0r2/temporary',
        \Rector\Php80\Rector\FunctionLike\UnionTypesRector::class,
        \Rector\Php81\Rector\FunctionLike\IntersectionTypesRector::class,
        \Rector\RemovingStatic\Rector\ClassMethod\LocallyCalledStaticMethodToNonStaticRector::class,
        \Rector\Transform\Rector\StaticCall\StaticCallToNewRector::class,
    ]);

    // define sets of rules
    $rectorConfig->sets([
        LevelSetList::UP_TO_PHP_81
    ]);
};

More info about Rector: https://getrector.org/