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

Add polyfills for the PHP 7.0 TypeError and Error classes #36

Merged
merged 1 commit into from
Jun 16, 2021

Conversation

jrfnl
Copy link
Collaborator

@jrfnl jrfnl commented Jun 16, 2021

Some of the existing code already references these classes and while not (currently) done in a PHP cross-version problematic way, it is still better to make sure these classes exist for optimal PHP cross-version compatibility.

While not strictly correct/PSR4-compliant, I've elected to put these classes in the Exceptions subfolder, even though these are non-namespaced classes and not strictly part of the PHPUnit polyfills.

Note: the autoloader will only be called if these classes do not exist in PHP itself (PHP < 7.0), so the way it is set up now, these files will never get loaded on PHP >= 7.0 (which would otherwise cause a "Class already declared" error).

Includes:

  • Explicitly excluding the PHPCompatibility notices about these classes in the PHPCS ruleset.
    Note: due to the use of the PHPCompatibilityWP ruleset in YoastCS, these notices weren't showing anyway as WP backfills these classes. All the same, making it explicit in the ruleset documents the polyfills as now included in this repo.
  • Adjustments to the Composer scripts to run the PHP linting and the GH Actions workflow which runs it.
    On PHP 7.x, these polyfills would cause a Cannot declare class Error, because the name is already in use in ... error otherwise.

Some of the existing code already references these classes and while not (currently) done in a PHP cross-version problematic way, it is still better to make sure these classes exist for optimal PHP cross-version compatibility.

While not strictly correct/PSR4-compliant, I've elected to put these classes in the `Exceptions` subfolder, even though these are non-namespaced classes and not strictly part of the _PHPUnit_ polyfills.

Note: the autoloader will only be called if these classes do not exist in PHP itself (PHP < 7.0), so the way it is set up now, these files will never get loaded on PHP >= 7.0 (which would otherwise cause a "Class already declared" error).

Includes:
* Explicitly excluding the PHPCompatibility notices about these classes in the PHPCS ruleset.
    _Note: due to the use of the PHPCompatibilityWP ruleset in YoastCS, these notices weren't showing anyway as WP backfills these classes. All the same, making it explicit in the ruleset documents the polyfills as now included in this repo._
* Adjustments to the Composer scripts to run the PHP linting and the GH Actions workflow which runs it.
    On PHP 7.x, these polyfills would cause a `Cannot declare class Error, because the name is already in use in ...` error otherwise.
@jrfnl jrfnl force-pushed the feature/add-error-typeerror-polyfills branch from 07ffba9 to 86abfb9 Compare June 16, 2021 13:31
@jrfnl jrfnl merged commit 985d7a8 into develop Jun 16, 2021
@jrfnl jrfnl deleted the feature/add-error-typeerror-polyfills branch June 16, 2021 13:39
jrfnl added a commit that referenced this pull request Jun 16, 2021
When adding the `TypeError`/`Error` polyfill (#36), I suddenly realized that the use of the `PHPCompatibilityWP` ruleset by the `Yoast` standard was causing certain issues not to show up, while - for this repo - they **_should_** be shown.

By setting the `severity` of all the sniffs in the `PHPCompatibilility` ruleset back to `5`, the `exclude`s from the `PHPCompatibilityWP` ruleset are effectively "undone" and we are back to using `PHPCompatibility` proper.
@jrfnl jrfnl removed the yoastcs/qa label Oct 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant