Closed brettshumaker closed 5 years ago
Relevant parts of ruleset:
That last ones shows that WordPress-VIP-Go
turns off the check for add_user_meta()
, so no mystery there.
Did some more testing and adding --warning-severity=1
to my phpcs
command brings back the expected warnings. I'm not sure why the --severity=1
flag isn't applying to warnings, because it should be according to the docs.
phpcs * --standard=WordPress-VIP-Go -s -d --severity=1 --warning-severity=1
FILE: /Users/brettshumaker/Developer/phpcstesting/phpcstesting.php
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
FOUND 2 ERRORS AND 3 WARNINGS AFFECTING 3 LINES
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
7 | WARNING | Not using strict comparison for in_array; supply true for third argument. (WordPress.PHP.StrictInArray.MissingTrueStrict)
7 | WARNING | Variable $x is undefined. (WordPressVIPMinimum.Variables.VariableAnalysis.UndefinedVariable)
7 | WARNING | Found: ==. Use strict comparisons (=== or !==). (WordPress.PHP.StrictComparisons.LooseComparison)
15 | ERROR | %s() is uncached. If this is being used to query a remote file please use wpcom_vip_file_get_contents() instead. If it's used for a local file please use WP_Filesystem
| | instead. Read more here: https://vip.wordpress.com/documentation/using-wp_filesystem-instead-of-direct-file-access-functions/
| | (WordPressVIPMinimum.VIP.FetchingRemoteData.fileGetContentsUknown)
16 | ERROR | File operations should use WP_Filesystem methods instead of direct PHP filesystem calls. Found: fopen(). Read more here:
| | https://vip.wordpress.com/documentation/using-wp_filesystem-instead-of-direct-file-access-functions/ (WordPress.WP.AlternativeFunctions.file_system_read_fopen)
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Time: 60ms; Memory: 6Mb
phpcs * --standard=WordPressVIPMinimum -s -d --severity=1 --warning-severity=1
FILE: /Users/brettshumaker/Developer/phpcstesting/phpcstesting.php
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
FOUND 1 ERROR AND 5 WARNINGS AFFECTING 4 LINES
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
7 | WARNING | Not using strict comparison for in_array; supply true for third argument. (WordPress.PHP.StrictInArray.MissingTrueStrict)
7 | WARNING | Variable $x is undefined. (WordPressVIPMinimum.Variables.VariableAnalysis.UndefinedVariable)
7 | WARNING | Found: ==. Use strict comparisons (=== or !==). (WordPress.PHP.StrictComparisons.LooseComparison)
13 | ERROR | add_user_meta() usage is highly discouraged on WordPress.com VIP due to it being a multisite, please see
| | https://lobby.vip.wordpress.com/wordpress-com-documentation/code-review-what-we-look-for/#wp_users-and-user_meta.
| | (WordPressVIPMinimum.VIP.RestrictedFunctions.user_meta_add_user_meta)
15 | WARNING | `file_get_contents()` is highly discouraged for remote requests, please use `wpcom_vip_file_get_contents()` or `vip_safe_wp_remote_get()` instead.
| | (WordPressVIPMinimum.VIP.FetchingRemoteData.fileGetContentsUknown)
16 | WARNING | File operations should use WP_Filesystem methods instead of direct PHP filesystem calls. Found: fopen() (WordPress.WP.AlternativeFunctions.file_system_read_fopen)
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Time: 54ms; Memory: 6Mb
I'm not sure why the
--severity=1
flag isn't applying to warnings, because it should be according to the docs.
Worth raising that on the PHPCS repo, even if only to get clarification on the intended usage.
Closing this out. I was doing something silly. I had seen the -d
flag used in an example in slack and I didn’t understand its usage. -d
is used to set php.ini
values and since I was putting --severity=1
after -d
it was trying to set severity
in php.ini
and wasn’t seeing it as a phpcs flag.
The following command works as expected:
phpcs /path/to/code --standard=WordPress-VIP-Go -s --severity=1
Bug Description
When running
phpcs * --standard=WordPress-VIP-Go -s -d --severity=1
against the code snippet below, I'd expect to see a warning triggered forWordPress.PHP.StrictComparisons.LooseComparison
(among others) but it is not present. If I runphpcs * --standard=WordPressVIPMinimum -s -d --severity=1
, however, I do see the warning.Minimal Code Snippet
Error Code
Environment
Use
php -v
andcomposer show
to get versions.master
branchAdditional Context (optional)
My installed standards
Tested Against
master
branch?master
branch of VIPCS.*Edited to update incorrect line numbers