@@ -10,12 +10,12 @@ wp_cache_set( $testing, $data, 'test_group', 5*MINUTE_IN_SECONDS );
1010wp_cache_set ( 123 , $ data , 'test_group ' , 5 * MINUTE_IN_SECONDS );
1111wp_cache_set ( 1234 , $ data , '' , 425 );
1212wp_cache_set ( $ testing , $ data , null , 350 );
13- wp_cache_set ( $ testing , $ data );
13+ \ wp_cache_set ( $ testing , $ data );
1414wp_cache_set ( 'test ' , $ data , $ group );
1515
1616wp_cache_add ( 'test ' , $ data , $ group , 300 );
1717wp_cache_add ( $ testing , $ data , 'test_group ' , 6 *MINUTE_IN_SECONDS );
18- wp_cache_add ( 1234 , $ data , '' , 425 );
18+ WP_CACHE_ADD ( 1234 , $ data , '' , 425 );
1919wp_cache_add ( $ testing , $ data , null , 350 );
2020
2121wp_cache_replace ( 'test ' , $ data , $ group , 300 );
@@ -30,13 +30,13 @@ wp_cache_set( 123, $data, null, 1.5 * MINUTE_IN_SECONDS ); // Lower than 300.
3030wp_cache_set ( $ testing , $ data , '' , 1.5 * MINUTE_IN_SECONDS ); // Lower than 300.
3131
3232wp_cache_add ( 'test ' , $ data , $ group , 100 ); // Lower than 300.
33- wp_cache_add ( 'test ' , $ data , $ group , 2 *MINUTE_IN_SECONDS ); // Lower than 300.
33+ \ wp_cache_add ( 'test ' , $ data , $ group , 2 *MINUTE_IN_SECONDS ); // Lower than 300.
3434wp_cache_add ( 123 , $ data , null , 1.5 * MINUTE_IN_SECONDS ); // Lower than 300.
3535wp_cache_add ( $ testing , $ data , '' , 1.5 * MINUTE_IN_SECONDS ); // Lower than 300.
3636
3737wp_cache_replace ( 'test ' , $ data , $ group , 100 ); // Lower than 300.
3838wp_cache_replace ( 'test ' , $ data , $ group , 2 *MINUTE_IN_SECONDS ); // Lower than 300.
39- wp_cache_replace ( 123 , $ data , null , 1.5 * MINUTE_IN_SECONDS ); // Lower than 300.
39+ WP_CACHE_REPLACE ( 123 , $ data , null , 1.5 * MINUTE_IN_SECONDS ); // Lower than 300.
4040wp_cache_replace ( $ testing , $ data , '' , 1.5 * MINUTE_IN_SECONDS ); // Lower than 300.
4141
4242// Test error being reported on the line containing the parameter.
@@ -49,7 +49,7 @@ wp_cache_replace(
4949
5050// Test calculations with floats.
5151wp_cache_replace ( $ testing , $ data , '' , 7.5 * MINUTE_IN_SECONDS ); // OK.
52- wp_cache_replace ( $ testing , $ data , '' , 500 * 0.1 ); // Bad.
52+ wp_cache_replace ( $ testing , $ data , '' , 500 * 0.1 , ); // Bad.
5353
5454// Test comment handling.
5555wp_cache_add ( 'test ' , $ data , $ group , /* Deliberately left empty */ ); // OK.
@@ -71,11 +71,11 @@ wp_cache_add(
7171); // OK.
7272
7373// Test variable/constant with or without calculation being passed.
74- wp_cache_set ( $ key , $ data , '' , $ time ); // Manual inspection warning.
74+ WP_Cache_Set ( $ key , $ data , '' , $ time ); // Manual inspection warning.
7575wp_cache_set ( $ key , $ data , '' , PREFIX_FIVE_MINUTES ); // Manual inspection warning.
7676wp_cache_set ( $ key , $ data , '' , 20 * $ time ); // Manual inspection warning.
77- wp_cache_set ( $ key , $ data , '' , $ base + $ extra ); // Manual inspection warning.
78- wp_cache_set ( $ key , $ data , '' , 300 + $ extra ); // Manual inspection warning.
77+ wp_cache_set ( $ key , $ data , '' , $ base + $ extra, ); // Manual inspection warning.
78+ \ wp_cache_set ( $ key , $ data , '' , 300 + $ extra ); // Manual inspection warning.
7979wp_cache_set ( $ key , $ data , '' , PREFIX_CUSTOM_TIME * 5 ); // Manual inspection warning.
8080
8181// Test calculations with additional aritmetic operators.
@@ -84,7 +84,7 @@ wp_cache_add( 'test', $data, $group, WEEK_IN_SECONDS / 3 + HOUR_IN_SECONDS ); /
8484
8585// Test calculations grouped with parentheses.
8686wp_cache_set ( $ key , $ data , '' , (24 * 60 * 60 ) ); // OK.
87- wp_cache_set ( $ key , $ data , '' , (-(2 * 60 ) + 600 ) ); // OK.
87+ wp_cache_set ( $ key , $ data , '' , (-(2 * 60 ) + 600 ), ); // OK.
8888wp_cache_set ( $ key , $ data , '' , (2 * 60 ) ); // Bad.
8989
9090
@@ -113,11 +113,27 @@ wp_cache_set( 'test', $data, $group, month_in_seconds ); // Bad - constants are
113113wp_cache_set ( 'test ' , $ data , $ group , HOUR_IN_SECONDS ::methodName () ); // Bad - not a constant.
114114wp_cache_set ( 'test ' , $ data , $ group , $ obj ->MONTH_IN_SECONDS ); // Bad - not a constant.
115115wp_cache_set ( 'test ' , $ data , $ group , $ obj ::MONTH_IN_SECONDS ); // Bad - not the WP constant.
116- wp_cache_set ( 'test ' , $ data , $ group , PluginNamespace \SubLevel \DAY_IN_SECONDS ); // Bad - not the WP constant.
116+ WP_Cache_Set ( 'test ' , $ data , $ group , PluginNamespace \SubLevel \DAY_IN_SECONDS , ); // Bad - not the WP constant.
117117
118118// Test passing negative number as cache time.
119119wp_cache_set ( 'test ' , $ data , $ group , -300 ); // Bad.
120120wp_cache_add ( $ testing , $ data , 'test_group ' , -6 * MINUTE_IN_SECONDS ); // Bad.
121121
122122// Test more complex logic in the parameter.
123123wp_cache_add ( $ key , $ data , '' , ($ toggle ? 200 : 400 ) ); // Manual inspection warning.
124+
125+ // Test handling of non-numeric data in text string.
126+ wp_cache_set ( 'test ' , $ data , $ group , '' ); // Manual inspection warning.
127+ wp_cache_set ( 'test ' , $ data , $ group , '300 Mulberry Street ' ); // Manual inspection warning.
128+
129+ // Test handling of edge case/parse error.
130+ wp_cache_set ( 'test ' , $ data , $ group ,\); // OK, ignore.
131+
132+ // Test handling of some modern PHP syntaxes.
133+ wp_cache_add ('test ' , $ data , $ group , ...$ params ); // PHP 5.6 argument unpacking. Manual inspection warning.
134+ wp_cache_add ( $ key , $ data , '' , $ toggle ?? 400 ) ); // PHP 7.0 null coalesce. Manual inspection warning.
135+ add_action ('my_action ' , wp_cache_set (...)); // PHP 8.1 first class callable. OK, ignore.
136+
137+ // Looks like a function call, but is a PHP 8.0+ class instantiation via an attribute.
138+ #[WP_Cache_Replace('text ' , 'data ' , 'group ' , 50 )]
139+ function foo () {}
0 commit comments