-
Notifications
You must be signed in to change notification settings - Fork 43
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 a PHPCompatibility ruleset to PHPCS #1651
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 17 error(s)
Temporary_PHPCompatibility_Test.php
Outdated
|
||
// Should tell me return void is not available in PHP 5.6 | ||
class Foo { | ||
public function do_nothing(): void { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 You must use "/**" style comments for a class comment
hash: 3fda944041338d326807f99503c2d731
Temporary_PHPCompatibility_Test.php
Outdated
// Should tell me return void is not available in PHP 5.6 | ||
class Foo { | ||
public function do_nothing(): void { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- 🚫 Missing doc comment for function do_nothing()
- 🚫 void return type is not present in PHP version 7.0 or earlier
hash: 3d3b3964061b197aba8324456a398b48
Temporary_PHPCompatibility_Test.php
Outdated
} | ||
|
||
// Should tell me anonymous class are not available in PHP 5.6 | ||
$a = new class {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 Inline comments must end in full-stops, exclamation marks, or question marks
hash: f0e90559592e54bbe82db68036616ab0
Temporary_PHPCompatibility_Test.php
Outdated
|
||
// Should tell me anonymous class are not available in PHP 5.6 | ||
$a = new class {} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- 🚫 Anonymous classes are not supported in PHP 5.6 or earlier
- 🚫 Parenthesis should always be used when instantiating a new object.
hash: 36fa514a1d31a8bbfe4ec88f51f1d1e9
Temporary_PHPCompatibility_Test.php
Outdated
$a = new class {} | ||
|
||
// Should tell me "create_function()" has been deprecated on PHP 7.2 | ||
create_function('', ''); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 Inline comments must end in full-stops, exclamation marks, or question marks
hash: 1b23e12727e46bff82706f1484d9b863
Temporary_PHPCompatibility_Test.php
Outdated
$a = new class {} | ||
|
||
// Should tell me "create_function()" has been deprecated on PHP 7.2 | ||
create_function('', ''); No newline at end of file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
⚠️ create_function() is highly discouraged, as it can execute arbritary code (additionally, it's deprecated as of PHP 7.2): https://wpvip.com/documentation/vip-go/code-review-blockers-warnings-notices/#eval-and-create_function. )⚠️ Function create_function() is deprecated since PHP 7.2; Use an anonymous function instead- 🚫 PHP syntax error: syntax error, unexpected 'create_function' (T_STRING)
- 🚫 create_function() is deprecated as of PHP 7.2, please use full fledged functions or anonymous functions instead.
- 🚫 Expected 1 spaces after opening parenthesis; 0 found
- 🚫 Expected 1 spaces before closing parenthesis; 0 found
- 🚫 Function create_function() has been deprecated
- 🚫 There must be a single space after the first parenthesis
- 🚫 There must be a single space before the last parenthesis
- 🚫 File must end with a newline character
hash: 5768da684300b0e405a37232e76f4b56
We might need to look into modifications to https://github.com/moderntribe/tribalscents as well. |
Hey Gustavo, what kind of modifications? Like, porting this to tribalscents? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's explore putting this into tribalscents so it can apply to multiple repos more easily.
@@ -10,6 +10,9 @@ | |||
</rule> | |||
<rule ref="TribalScents"/> | |||
|
|||
<rule ref="PHPCompatibility"/> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<rule ref="PHPCompatibility"/> | |
<rule ref="PHPCompatibilityWP"/> |
(Otherwise you still won't benefit from the PHPCompatibilityWP ruleset taking polyfilled PHP features in WP into account)
Actually, there are also things which static analysis just can't detect which aren't covered, but we try. |
Thanks a lot for dropping by, @jrfnl! I'm no longer involved in the development of this project. Best regards, |
This PR adds a PHPCompatibility ruleset to the existing PHPCS rules.
It is configured to check compatibility with PHP 5.6+.
For instance, if there's a:
public function foo(): void
in the code being checked by PHPCS, it will come back with:void return type is not present in PHP version 7.0 or earlier
It will also warn about deprecations. For instance, using
create_function()
gives me:create_function() is deprecated as of PHP 7.2, please use full fledged functions or anonymous functions instead.
The compatibility coverage is not 100%, but close to 95%. You can see the 5% it doesn't cover yet, here:
Please, do not merge yet, I'll push some commits to this PR to test that PHPCompatibility is working alright.Done.