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

Prevent fatals with the Howto block in rare situations #21332

Open
wants to merge 6 commits into
base: trunk
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Simplify and prevent warnings
  • Loading branch information
Djennez committed May 7, 2024
commit f1f0860b8bea807cc5b6b712c2c566f2161f5609
6 changes: 3 additions & 3 deletions src/generators/schema/howto.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
/**
* Renders a list of questions, referencing them by ID.
*
* @return array Our Schema graph.

Check failure on line 24 in src/generators/schema/howto.php

View workflow job for this annotation

GitHub Actions / Check code style

@return annotation of method \Yoast\WP\SEO\Generators\Schema\HowTo::generate() does not specify type hint for items of its traversable return value.

Check failure on line 24 in src/generators/schema/howto.php

View workflow job for this annotation

GitHub Actions / Check code style

@return annotation of method \Yoast\WP\SEO\Generators\Schema\HowTo::generate() does not specify type hint for items of its traversable return value.
*/
public function generate() {
$graph = [];
Expand All @@ -36,8 +36,8 @@
/**
* Adds the duration of the task to the Schema.
*
* @param array $data Our How-To schema data.

Check failure on line 39 in src/generators/schema/howto.php

View workflow job for this annotation

GitHub Actions / Check code style

@param annotation of method \Yoast\WP\SEO\Generators\Schema\HowTo::add_duration() does not specify type hint for items of its traversable parameter $data.

Check failure on line 39 in src/generators/schema/howto.php

View workflow job for this annotation

GitHub Actions / Check code style

@param annotation of method \Yoast\WP\SEO\Generators\Schema\HowTo::add_duration() does not specify type hint for items of its traversable parameter $data.
* @param array $attributes The block data attributes.

Check failure on line 40 in src/generators/schema/howto.php

View workflow job for this annotation

GitHub Actions / Check code style

@param annotation of method \Yoast\WP\SEO\Generators\Schema\HowTo::add_duration() does not specify type hint for items of its traversable parameter $attributes.

Check failure on line 40 in src/generators/schema/howto.php

View workflow job for this annotation

GitHub Actions / Check code style

@param annotation of method \Yoast\WP\SEO\Generators\Schema\HowTo::add_duration() does not specify type hint for items of its traversable parameter $attributes.
*
* @return void
*/
Expand All @@ -46,9 +46,9 @@
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 );

Check failure on line 49 in src/generators/schema/howto.php

View workflow job for this annotation

GitHub Actions / Check code style

Operation must be bracketed

Check failure on line 49 in src/generators/schema/howto.php

View workflow job for this annotation

GitHub Actions / Check code style

Operation must be bracketed
$hours = \intval( $attributes['hours'] ?? 0 );

Check failure on line 50 in src/generators/schema/howto.php

View workflow job for this annotation

GitHub Actions / Check code style

Operation must be bracketed

Check failure on line 50 in src/generators/schema/howto.php

View workflow job for this annotation

GitHub Actions / Check code style

Operation must be bracketed
$minutes = \intval( $attributes['minutes'] ?? 0 );

Check failure on line 51 in src/generators/schema/howto.php

View workflow job for this annotation

GitHub Actions / Check code style

Operation must be bracketed

Check failure on line 51 in src/generators/schema/howto.php

View workflow job for this annotation

GitHub Actions / Check code style

Operation must be bracketed

if ( ( $days + $hours + $minutes ) > 0 ) {
$data['totalTime'] = \esc_attr( 'P' . $days . 'DT' . $hours . 'H' . $minutes . 'M' );
Expand All @@ -58,8 +58,8 @@
/**
* Adds the steps to our How-To output.
*
* @param array $data Our How-To schema data.

Check failure on line 61 in src/generators/schema/howto.php

View workflow job for this annotation

GitHub Actions / Check code style

@param annotation of method \Yoast\WP\SEO\Generators\Schema\HowTo::add_steps() does not specify type hint for items of its traversable parameter $data.

Check failure on line 61 in src/generators/schema/howto.php

View workflow job for this annotation

GitHub Actions / Check code style

@param annotation of method \Yoast\WP\SEO\Generators\Schema\HowTo::add_steps() does not specify type hint for items of its traversable parameter $data.
* @param array $steps Our How-To block's steps.

Check failure on line 62 in src/generators/schema/howto.php

View workflow job for this annotation

GitHub Actions / Check code style

@param annotation of method \Yoast\WP\SEO\Generators\Schema\HowTo::add_steps() does not specify type hint for items of its traversable parameter $steps.

Check failure on line 62 in src/generators/schema/howto.php

View workflow job for this annotation

GitHub Actions / Check code style

@param annotation of method \Yoast\WP\SEO\Generators\Schema\HowTo::add_steps() does not specify type hint for items of its traversable parameter $steps.
*
* @return void
*/
Expand Down Expand Up @@ -115,7 +115,7 @@
/**
* Checks if we have a step description, if we do, add it.
*
* @param array $schema_step Our Schema output for the Step.

Check failure on line 118 in src/generators/schema/howto.php

View workflow job for this annotation

GitHub Actions / Check code style

@param annotation of method \Yoast\WP\SEO\Generators\Schema\HowTo::add_step_description() does not specify type hint for items of its traversable parameter $schema_step.

Check failure on line 118 in src/generators/schema/howto.php

View workflow job for this annotation

GitHub Actions / Check code style

@param annotation of method \Yoast\WP\SEO\Generators\Schema\HowTo::add_step_description() does not specify type hint for items of its traversable parameter $schema_step.
* @param string $json_text The step text.
*
* @return void
Expand All @@ -132,7 +132,7 @@
/**
* Checks if we have a step image, if we do, add it.
*
* @param array $schema_step Our Schema output for the Step.

Check failure on line 135 in src/generators/schema/howto.php

View workflow job for this annotation

GitHub Actions / Check code style

@param annotation of method \Yoast\WP\SEO\Generators\Schema\HowTo::add_step_image() does not specify type hint for items of its traversable parameter $schema_step.

Check failure on line 135 in src/generators/schema/howto.php

View workflow job for this annotation

GitHub Actions / Check code style

@param annotation of method \Yoast\WP\SEO\Generators\Schema\HowTo::add_step_image() does not specify type hint for items of its traversable parameter $schema_step.
* @param array $step The step block data.
*
* @return void
Expand Down