Skip to content

Commit d846b56

Browse files
authored
Merge branch 'master' into fix/phpcs-violations-in-vipcs
2 parents c08fc69 + 395c4de commit d846b56

File tree

3 files changed

+21
-10
lines changed

3 files changed

+21
-10
lines changed

README.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,28 @@ The ruleset takes advantage of existing rules in the [WordPress-Coding-Standards
1313

1414
Go to https://vip.wordpress.com/documentation/phpcs-review-feedback/ to learn about why various things are flagged as errors vs warnings and what the levels mean for us.
1515

16-
# Installation
16+
## Installation
1717

1818

19-
First, make sure you have WPCS v1+ and PHPCS v3+ installed. If you do not, please refer to the [installation instructions for installing PHP CodeSniffer for WordPress.com VIP](https://vip.wordpress.com/documentation/how-to-install-php-code-sniffer-for-wordpress-com-vip/)
19+
First, make sure you have WPCS 1.* and PHPCS v3+ installed. If you do not, please refer to the [installation instructions for installing PHP CodeSniffer for WordPress.com VIP](https://vip.wordpress.com/documentation/how-to-install-php-code-sniffer-for-wordpress-com-vip/). Note that VIPCS does not currently work with the `develop` branch of WPCS.
2020

2121
You will also find additional information at the [WordPress Coding Standards for PHP_CodeSniffer project](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards#installation).
2222

2323
Then, clone this repo to your local machine, and add the standard to PHPCodeSniffer by appending the folder you cloned into to the end of the installed paths. e.g.
2424

2525
`phpcs --config-set installed_paths [/path/to/wpcsstandard],[path/to/vipcsstandard],etc`
2626

27-
## Minimal requirements
27+
Alternatively, we recommend the [PHP_CodeSniffer Standards Composer Installer Plugin](https://github.com/Dealerdirect/phpcodesniffer-composer-installer), which handles the registration of all of the installed standards, so there is no need to set the `installed_paths` config value manually, for single or multiple standards.
2828

29-
* [PHPCS v3](https://github.com/squizlabs/PHP_CodeSniffer/releases/tag/3.3.0)
30-
* [WPCS v1.0.0](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/releases/tag/1.0.0)
29+
### Minimal requirements
3130

32-
# Setup note
31+
* [PHPCS 3+](https://github.com/squizlabs/PHP_CodeSniffer/releases)
32+
* [WPCS 1.*](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/releases)
33+
34+
### Setup note
3335

3436
Should you wish to run both standards (WordPress.com VIP minimum standard & WordPress.com VIP coding standard), you can add both to PHPCS by running the following configuration command:
3537

3638
`phpcs --config-set installed_paths [/path/to/standard],[path/to/standard]`
3739

38-
(note the comma separating each standard)
40+
Note the comma separating each standard.

WordPress-VIP-Go/ruleset.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@
5050
<rule ref="WordPressVIPMinimum.VIP.FetchingRemoteData.fileGetContentsUknown">
5151
<type>error</type>
5252
<Severity>5</Severity>
53-
<message>%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/</message>
5453
</rule>
5554
<rule ref="WordPress.WP.AlternativeFunctions.file_system_read_fopen">
5655
<type>error</type>

WordPressVIPMinimum/Sniffs/VIP/FetchingRemoteDataSniff.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,24 @@ public function process( File $phpcsFile, $stackPtr ) {
4747

4848
$fileNameStackPtr = $phpcsFile->findNext( Tokens::$stringTokens, ( $stackPtr + 1 ), null, false, null, true );
4949
if ( false === $fileNameStackPtr ) {
50-
$phpcsFile->addWarning( sprintf( '`%s()` is highly discouraged for remote requests, please use `wpcom_vip_file_get_contents()` or `vip_safe_wp_remote_get()` instead.', $tokens[ $stackPtr ]['content'] ), $stackPtr, 'fileGetContentsUknown' );
50+
$phpcsFile->addWarning(
51+
'`%s()` is highly discouraged for remote requests, please use `wpcom_vip_file_get_contents()` or `vip_safe_wp_remote_get()` instead. If it\'s for a local file please use WP_Filesystem instead.',
52+
$stackPtr,
53+
'fileGetContentsUknown',
54+
[ $tokens[ $stackPtr ]['content'] ]
55+
);
5156
}
5257

5358
$fileName = $tokens[ $fileNameStackPtr ]['content'];
5459

5560
$isRemoteFile = ( false !== strpos( $fileName, '://' ) );
5661
if ( true === $isRemoteFile ) {
57-
$phpcsFile->addWarning( sprintf( '`%s()` is highly discouraged for remote requests, please use `wpcom_vip_file_get_contents()` or `vip_safe_wp_remote_get()` instead.', $tokens[ $stackPtr ]['content'] ), $stackPtr, 'fileGetContentsRemoteFile' );
62+
$phpcsFile->addWarning(
63+
'`%s()` is highly discouraged for remote requests, please use `wpcom_vip_file_get_contents()` or `vip_safe_wp_remote_get()` instead.',
64+
$stackPtr,
65+
'fileGetContentsRemoteFile',
66+
[ $tokens[ $stackPtr ]['content'] ]
67+
);
5868
}
5969
}
6070

0 commit comments

Comments
 (0)