Skip to content

Add strict PHPStan rules for Speculative Loading#1392

Merged
westonruter merged 3 commits into
trunkfrom
add/speculation-rules-strict
Jul 24, 2024
Merged

Add strict PHPStan rules for Speculative Loading#1392
westonruter merged 3 commits into
trunkfrom
add/speculation-rules-strict

Conversation

@westonruter
Copy link
Copy Markdown
Member

@westonruter westonruter commented Jul 23, 2024

This is a follow-up to #1241 to edge closer to full strict rule compliance for PHPStan. See #1219.

See also #775.

This improves typing of functions in the Speculative Loading plugin, and consolidates the obtaining of the stored option value in the plsr_get_stored_setting_value() function.

@westonruter westonruter added [Type] Enhancement A suggestion for improvement of an existing feature [Plugin] Speculative Loading Issues for the Speculative Loading plugin (formerly Speculation Rules) skip changelog PRs that should not be mentioned in changelogs labels Jul 23, 2024
@westonruter westonruter added this to the speculation-rules n.e.x.t milestone Jul 23, 2024
@westonruter westonruter requested a review from felixarntz as a code owner July 23, 2024 19:34
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jul 23, 2024

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: westonruter <westonruter@git.wordpress.org>
Co-authored-by: swissspidy <swissspidy@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

*/
function plsr_print_speculation_rules(): void {
$rules = plsr_get_speculation_rules();
if ( empty( $rules ) ) {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function never returns an empty array, so this condition is dead code.

Comment on lines -200 to -202
if ( empty( $args['field'] ) || empty( $args['title'] ) ) { // Invalid.
return;
}
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The field and title args are always provided in plsr_add_setting_ui().

}
<?php endforeach; ?>

if ( ! empty( $args['description'] ) ) {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The description is always provided in plsr_add_setting_ui().

* }
*/
function plsr_get_stored_setting_value(): array {
return plsr_sanitize_setting( get_option( 'plsr_speculation_rules' ) );
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The plsr_sanitize_setting() function could perhaps be eliminated in favor of the JSON schema.

Base automatically changed from update/strict-rules to trunk July 23, 2024 20:25
@westonruter westonruter force-pushed the add/speculation-rules-strict branch from c77c40e to 7ffe2b1 Compare July 23, 2024 20:26
Comment thread plugins/speculation-rules/settings.php Outdated
Comment thread plugins/speculation-rules/settings.php Outdated
Comment thread plugins/speculation-rules/settings.php Outdated
@westonruter westonruter merged commit b319595 into trunk Jul 24, 2024
@westonruter westonruter deleted the add/speculation-rules-strict branch July 24, 2024 21:57
@felixarntz felixarntz added no milestone PRs that do not have a defined milestone for release and removed skip changelog PRs that should not be mentioned in changelogs labels Nov 15, 2024
@felixarntz felixarntz removed this from the speculation-rules n.e.x.t milestone Nov 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no milestone PRs that do not have a defined milestone for release [Plugin] Speculative Loading Issues for the Speculative Loading plugin (formerly Speculation Rules) [Type] Enhancement A suggestion for improvement of an existing feature

Projects

Status: Done 😃

Development

Successfully merging this pull request may close these issues.

3 participants