forked from WordPress/WordPress-Coding-Standards
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCurrentTimeTimestampUnitTest.inc.fixed
More file actions
38 lines (31 loc) · 1.23 KB
/
CurrentTimeTimestampUnitTest.inc.fixed
File metadata and controls
38 lines (31 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php
current_time(); // OK. Well not really, but not our concern.
current_time( 'mysql', true ); // OK.
current_time( 'Y-m-d' ); // OK.
current_time( self::get_date_format() ); // OK.
current_time( $format, $gmt ); // OK.
time(); // Error.
time(); // Error.
// Test multi-line function call + interlaced comments handling.
current_time( // Error.
"timestamp", // Timestamp format.
true // Use GMT timezone.
);
current_time( 'timestamp', $gmt ); // Warning.
\Current_Time( 'timestamp', false ); // Warning.
current_time( 'U', 0 ); // Warning.
current_time( 'U' ); // Warning.
// Safeguard support for PHP 8.0+ named parameters.
current_time( gmt: false ); // OK. Well not really (missing required $type), but not our concern.
current_time( gmt: true, type: 'mysql', ); // OK.
current_time( type: 'Y-m-d' ); // OK.
time(); // Error.
current_time( gmt: 0, type : 'U' ); // Warning.
/*
* Safeguard correct handling of all types of namespaced function calls.
*/
\time(); // Error.
MyNamespace\current_time( 'timestamp', true );
\MyNamespace\current_time( 'timestamp', true );
namespace\current_time( 'timestamp', true ); // The sniff should start flagging this once it can resolve relative namespaces.
namespace\Sub\current_time( 'timestamp', true );