From 1d4346bcf6665dcb81031f2fc9e476814a92af2b Mon Sep 17 00:00:00 2001 From: Jannes Date: Tue, 23 Apr 2024 15:14:40 +0200 Subject: [PATCH 1/6] Check for numeric and always cast to int --- src/generators/schema/howto.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/generators/schema/howto.php b/src/generators/schema/howto.php index 7319cf7a400..0186f0724b4 100644 --- a/src/generators/schema/howto.php +++ b/src/generators/schema/howto.php @@ -46,9 +46,9 @@ private function add_duration( &$data, $attributes ) { return; } - $days = empty( $attributes['days'] ) ? 0 : $attributes['days']; - $hours = empty( $attributes['hours'] ) ? 0 : $attributes['hours']; - $minutes = empty( $attributes['minutes'] ) ? 0 : $attributes['minutes']; + $days = ! is_numeric( $attributes['days'] ) ? 0 : intval( $attributes['days'] ); + $hours = ! is_numeric( $attributes['hours'] ) ? 0 : intval( $attributes['hours'] ); + $minutes = ! is_numeric( $attributes['minutes'] ) ? 0 : intval( $attributes['minutes'] ); if ( ( $days + $hours + $minutes ) > 0 ) { $data['totalTime'] = \esc_attr( 'P' . $days . 'DT' . $hours . 'H' . $minutes . 'M' ); From 1bc34419f39b446641d91edaa33658296985df7d Mon Sep 17 00:00:00 2001 From: Jannes Date: Tue, 23 Apr 2024 15:40:34 +0200 Subject: [PATCH 2/6] Check for numeric and always cast to float --- src/generators/schema/howto.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/generators/schema/howto.php b/src/generators/schema/howto.php index 0186f0724b4..0bf8fe6db72 100644 --- a/src/generators/schema/howto.php +++ b/src/generators/schema/howto.php @@ -46,9 +46,9 @@ private function add_duration( &$data, $attributes ) { return; } - $days = ! is_numeric( $attributes['days'] ) ? 0 : intval( $attributes['days'] ); - $hours = ! is_numeric( $attributes['hours'] ) ? 0 : intval( $attributes['hours'] ); - $minutes = ! is_numeric( $attributes['minutes'] ) ? 0 : intval( $attributes['minutes'] ); + $days = ! is_numeric( $attributes['days'] ) ? 0 : floatval( $attributes['days'] ); + $hours = ! is_numeric( $attributes['hours'] ) ? 0 : floatval( $attributes['hours'] ); + $minutes = ! is_numeric( $attributes['minutes'] ) ? 0 : floatval( $attributes['minutes'] ); if ( ( $days + $hours + $minutes ) > 0 ) { $data['totalTime'] = \esc_attr( 'P' . $days . 'DT' . $hours . 'H' . $minutes . 'M' ); From 9cbac04d73a451063b04156c278886d515db9073 Mon Sep 17 00:00:00 2001 From: Jannes Date: Tue, 23 Apr 2024 15:56:12 +0200 Subject: [PATCH 3/6] Back to intval, since we dont accept floats anyway --- src/generators/schema/howto.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/generators/schema/howto.php b/src/generators/schema/howto.php index 0bf8fe6db72..0186f0724b4 100644 --- a/src/generators/schema/howto.php +++ b/src/generators/schema/howto.php @@ -46,9 +46,9 @@ private function add_duration( &$data, $attributes ) { return; } - $days = ! is_numeric( $attributes['days'] ) ? 0 : floatval( $attributes['days'] ); - $hours = ! is_numeric( $attributes['hours'] ) ? 0 : floatval( $attributes['hours'] ); - $minutes = ! is_numeric( $attributes['minutes'] ) ? 0 : floatval( $attributes['minutes'] ); + $days = ! is_numeric( $attributes['days'] ) ? 0 : intval( $attributes['days'] ); + $hours = ! is_numeric( $attributes['hours'] ) ? 0 : intval( $attributes['hours'] ); + $minutes = ! is_numeric( $attributes['minutes'] ) ? 0 : intval( $attributes['minutes'] ); if ( ( $days + $hours + $minutes ) > 0 ) { $data['totalTime'] = \esc_attr( 'P' . $days . 'DT' . $hours . 'H' . $minutes . 'M' ); From 76d8f8f0cae9d8634b853b100b46fb2c2615e33d Mon Sep 17 00:00:00 2001 From: Jannes Date: Tue, 23 Apr 2024 16:03:28 +0200 Subject: [PATCH 4/6] CS --- src/generators/schema/howto.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/generators/schema/howto.php b/src/generators/schema/howto.php index 0186f0724b4..7d9352598be 100644 --- a/src/generators/schema/howto.php +++ b/src/generators/schema/howto.php @@ -46,9 +46,9 @@ private function add_duration( &$data, $attributes ) { return; } - $days = ! is_numeric( $attributes['days'] ) ? 0 : intval( $attributes['days'] ); - $hours = ! is_numeric( $attributes['hours'] ) ? 0 : intval( $attributes['hours'] ); - $minutes = ! is_numeric( $attributes['minutes'] ) ? 0 : intval( $attributes['minutes'] ); + $days = ! \is_numeric( $attributes['days'] ) ? 0 : \intval( $attributes['days'] ); + $hours = ! \is_numeric( $attributes['hours'] ) ? 0 : \intval( $attributes['hours'] ); + $minutes = ! \is_numeric( $attributes['minutes'] ) ? 0 : \intval( $attributes['minutes'] ); if ( ( $days + $hours + $minutes ) > 0 ) { $data['totalTime'] = \esc_attr( 'P' . $days . 'DT' . $hours . 'H' . $minutes . 'M' ); From f1f0860b8bea807cc5b6b712c2c566f2161f5609 Mon Sep 17 00:00:00 2001 From: Jannes Date: Tue, 7 May 2024 14:17:32 +0200 Subject: [PATCH 5/6] Simplify and prevent warnings --- src/generators/schema/howto.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/generators/schema/howto.php b/src/generators/schema/howto.php index 7d9352598be..2208e25b3f2 100644 --- a/src/generators/schema/howto.php +++ b/src/generators/schema/howto.php @@ -46,9 +46,9 @@ private function add_duration( &$data, $attributes ) { return; } - $days = ! \is_numeric( $attributes['days'] ) ? 0 : \intval( $attributes['days'] ); - $hours = ! \is_numeric( $attributes['hours'] ) ? 0 : \intval( $attributes['hours'] ); - $minutes = ! \is_numeric( $attributes['minutes'] ) ? 0 : \intval( $attributes['minutes'] ); + $days = \intval( $attributes['days'] ?? 0 ); + $hours = \intval( $attributes['hours'] ?? 0 ); + $minutes = \intval( $attributes['minutes'] ?? 0 ); if ( ( $days + $hours + $minutes ) > 0 ) { $data['totalTime'] = \esc_attr( 'P' . $days . 'DT' . $hours . 'H' . $minutes . 'M' ); From 296635913ba5356df77a47c4b330588808a6718f Mon Sep 17 00:00:00 2001 From: Jannes Date: Tue, 7 May 2024 15:31:02 +0200 Subject: [PATCH 6/6] CS --- src/generators/schema/howto.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/generators/schema/howto.php b/src/generators/schema/howto.php index 2208e25b3f2..43d1ae766bc 100644 --- a/src/generators/schema/howto.php +++ b/src/generators/schema/howto.php @@ -46,9 +46,9 @@ private function add_duration( &$data, $attributes ) { return; } - $days = \intval( $attributes['days'] ?? 0 ); - $hours = \intval( $attributes['hours'] ?? 0 ); - $minutes = \intval( $attributes['minutes'] ?? 0 ); + $days = \intval( ( $attributes['days'] ?? 0 ) ); + $hours = \intval( ( $attributes['hours'] ?? 0 ) ); + $minutes = \intval( ( $attributes['minutes'] ?? 0 ) ); if ( ( $days + $hours + $minutes ) > 0 ) { $data['totalTime'] = \esc_attr( 'P' . $days . 'DT' . $hours . 'H' . $minutes . 'M' );