Skip to content

Commit 3384471

Browse files
rodrigoprimojrfnl
andcommitted
PHP/NoSilencedErrors: add tests for namespaced names
Co-authored-by: Juliette <663378+jrfnl@users.noreply.github.com>
1 parent 81560f6 commit 3384471

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

WordPress/Tests/PHP/NoSilencedErrorsUnitTest.inc

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ if (@in_array($array, $needle)) { // Bad.
1212
}
1313

1414
// File extension.
15-
if ( @&file_exists( $filename ) && @ /*comment*/ is_readable( $filename ) ) {
15+
if ( @&file_exists( $filename ) && @ /*comment*/ IS_READABLE( $filename ) ) {
1616
$file = @ \file( $filename );
1717
}
1818

@@ -22,7 +22,7 @@ $fp = @fopen('https://www.example.com', 'r', false);
2222

2323
// Directory extension.
2424
if (@is_dir($dir)) {
25-
if ($dh = @\opendir($dir)) {
25+
if ($dh = @\OPENDIR($dir)) {
2626
while (($file = @readdir($dh)) !== false) { // Bad.
2727
echo "filename: $file : filetype: " . @\filetype($dir . $file) . "\n";
2828
}
@@ -84,3 +84,11 @@ $decoded = @hex2bin( $data );
8484
// phpcs:set WordPress.PHP.NoSilencedErrors context_length 0
8585
echo @some_userland_function( $param ); // Bad.
8686
// phpcs:set WordPress.PHP.NoSilencedErrors context_length 6
87+
88+
/*
89+
* Safeguard correct handling of namespaced function calls (fully qualified is already tested above).
90+
*/
91+
$file = @MyNS\MyClass::file_get_contents( $file ); // Bad.
92+
$file = @MyNS\MyClass\file_exists( $file ); // Bad.
93+
$file = @namespace\MyNS\MyClass::file( $file ); // Bad.
94+
$file = @namespace\is_dir( $dir ); // The sniff should stop flagging this once it can resolve relative namespaces.

WordPress/Tests/PHP/NoSilencedErrorsUnitTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ public function getWarningList() {
6161
71 => 1,
6262
78 => 1,
6363
85 => 1,
64+
91 => 1,
65+
92 => 1,
66+
93 => 1,
67+
94 => 1,
6468
);
6569
}
6670
}

0 commit comments

Comments
 (0)