Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions WordPress/Tests/DB/RestrictedFunctionsUnitTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,11 @@ WP_Date_Query::build_mysql_datetime(); // Ok.
myFictionFunction(); // Bad.
myFictional(); // OK.
Myfictional(); // OK.

/*
* Safeguard correct handling of all types of namespaced function calls.
*/
\mysql_connect();
MyNamespace\mysql_connect();
\MyNamespace\mysql_connect();
namespace\mysql_connect(); // The sniff should start flagging this once it can resolve relative namespaces.
84 changes: 43 additions & 41 deletions WordPress/Tests/DB/RestrictedFunctionsUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,54 +63,56 @@ protected function tearDown(): void {
*/
public function getErrorList() {
return array(
25 => 1,
26 => 1,
27 => 1,
28 => 1,
29 => 1,
30 => 1,
31 => 1,
32 => 1,
33 => 1,
25 => 1,
26 => 1,
27 => 1,
28 => 1,
29 => 1,
30 => 1,
31 => 1,
32 => 1,
33 => 1,

36 => 1,
37 => 1,
38 => 1,
39 => 1,
40 => 1,
41 => 1,
42 => 1,
43 => 1,
44 => 1,
36 => 1,
37 => 1,
38 => 1,
39 => 1,
40 => 1,
41 => 1,
42 => 1,
43 => 1,
44 => 1,

47 => 1,
48 => 1,
49 => 1,
50 => 1,
51 => 1,
47 => 1,
48 => 1,
49 => 1,
50 => 1,
51 => 1,

54 => 1,
55 => 1,
56 => 1,
57 => 1,
54 => 1,
55 => 1,
56 => 1,
57 => 1,

60 => 1,
60 => 1,

63 => 1,
63 => 1,

66 => 1,
67 => 1,
68 => 1,
69 => 1,
70 => 1,
71 => 1,
72 => 1,
73 => 1,
74 => 1,
75 => 1,
76 => 1,
66 => 1,
67 => 1,
68 => 1,
69 => 1,
70 => 1,
71 => 1,
72 => 1,
73 => 1,
74 => 1,
75 => 1,
76 => 1,

94 => 1,
94 => 1,

101 => 1,
);
}

Expand Down
8 changes: 8 additions & 0 deletions WordPress/Tests/DateTime/RestrictedFunctionsUnitTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,11 @@ $date->setTimezone( new DateTimeZone( 'America/Toronto' ) ); // Yay!

$post_data['post_title'] = sprintf( __( 'Draft created on %1$s at %2$s' ), date( __( 'F j, Y' ), $now ), date( __( 'g:i a' ), $now ) ); // Error.
$post_data['post_title'] = sprintf( __( 'Draft created on %1$s at %2$s' ), gmdate( __( 'F j, Y' ), $now ), gmdate( __( 'g:i a' ), $now ) ); // OK.

/*
* Safeguard correct handling of all types of namespaced function calls.
*/
\date_default_timezone_set( 'Foo/Bar' );
MyNamespace\date_default_timezone_set( 'Foo/Bar' );
\MyNamespace\date_default_timezone_set( 'Foo/Bar' );
namespace\date_default_timezone_set( 'Foo/Bar' ); // The sniff should start flagging this once it can resolve relative namespaces.
5 changes: 3 additions & 2 deletions WordPress/Tests/DateTime/RestrictedFunctionsUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ final class RestrictedFunctionsUnitTest extends AbstractSniffUnitTest {
*/
public function getErrorList() {
return array(
3 => 1,
8 => 2,
3 => 1,
8 => 2,
14 => 1,
);
}

Expand Down
10 changes: 8 additions & 2 deletions WordPress/Tests/PHP/DevelopmentFunctionsUnitTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,11 @@ phpinfo(); // Error.

Wrapper_Class::var_dump(); // OK, not the native PHP function.
$wrapper ->var_dump(); // OK, not the native PHP function.
namespace\var_dump(); // OK as long as the file is namespaced.
MyNamespace\var_dump(); // OK, namespaced function.

/*
* Safeguard correct handling of all types of namespaced function calls.
*/
\var_dump( $value );
MyNamespace\var_dump( $value );
\MyNamespace\var_dump( $value );
namespace\var_dump( $value ); // The sniff should start flagging this once it can resolve relative namespaces.
1 change: 1 addition & 0 deletions WordPress/Tests/PHP/DevelopmentFunctionsUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public function getWarningList() {
24 => 1,
33 => 1,
34 => 1,
42 => 1,
);
}
}
10 changes: 5 additions & 5 deletions WordPress/Tests/PHP/DiscouragedPHPFunctionsUnitTest.inc
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?php






