Skip to content

Commit 2b500b4

Browse files
swissspidyclaude
andcommitted
Give the modification date a type PHPStan can follow
The pair was collected into an array with both keys optional, so nothing told PHPStan that reaching the consistency check meant at least one of them was present, and the values stayed mixed all the way into get_gmt_from_date() and get_date_from_gmt(). Two scalars say the same thing in a way the analyser can follow, and the array is built once both are known. is_scalar() guards the cast: a value that is not scalar could not be a date anyway, and casting one to string is what the strict rule is there to prevent. No behaviour change - `! empty()` still decides whether each was given, and the pair is still completed from whichever half arrived. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014SSZzqMJRDTiLiDxQEPYcL
1 parent 8ff4d0c commit 2b500b4

1 file changed

Lines changed: 17 additions & 13 deletions

File tree

‎src/Post_Command.php‎

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -281,25 +281,29 @@ function ( $params ) {
281281
* no modification date was requested.
282282
*/
283283
private static function add_post_modified_filter( $params ) {
284-
$modified = [];
285-
286-
foreach ( [ 'post_modified', 'post_modified_gmt' ] as $key ) {
287-
if ( ! empty( $params[ $key ] ) ) {
288-
$modified[ $key ] = $params[ $key ];
289-
}
290-
}
291-
292-
if ( empty( $modified ) ) {
284+
$local = ! empty( $params['post_modified'] ) && is_scalar( $params['post_modified'] )
285+
? (string) $params['post_modified']
286+
: null;
287+
$gmt = ! empty( $params['post_modified_gmt'] ) && is_scalar( $params['post_modified_gmt'] )
288+
? (string) $params['post_modified_gmt']
289+
: null;
290+
291+
if ( null === $local && null === $gmt ) {
293292
return null;
294293
}
295294

296295
// Keep the pair consistent when only one of the two was given.
297-
if ( ! isset( $modified['post_modified_gmt'] ) ) {
298-
$modified['post_modified_gmt'] = get_gmt_from_date( $modified['post_modified'] );
299-
} elseif ( ! isset( $modified['post_modified'] ) ) {
300-
$modified['post_modified'] = get_date_from_gmt( $modified['post_modified_gmt'] );
296+
if ( null === $gmt ) {
297+
$gmt = get_gmt_from_date( $local );
298+
} elseif ( null === $local ) {
299+
$local = get_date_from_gmt( $gmt );
301300
}
302301

302+
$modified = [
303+
'post_modified' => $local,
304+
'post_modified_gmt' => $gmt,
305+
];
306+
303307
$callback = static function ( $data ) use ( $modified ) {
304308
return array_merge( $data, $modified );
305309
};

0 commit comments

Comments
 (0)