Skip to content

Commit f503500

Browse files
committed
Fix WordPressVIPMinimum ruleset test cases for site_option grouping in RestrictedFunctionsSniff
1 parent 6f77a54 commit f503500

File tree

5 files changed

+6
-53
lines changed

5 files changed

+6
-53
lines changed

WordPressVIPMinimum/Sniffs/Files/IncludingFileSniff.php

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
/**
1414
* WordPressVIPMinimum_Sniffs_Files_IncludingFileSniff.
1515
*
16-
* Checks for custom variables, functions and constants, and external URLs used in file inclusion.
16+
* Checks that __DIR__, dirname( __FILE__ ) or plugin_dir_path( __FILE__ )
17+
* is used when including or requiring files.
1718
*
1819
* @package VIPCS\WordPressVIPMinimum
1920
*/
@@ -54,17 +55,6 @@ class IncludingFileSniff extends AbstractFunctionRestrictionsSniff {
5455
'WP_PLUGIN_DIR',
5556
];
5657

57-
/**
58-
* List of keywords allowed for use in custom constants.
59-
* Note: Customizing this property will overwrite current default values.
60-
*
61-
* @var array
62-
*/
63-
public $allowedKeywords = [
64-
'PATH',
65-
'DIR',
66-
];
67-
6858
/**
6959
* Functions used for modify slashes.
7060
*
@@ -132,11 +122,6 @@ public function process_token( $stackPtr ) {
132122
return;
133123
}
134124

135-
if ( $this->has_custom_path( $this->tokens[ $nextToken ]['content'] ) === true ) {
136-
// The construct is using a constant with an allowed keyword.
137-
return;
138-
}
139-
140125
if ( array_key_exists( $this->tokens[ $nextToken ]['content'], $this->restrictedConstants ) === true ) {
141126
// The construct is using one of the restricted constants.
142127
$message = '`%s` constant might not be defined or available. Use `%s()` instead.';
@@ -187,21 +172,4 @@ public function process_token( $stackPtr ) {
187172
$message = 'Absolute include path must be used. Use `get_template_directory()`, `get_stylesheet_directory()` or `plugin_dir_path()`.';
188173
$this->phpcsFile->addError( $message, $nextToken, 'NotAbsolutePath' );
189174
}
190-
191-
/**
192-
* Check if a content string contains a keyword in custom paths.
193-
*
194-
* @param string $content Content string.
195-
*
196-
* @return bool True if the string partially matches a keyword in $allowedCustomKeywords, false otherwise.
197-
*/
198-
private function has_custom_path( $content ) {
199-
foreach ( $this->allowedKeywords as $keyword ) {
200-
if ( strpos( $content, $keyword ) !== false ) {
201-
return true;
202-
}
203-
}
204-
205-
return false;
206-
}
207175
}

WordPressVIPMinimum/Tests/Files/IncludingFileUnitTest.inc

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,4 @@ require_once "my_file.php"; // Not absolute path.
2525
require '../my_file.php'; // Not absolute path.
2626
require '../../my_file.php'; // Not absolute path.
2727
include( 'http://www.google.com/bad_file.php' ); // External URL.
28-
include_once("http://www.google.com/bad_file.php"); // External URL.
29-
30-
// Allowed keywords
31-
include 'https://path.com/bad_file.php'; // Error - external URL with keyword from $allowedKeywords.
32-
require $path; // Warning - custom variable with keyword from $allowedKeywords.
33-
include_once dir_function(); // Error - custom functionm with keyword from $allowedKeywords.
34-
require CUSTOM_CONSTANT_DIR . 'file.php'; // OK.
35-
require_once ( VIPCS_PATH ) . 'file.php'; // OK.
36-
include_once
37-
DIR_CUSTOM , 'file.php'; // OK.
28+
include_once("http://www.google.com/bad_file.php"); // External URL.

WordPressVIPMinimum/Tests/Files/IncludingFileUnitTest.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ public function getErrorList() {
2929
26 => 1,
3030
27 => 1,
3131
28 => 1,
32-
31 => 1,
3332
];
3433
}
3534

@@ -44,8 +43,6 @@ public function getWarningList() {
4443
19 => 1,
4544
20 => 1,
4645
21 => 1,
47-
32 => 1,
48-
33 => 1,
4946
];
5047
}
5148

WordPressVIPMinimum/ruleset-test.inc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -390,9 +390,9 @@ chown(); // Error.
390390
chmod(); // Error.
391391
lchgrp(); // Error.
392392
lchown(); // Error.
393-
add_site_option( 'foo', $bar ); // Error.
394-
update_site_option( $bar, $foo, true ); // Error.
395-
delete_site_option( $foo ); // Error.
393+
394+
395+
396396
wp_mail(); // Warning.
397397
mail(); // Warning.
398398
is_multi_author(); // Warning.

WordPressVIPMinimum/ruleset-test.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,6 @@
161161
390 => 1,
162162
391 => 1,
163163
392 => 1,
164-
393 => 1,
165-
394 => 1,
166-
395 => 1,
167164
402 => 1,
168165
415 => 1,
169166
425 => 1,

0 commit comments

Comments
 (0)