Skip to content

PHP 5.3: New PHPCompatibility.Namespaces.ReservedNames sniff#1026

Merged
wimg merged 1 commit intodevelopfrom
feature/1025-new-namespace-reserved-name-sniff
May 5, 2020
Merged

PHP 5.3: New PHPCompatibility.Namespaces.ReservedNames sniff#1026
wimg merged 1 commit intodevelopfrom
feature/1025-new-namespace-reserved-name-sniff

Conversation

@jrfnl
Copy link
Member

@jrfnl jrfnl commented Apr 29, 2020

The Namespace name PHP, and compound names starting with this name (like PHP\Classes) are reserved for internal language use and should not be used in the userspace code.

Source: https://www.php.net/manual/en/language.namespaces.rationale.php

This PR introduces a new PHPCompatibility.Namespaces.ReservedNames sniff to detect use of namespace names reserved by PHP, in userland code.

The sniff will throw a warning when a reserved namespace name is detected.

This sniff is along the same lines as the PHPCompatibility.FunctionNameRestrictions.ReservedFunctionNames sniff which does the same for reserved function names to prevent code being introduced in userland code which has a high risk of being incompatible with future PHP versions.

Includes unit tests.

Fixes #1025

@jrfnl
Copy link
Member Author

jrfnl commented Apr 29, 2020

Hmm... looks like something weird is going on as Travis doesn't seem to be reporting on the PR (though the build does pass: https://travis-ci.org/github/PHPCompatibility/PHPCompatibility/builds/681042349).

@jrfnl jrfnl force-pushed the feature/1025-new-namespace-reserved-name-sniff branch from 0fa6c63 to 818b96b Compare April 30, 2020 13:33
@jrfnl jrfnl changed the title New PHPCompatibility.Namespaces.ReservedNames sniff PHP 5.3: New PHPCompatibility.Namespaces.ReservedNames sniff May 2, 2020
> The Namespace name PHP, and compound names starting with this name (like PHP\Classes) are reserved for internal language use and should not be used in the userspace code.

Source: https://www.php.net/manual/en/language.namespaces.rationale.php

This PR introduces a new `PHPCompatibility.Namespaces.ReservedNames` sniff to detect use of namespace names reserved by PHP, in userland code.

The sniff will throw a `warning` when a reserved namespace name is detected.

This sniff is along the same lines as the `PHPCompatibility.FunctionNameRestrictions.ReservedFunctionNames` sniff which does the same for reserved function names to prevent code being introduced in userland code which has a high risk of being incompatible with future PHP versions.

Includes unit tests.

Fixes 1025
@jrfnl jrfnl force-pushed the feature/1025-new-namespace-reserved-name-sniff branch from 818b96b to c332efb Compare May 2, 2020 17:07
@wimg wimg merged commit 6b0c6dc into develop May 5, 2020
@wimg wimg deleted the feature/1025-new-namespace-reserved-name-sniff branch May 5, 2020 12:10
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.

New sniff: warn on use of PHP as top-level namespace

2 participants