// Safeguard against false positives on namespaced function calls.
MyNamespace\serialize( $value );
\MyNamespace\serialize( $value );
namespace\serialize( $value ); // The sniff should start flagging this once it can resolve relative namespaces.

serialize(); // Warning.
\serialize( $value ); // Warning.
unserialize(); // Warning.

urlencode(); // Warning.
Expand Down
1 change: 1 addition & 0 deletions WordPress/Tests/PHP/DiscouragedPHPFunctionsUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public function getErrorList() {
*/
public function getWarningList() {
return array(
8 => 1,
9 => 1,
10 => 1,
12 => 1,
Expand Down
8 changes: 8 additions & 0 deletions WordPress/Tests/PHP/DontExtractUnitTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,11 @@ my_extract(); // Ok.
My_Object::extract(); // Ok.
$this->extract(); // Ok.
$my_object->extract(); // Ok.

/*
* Safeguard correct handling of all types of namespaced function calls.
*/
\extract( array( 'a' => 1 ) );
MyNamespace\extract( array( 'a' => 1 ) );
\MyNamespace\extract( array( 'a' => 1 ) );
namespace\extract( array( 'a' => 1 ) ); // The sniff should start flagging this once it can resolve relative namespaces.
3 changes: 2 additions & 1 deletion WordPress/Tests/PHP/DontExtractUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ final class DontExtractUnitTest extends AbstractSniffUnitTest {
*/
public function getErrorList() {
return array(
3 => 1,
3 => 1,
14 => 1,
);
}

Expand Down
8 changes: 8 additions & 0 deletions WordPress/Tests/PHP/POSIXFunctionsUnitTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,11 @@ list( $year, $month, $day ) = split( ':', $date ); // Bad, split has been deprec
$title_parts = spliti( ' ', get_the_title(), 4 ); // Bad, spliti also deprecated. Use preg_split instead.

sql_regcase( 'Foo - bar.'); // Bad. Deprecated.

/*
* Safeguard correct handling of all types of namespaced function calls.
*/
\split( ':', $date );
MyNamespace\split( ':', $date );
\MyNamespace\split( ':', $date );
namespace\split( ':', $date ); // The sniff should start flagging this once it can resolve relative namespaces.
1 change: 1 addition & 0 deletions WordPress/Tests/PHP/POSIXFunctionsUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public function getErrorList() {
22 => 1,
24 => 1,
26 => 1,
31 => 1,
);
}

Expand Down
8 changes: 8 additions & 0 deletions WordPress/Tests/PHP/RestrictedPHPFunctionsUnitTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,11 @@
add_action( 'widgets_init', create_function( '', // Error.
'return register_widget( "time_more_on_time_widget" );'
) );

/*
* Safeguard correct handling of all types of namespaced function calls.
*/
\create_function('', 'return;');
MyNamespace\create_function('', 'return;');
\MyNamespace\create_function('', 'return;');
namespace\create_function('', 'return;'); // The sniff should start flagging this once it can resolve relative namespaces.
3 changes: 2 additions & 1 deletion WordPress/Tests/PHP/RestrictedPHPFunctionsUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ final class RestrictedPHPFunctionsUnitTest extends AbstractSniffUnitTest {
*/
public function getErrorList() {
return array(
3 => 1,
3 => 1,
10 => 1,
);
}

Expand Down
8 changes: 8 additions & 0 deletions WordPress/Tests/Security/SafeRedirectUnitTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,11 @@

wp_redirect( $location ); // Warning.
wp_safe_redirect( $location ); // OK.

/*
* Safeguard correct handling of all types of namespaced function calls.
*/
\wp_redirect( $location );
MyNamespace\wp_redirect( $location );
\MyNamespace\wp_redirect( $location );
namespace\wp_redirect( $location ); // The sniff should start flagging this once it can resolve relative namespaces.
1 change: 1 addition & 0 deletions WordPress/Tests/Security/SafeRedirectUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public function getErrorList() {
public function getWarningList() {
return array(
3 => 1,
9 => 1,
);
}
}
9 changes: 9 additions & 0 deletions WordPress/Tests/WP/DeprecatedFunctionsUnitTest.2.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

/*
* Safeguard correct handling of all types of namespaced function calls.
*/
\the_category_ID();
MyNamespace\the_category_ID();
\MyNamespace\the_category_ID();
namespace\the_category_ID(); // The sniff should start flagging this once it can resolve relative namespaces.
Loading