Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RestrictedPHPFunctions: add error for use of date() #1714

Merged
merged 1 commit into from
Jun 27, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions WordPress/Sniffs/PHP/RestrictedPHPFunctionsSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* @package WPCS\WordPressCodingStandards
*
* @since 0.14.0
* @since 2.2.0 New group `date` added.
*/
class RestrictedPHPFunctionsSniff extends AbstractFunctionRestrictionsSniff {

Expand All @@ -42,6 +43,13 @@ public function getGroups() {
'create_function',
),
),
'date' => array(
'type' => 'error',
'message' => '%s() is affected by runtime timezone changes which can cause date/time to be incorrectly displayed. Use gmdate() instead.',
'functions' => array(
'date',
),
),
);
}

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

$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.
1 change: 1 addition & 0 deletions WordPress/Tests/PHP/RestrictedPHPFunctionsUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class RestrictedPHPFunctionsUnitTest extends AbstractSniffUnitTest {
public function getErrorList() {
return array(
3 => 1,
7 => 2,
);
}

Expand Down