Skip to content

Commit b050cb4

Browse files
authored
Merge pull request #2663 from rodrigoprimo/abstract-function-restrictions-improve-namespaced-names-tests
2 parents 2781d2c + 5a9ae23 commit b050cb4

17 files changed

Lines changed: 111 additions & 52 deletions

WordPress/Tests/DB/RestrictedFunctionsUnitTest.inc

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ prefix_mysql_info(); // Ok.
2323

2424
// MYSQL Extension.
2525
mysql_affected_rows();
26-
mysql_connect();
27-
mysql_close();
26+
Mysql_CONNECT();
27+
\MYSQL_close();
2828
mysql_fetch_row();
2929
mysql_info();
3030
mysql_numrows();
@@ -99,6 +99,7 @@ Myfictional(); // OK.
9999
* Safeguard correct handling of all types of namespaced function calls.
100100
*/
101101
\mysql_connect();
102-
MyNamespace\mysql_connect();
103-
\MyNamespace\mysql_connect();
104-
namespace\mysql_connect(); // The sniff should start flagging this once it can resolve relative namespaces.
102+
MyNamespace\mysqli_init();
103+
\MyNamespace\mysqlnd_qc_clear_cache();
104+
namespace\maxdb_close(); // The sniff should start flagging this once it can resolve relative namespaces.
105+
namespace\Sub\mysqli_fetch();

WordPress/Tests/DateTime/RestrictedFunctionsUnitTest.inc

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@ date_default_timezone_set( 'Foo/Bar' ); // Bad.
55
$date = new DateTime();
66
$date->setTimezone( new DateTimeZone( 'America/Toronto' ) ); // Yay!
77

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

1111
/*
1212
* Safeguard correct handling of all types of namespaced function calls.
1313
*/
1414
\date_default_timezone_set( 'Foo/Bar' );
15-
MyNamespace\date_default_timezone_set( 'Foo/Bar' );
15+
\DATE_default_timezone_SET( 'Foo/Bar' );
16+
MyNamespace\date( 'Y-m-d' );
1617
\MyNamespace\date_default_timezone_set( 'Foo/Bar' );
17-
namespace\date_default_timezone_set( 'Foo/Bar' ); // The sniff should start flagging this once it can resolve relative namespaces.
18+
namespace\date( 'Y-m-d' ); // The sniff should start flagging this once it can resolve relative namespaces.
19+
namespace\Sub\date_default_timezone_set( 'Foo/Bar' );

WordPress/Tests/DateTime/RestrictedFunctionsUnitTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public function getErrorList() {
3030
3 => 1,
3131
8 => 2,
3232
14 => 1,
33+
15 => 1,
3334
);
3435
}
3536

WordPress/Tests/PHP/DevelopmentFunctionsUnitTest.inc

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ phpinfo(); // Ok - within excluded group.
3030

3131
// Reset group exclusions.
3232
// phpcs:set WordPress.PHP.DevelopmentFunctions exclude[]
33-
trigger_error(); // Error.
33+
\TRIGGER_ERROR(); // Error.
3434
phpinfo(); // Error.
3535

3636
Wrapper_Class::var_dump(); // OK, not the native PHP function.
@@ -40,6 +40,7 @@ $wrapper ->var_dump(); // OK, not the native PHP function.
4040
* Safeguard correct handling of all types of namespaced function calls.
4141
*/
4242
\var_dump( $value );
43-
MyNamespace\var_dump( $value );
44-
\MyNamespace\var_dump( $value );
45-
namespace\var_dump( $value ); // The sniff should start flagging this once it can resolve relative namespaces.
43+
MyNamespace\phpinfo();
44+
\MyNamespace\print_r( $value );
45+
namespace\error_reporting(); // The sniff should start flagging this once it can resolve relative namespaces.
46+
namespace\Sub\debug_backtrace();

WordPress/Tests/PHP/DiscouragedPHPFunctionsUnitTest.inc

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<?php
22

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

88
serialize(); // Warning.
99
\serialize( $value ); // Warning.
10-
unserialize(); // Warning.
10+
UNserialize(); // Warning.
1111

1212
urlencode(); // Warning.
1313
rawurlencode(); // Ok.
@@ -19,7 +19,7 @@ ini_restore(); // Warning.
1919
magic_quotes_runtime(); // Warning.
2020
set_magic_quotes_runtime(); // Warning.
2121
apache_setenv(); // Warning.
22-
putenv(); // Warning.
22+
\PUTENV(); // Warning.
2323
set_include_path(); // Warning.
2424
restore_include_path(); // Warning.
2525

