Skip to content

Commit c98ecc2

Browse files
committed
AbstractFunctionRestrictions: implement Sniff::is_class_object_call() and Sniff::is_token_namespaced()
1 parent a55e3e0 commit c98ecc2

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

WordPress/AbstractFunctionRestrictionsSniff.php

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,15 @@ public function process_token( $stackPtr ) {
213213
public function is_targetted_token( $stackPtr ) {
214214

215215
// Exclude function definitions, class methods, and namespaced calls.
216-
if ( \T_STRING === $this->tokens[ $stackPtr ]['code'] && isset( $this->tokens[ ( $stackPtr - 1 ) ] ) ) {
216+
if ( \T_STRING === $this->tokens[ $stackPtr ]['code'] ) {
217+
if ( $this->is_class_object_call( $stackPtr ) === true ) {
218+
return false;
219+
}
220+
221+
if ( $this->is_token_namespaced( $stackPtr ) === true ) {
222+
return false;
223+
}
224+
217225
$prev = $this->phpcsFile->findPrevious( Tokens::$emptyTokens, ( $stackPtr - 1 ), null, true );
218226

219227
if ( false !== $prev ) {
@@ -222,21 +230,11 @@ public function is_targetted_token( $stackPtr ) {
222230
\T_FUNCTION => \T_FUNCTION,
223231
\T_CLASS => \T_CLASS,
224232
\T_AS => \T_AS, // Use declaration alias.
225-
\T_DOUBLE_COLON => \T_DOUBLE_COLON,
226-
\T_OBJECT_OPERATOR => \T_OBJECT_OPERATOR,
227233
);
228234

229235
if ( isset( $skipped[ $this->tokens[ $prev ]['code'] ] ) ) {
230236
return false;
231237
}
232-
233-
// Skip namespaced functions, ie: \foo\bar() not \bar().
234-
if ( \T_NS_SEPARATOR === $this->tokens[ $prev ]['code'] ) {
235-
$pprev = $this->phpcsFile->findPrevious( Tokens::$emptyTokens, ( $prev - 1 ), null, true );
236-
if ( false !== $pprev && \T_STRING === $this->tokens[ $pprev ]['code'] ) {
237-
return false;
238-
}
239-
}
240238
}
241239

242240
return true;

WordPress/Tests/PHP/DevelopmentFunctionsUnitTest.inc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,8 @@ phpinfo(); // Ok - within excluded group.
3232
// phpcs:set WordPress.PHP.DevelopmentFunctions exclude[]
3333
trigger_error(); // Error.
3434
phpinfo(); // Error.
35+
36+
Wrapper_Class::var_dump(); // OK, not the native PHP function.
37+
$wrapper ->var_dump(); // OK, not the native PHP function.
38+
namespace\var_dump(); // OK as long as the file is namespaced.
39+
MyNamespace\var_dump(); // OK, namespaced function.

0 commit comments

Comments
 (0)