Skip to content

Commit bd9c331

Browse files
authored
Merge pull request #1709 from WordPress-Coding-Standards/develop
Release version 2.1.1
2 parents 8c7a2e7 + 97d6fbf commit bd9c331

14 files changed

+123
-26
lines changed

CHANGELOG.md

+22
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,27 @@ This projects adheres to [Semantic Versioning](https://semver.org/) and [Keep a
88

99
_No documentation available about unreleased changes as of yet._
1010

11+
12+
## [2.1.1] - 2019-05-21
13+
14+
### Changed
15+
- The `WordPress.WP.CapitalPDangit` will now ignore misspelled instances of `WordPress` within constant declarations.
16+
This covers both constants declared using `defined()` as well as constants declared using the `const` keyword.
17+
- The default value for `minimum_supported_wp_version`, as used by a [number of sniffs detecting usage of deprecated WP features](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki/Customizable-sniff-properties#minimum-wp-version-to-check-for-usage-of-deprecated-functions-classes-and-function-parameters), has been updated to `4.9`.
18+
19+
### Removed
20+
- `paginate_comments_links()` from the list of auto-escaped functions `Sniff::$autoEscapedFunctions`.
21+
This affects the `WordPress.Security.EscapeOutput` sniff.
22+
23+
### Fixed
24+
- The `$current_blog` and `$tag_ID` variables have been added to the list of WordPress global variables.
25+
This fixes some false positives from the `WordPress.NamingConventions.PrefixAllGlobals` and the `WordPress.WP.GlobalVariablesOverride` sniffs.
26+
- The generic `TestCase` class name has been added to the `$test_class_whitelist`.
27+
This fixes some false positives from the `WordPress.NamingConventions.FileName`, `WordPress.NamingConventions.PrefixAllGlobals` and the `WordPress.WP.GlobalVariablesOverride` sniffs.
28+
- The `WordPress.NamingConventions.ValidVariableName` sniff will now correctly recognize `$tag_ID` as a WordPress native, mixed-case variable.
29+
- The `WordPress.Security.NonceVerification` sniff will now correctly recognize nonce verification within a nested closure or anonymous class.
30+
31+
1132
## [2.1.0] - 2019-04-08
1233

1334
### Added
@@ -1070,6 +1091,7 @@ See the comparison for full list.
10701091
Initial tagged release.
10711092

10721093
[Unreleased]: https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/compare/master...HEAD
1094+
[2.1.1]: https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/compare/2.1.0...2.1.1
10731095
[2.1.0]: https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/compare/2.0.0...2.1.0
10741096
[2.0.0]: https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/compare/2.0.0-RC1...2.0.0
10751097
[2.0.0-RC1]: https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/compare/1.2.1...2.0.0-RC1

WordPress/Sniff.php

+14-9
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ abstract class Sniff implements PHPCS_Sniff {
8282
*
8383
* @var string WordPress version.
8484
*/
85-
public $minimum_supported_version = '4.8';
85+
public $minimum_supported_version = '4.9';
8686

8787
/**
8888
* Custom list of classes which test classes can extend.
@@ -202,7 +202,6 @@ abstract class Sniff implements PHPCS_Sniff {
202202
'get_the_ID' => true,
203203
'get_the_post_thumbnail' => true,
204204
'get_the_term_list' => true,
205-
'paginate_comments_links' => true,
206205
'post_type_archive_title' => true,
207206
'readonly' => true,
208207
'selected' => true,
@@ -638,6 +637,7 @@ abstract class Sniff implements PHPCS_Sniff {
638637
'compress_css' => true,
639638
'compress_scripts' => true,
640639
'concatenate_scripts' => true,
640+
'current_blog' => true,
641641
'current_screen' => true,
642642
'current_site' => true,
643643
'current_user' => true,
@@ -740,6 +740,7 @@ abstract class Sniff implements PHPCS_Sniff {
740740
'table_prefix' => true,
741741
'tabs' => true,
742742
'tag' => true,
743+
'tag_ID' => true,
743744
'targets' => true,
744745
'tax' => true,
745746
'taxnow' => true,
@@ -860,6 +861,8 @@ abstract class Sniff implements PHPCS_Sniff {
860861
'WP_XMLRPC_UnitTestCase' => true,
861862
'PHPUnit_Framework_TestCase' => true,
862863
'PHPUnit\Framework\TestCase' => true,
864+
// PHPUnit native TestCase class when imported via use statement.
865+
'TestCase' => true,
863866
);
864867

865868
/**
@@ -1440,13 +1443,15 @@ protected function has_nonce_check( $stackPtr ) {
14401443
$tokens = $this->phpcsFile->getTokens();
14411444

14421445
// If we're in a function, only look inside of it.
1443-
$f = $this->phpcsFile->getCondition( $stackPtr, \T_FUNCTION );
1444-
if ( false !== $f ) {
1445-
$start = $tokens[ $f ]['scope_opener'];
1446-
} else {
1447-
$f = $this->phpcsFile->getCondition( $stackPtr, \T_CLOSURE );
1448-
if ( false !== $f ) {
1449-
$start = $tokens[ $f ]['scope_opener'];
1446+
// Once PHPCS 3.5.0 comes out this should be changed to the new Conditions::GetLastCondition() method.
1447+
if ( isset( $tokens[ $stackPtr ]['conditions'] ) === true ) {
1448+
$conditions = $tokens[ $stackPtr ]['conditions'];
1449+
$conditions = array_reverse( $conditions, true );
1450+
foreach ( $conditions as $tokenPtr => $condition ) {
1451+
if ( \T_FUNCTION === $condition || \T_CLOSURE === $condition ) {
1452+
$start = $tokens[ $tokenPtr ]['scope_opener'];
1453+
break;
1454+
}
14501455
}
14511456
}
14521457

WordPress/Sniffs/NamingConventions/ValidVariableNameSniff.php

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class ValidVariableNameSniff extends PHPCS_AbstractVariableSniff {
5050
'is_winIE' => true,
5151
'PHP_SELF' => true,
5252
'post_ID' => true,
53+
'tag_ID' => true,
5354
'user_ID' => true,
5455
);
5556

WordPress/Sniffs/WP/CapitalPDangitSniff.php

+18
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,24 @@ public function process_token( $stackPtr ) {
188188
}
189189
}
190190

191+
// Ignore constant declarations via define().
192+
if ( $this->is_in_function_call( $stackPtr, array( 'define' => true ), true, true ) ) {
193+
return;
194+
}
195+
196+
// Ignore constant declarations using the const keyword.
197+
$stop_points = array(
198+
\T_CONST,
199+
\T_SEMICOLON,
200+
\T_OPEN_TAG,
201+
\T_CLOSE_TAG,
202+
\T_OPEN_CURLY_BRACKET,
203+
);
204+
$maybe_const = $this->phpcsFile->findPrevious( $stop_points, ( $stackPtr - 1 ) );
205+
if ( false !== $maybe_const && \T_CONST === $this->tokens[ $maybe_const ]['code'] ) {
206+
return;
207+
}
208+
191209
$content = $this->tokens[ $stackPtr ]['content'];
192210

193211
if ( preg_match_all( self::WP_REGEX, $content, $matches, ( \PREG_PATTERN_ORDER | \PREG_OFFSET_CAPTURE ) ) > 0 ) {

WordPress/Tests/Files/FileNameUnitTests/TestFiles/test-sample-namespaced-extends.4.inc

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
phpcs:set WordPress.Files.FileName custom_test_class_whitelist[] Some\Name\TestSample
33
<?php
44

5-
class TestCase extends TestSample {}
5+
class MyUnitTest extends TestSample {}
66
/* phpcs:set WordPress.Files.FileName custom_test_class_whitelist[] */

WordPress/Tests/Security/NonceVerificationUnitTest.inc

+27-1
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ function allow_for_array_comparison_in_condition() {
247247
}
248248
}
249249

250-
# Issue #572.
250+
// Issue #572.
251251
function allow_for_unslash_before_noncecheck_but_demand_noncecheck() {
252252
$var = wp_unslash( $_POST['foo'] ); // Bad.
253253
echo $var;
@@ -275,3 +275,29 @@ function dont_allow_bypass_nonce_via_sanitization() {
275275
wp_verify_nonce( $var );
276276
echo $var;
277277
}
278+
279+
// Issue #1694
280+
function function_containing_nested_class() {
281+
if ( !class_exists( 'Nested_Class' ) ) {
282+
class Nested_Class extends Something {
283+
public function method_in_nested_class() {
284+
if ( isset( $_POST['my_nonce'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['my_nonce'] ) ), 'the_nonce' ) ) {
285+
if ( isset( $_POST['hello'] ) ) {
286+
echo 'world';
287+
}
288+
}
289+
}
290+
}
291+
}
292+
}
293+
294+
function function_containing_nested_closure() {
295+
$closure = function() {
296+
if ( isset( $_POST['my_nonce'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['my_nonce'] ) ), 'the_nonce' ) ) {
297+
if ( isset( $_POST['hello'] ) ) {
298+
echo 'world';
299+
}
300+
}
301+
};
302+
}
303+

WordPress/Tests/WP/CapitalPDangitUnitTest.inc

+8
Original file line numberDiff line numberDiff line change
@@ -180,3 +180,11 @@ wordpress.pot
180180
$text = <<<'EOD'
181181
This is an explanation about word-press.
182182
EOD;
183+
184+
// Issue 1698 - ignore constant declarations.
185+
define( 'WORDPRESS_SOMETHING', 'wordpress' ); // OK.
186+
class TestMe {
187+
public const MY_CONST = 123,
188+
ANOTHER => array( 'a' => 'b' ),
189+
WORDPRESS_SOMETHING = 'wordpress'; // OK (complex declaration to make sure start of statement is detected correctly).
190+
}

WordPress/Tests/WP/CapitalPDangitUnitTest.inc.fixed

+8
Original file line numberDiff line numberDiff line change
@@ -180,3 +180,11 @@ wordpress.pot
180180
$text = <<<'EOD'
181181
This is an explanation about WordPress.
182182
EOD;
183+
184+
// Issue 1698 - ignore constant declarations.
185+
define( 'WORDPRESS_SOMETHING', 'wordpress' ); // OK.
186+
class TestMe {
187+
public const MY_CONST = 123,
188+
ANOTHER => array( 'a' => 'b' ),
189+
WORDPRESS_SOMETHING = 'wordpress'; // OK (complex declaration to make sure start of statement is detected correctly).
190+
}

WordPress/Tests/WP/DeprecatedFunctionsUnitTest.inc

+2-2
Original file line numberDiff line numberDiff line change
@@ -327,12 +327,12 @@ _usort_terms_by_name();
327327
get_paged_template();
328328
wp_get_network();
329329
wp_kses_js_entities();
330+
/* ============ WP 4.8 ============ */
331+
wp_dashboard_plugins_output();
330332

331333
/*
332334
* Warning.
333335
*/
334-
/* ============ WP 4.8 ============ */
335-
wp_dashboard_plugins_output();
336336
/* ============ WP 4.9 ============ */
337337
get_shortcut_link();
338338
is_user_option_local();

WordPress/Tests/WP/DeprecatedFunctionsUnitTest.php

+5-4
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class DeprecatedFunctionsUnitTest extends AbstractSniffUnitTest {
2828
*/
2929
public function getErrorList() {
3030

31-
$errors = array_fill( 8, 322, 1 );
31+
$errors = array_fill( 8, 324, 1 );
3232

3333
// Unset the lines related to version comments.
3434
unset(
@@ -61,7 +61,8 @@ public function getErrorList() {
6161
$errors[304],
6262
$errors[311],
6363
$errors[319],
64-
$errors[323]
64+
$errors[323],
65+
$errors[330]
6566
);
6667

6768
return $errors;
@@ -74,10 +75,10 @@ public function getErrorList() {
7475
*/
7576
public function getWarningList() {
7677

77-
$warnings = array_fill( 335, 9, 1 );
78+
$warnings = array_fill( 337, 7, 1 );
7879

7980
// Unset the lines related to version comments.
80-
unset( $warnings[336], $warnings[341] );
81+
unset( $warnings[341] );
8182

8283
return $warnings;
8384
}

WordPress/Tests/WP/DeprecatedParametersUnitTest.inc

+2-3
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ comments_link( 'deprecated', 'deprecated' );
3434
comments_number( '', '', '', 'deprecated' );
3535
convert_chars( '', 'deprecated' );
3636
discover_pingback_server_uri( '', 'deprecated' );
37+
get_category_parents( '', '', '', '', array( 'deprecated') );
3738
get_delete_post_link( '', 'deprecated' );
3839
get_last_updated( 'deprecated' );
3940
get_the_author( 'deprecated' );
@@ -61,6 +62,4 @@ wp_title_rss( 'deprecated' );
6162
wp_upload_bits( '', 'deprecated' );
6263
xfn_check( '', '', 'deprecated' );
6364

64-
// All will give an WARNING as they have been deprecated after WP 4.8.
65-
66-
get_category_parents( '', '', '', '', array( 'deprecated') );
65+
// All will give an WARNING as they have been deprecated after WP 4.9.

WordPress/Tests/WP/DeprecatedParametersUnitTest.php

+3-5
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@ class DeprecatedParametersUnitTest extends AbstractSniffUnitTest {
2727
* @return array <int line number> => <int number of errors>
2828
*/
2929
public function getErrorList() {
30-
$errors = array_fill( 28, 35, 1 );
30+
$errors = array_fill( 28, 36, 1 );
3131

3232
$errors[22] = 1;
3333
$errors[23] = 1;
3434
$errors[24] = 1;
3535

3636
// Override number of errors.
3737
$errors[33] = 2;
38-
$errors[47] = 2;
38+
$errors[48] = 2;
3939

4040
return $errors;
4141
}
@@ -46,9 +46,7 @@ public function getErrorList() {
4646
* @return array <int line number> => <int number of warnings>
4747
*/
4848
public function getWarningList() {
49-
return array(
50-
66 => 1,
51-
);
49+
return array();
5250
}
5351

5452
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
use PHPUnit\Framework\TestCase;
4+
5+
class Test_Class_D extends TestCase {
6+
7+
public function test_something() {
8+
global $tabs;
9+
$tabs = 50; // Ok.
10+
}
11+
}

phpcs.xml.dist.sample

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
the wiki:
7171
https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki/Customizable-sniff-properties
7272
-->
73-
<config name="minimum_supported_wp_version" value="4.8"/>
73+
<config name="minimum_supported_wp_version" value="4.9"/>
7474

7575
<rule ref="WordPress.WP.I18n">
7676
<properties>

0 commit comments

Comments
 (0)