@@ -41,3 +41,11 @@ $handle = popen( '/bin/ls', 'r' );
4141
// Issue #898.
4242
class System {}
4343
class Serialize {}
44+
45+
/*
46+
* Safeguard correct handling of all types of namespaced function calls.
47+
*/
48+
MyNamespace\urlencode( $value );
49+
\MyNamespace\putenv( $value );
50+
namespace\exec( $command ); // The sniff should start flagging this once it can resolve relative namespaces.
51+
namespace\Sub\base64_decode( $value );

WordPress/Tests/PHP/DontExtractUnitTest.inc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22

33
extract( array( 'a' => 1 ) ); // Bad.
4+
exTRAct( array( 'a' => 1 ) ); // Bad.
45

56
// Similarly named functions or methods however are fine.
67
my_extract(); // Ok.
@@ -12,6 +13,8 @@ $my_object->extract(); // Ok.
1213
* Safeguard correct handling of all types of namespaced function calls.
1314
*/
1415
\extract( array( 'a' => 1 ) );
16+
\EXTRACT( array( 'a' => 1 ) );
1517
MyNamespace\extract( array( 'a' => 1 ) );
1618
\MyNamespace\extract( array( 'a' => 1 ) );
1719
namespace\extract( array( 'a' => 1 ) ); // The sniff should start flagging this once it can resolve relative namespaces.
20+
namespace\Sub\extract( array( 'a' => 1 ) );

WordPress/Tests/PHP/DontExtractUnitTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ final class DontExtractUnitTest extends AbstractSniffUnitTest {
3030
public function getErrorList() {
3131
return array(
3232
3 => 1,
33-
14 => 1,
33+
4 => 1,
34+
15 => 1,
35+
16 => 1,
3436
);
3537
}
3638

WordPress/Tests/PHP/POSIXFunctionsUnitTest.inc

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ $title = preg_split( 'cool', get_the_title() ); // Good.
1313
if ( ereg( '[A-Za-z]+', $title, $regs ) ) // Bad, ereg deprecated. Use preg_match instead.
1414
die( $regs );
1515

16-
if ( eregi( '[a-z]+', $title, $regs ) ) {} // Bad, eregi deprecated. Use preg_match instead.
16+
if ( \EREGI( '[a-z]+', $title, $regs ) ) {} // Bad, eregi deprecated. Use preg_match instead.
1717

18-
$title = ereg_replace( 'cool', 'not cool', get_the_title() ); // Bad, ereg_replace has been deprecated. Use preg_replace instead.
18+
$title = ereg_REPLACE( 'cool', 'not cool', get_the_title() ); // Bad, ereg_replace has been deprecated. Use preg_replace instead.
1919

2020
$title = eregi_replace( 'cool', 'not cool', get_the_title() ); // Bad, eregi_replace also deprecated. Use preg_replace instead.
2121

@@ -29,6 +29,7 @@ sql_regcase( 'Foo - bar.'); // Bad. Deprecated.
2929
* Safeguard correct handling of all types of namespaced function calls.
3030
*/
3131
\split( ':', $date );
32-
MyNamespace\split( ':', $date );
33-
\MyNamespace\split( ':', $date );
34-
namespace\split( ':', $date ); // The sniff should start flagging this once it can resolve relative namespaces.
32+
MyNamespace\ereg( 'pattern', $string );
33+
\MyNamespace\ereg_replace( 'pattern', 'replacement', $string );
34+
namespace\spliti( ':', $date ); // The sniff should start flagging this once it can resolve relative namespaces.
35+
namespace\Sub\sql_regcase( 'string' );

WordPress/Tests/PHP/RestrictedPHPFunctionsUnitTest.inc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@
33
add_action( 'widgets_init', create_function( '', // Error.
44
'return register_widget( "time_more_on_time_widget" );'
55
) );
6+
CREATE_function( '', '' ); // Error.
67

78
/*
89
* Safeguard correct handling of all types of namespaced function calls.
910
*/
1011
\create_function('', 'return;');
12+
\Create_Function('', 'return;');
1113
MyNamespace\create_function('', 'return;');
1214
\MyNamespace\create_function('', 'return;');
1315
namespace\create_function('', 'return;'); // The sniff should start flagging this once it can resolve relative namespaces.
16+
namespace\Sub\create_function('', 'return;');

WordPress/Tests/PHP/RestrictedPHPFunctionsUnitTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ final class RestrictedPHPFunctionsUnitTest extends AbstractSniffUnitTest {
2828
public function getErrorList() {
2929
return array(
3030
3 => 1,
31-
10 => 1,
31+
6 => 1,
32+
11 => 1,
33+
12 => 1,
3234
);
3335
}
3436

0 commit comments

Comments
 (0)