-
Notifications
You must be signed in to change notification settings - Fork 127
Upgrade PHPStan to 1.11.6 #1325
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
Changes from all commits
70b8ed0
16e4054
4354000
2eccdc7
b05aeac
75cd653
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -533,29 +533,28 @@ function webp_uploads_update_image_references( $content ): string { | |
} | ||
|
||
// This content does not have any tag on it, move forward. | ||
// TODO: Eventually this should use the HTML API to parse out the image tags and then update them. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. or, switch to using the |
||
if ( ! preg_match_all( '/<(img)\s[^>]+>/', $content, $img_tags, PREG_SET_ORDER ) ) { | ||
return $content; | ||
} | ||
|
||
$images = array(); | ||
foreach ( $img_tags as list( $img ) ) { | ||
// Find the ID of each image by the class. | ||
if ( ! preg_match( '/wp-image-([\d]+)/i', $img, $class_name ) ) { | ||
$processor = new WP_HTML_Tag_Processor( $img ); | ||
if ( ! $processor->next_tag( array( 'tag_name' => 'IMG' ) ) ) { | ||
// This condition won't ever be met since we're iterating over the IMG tags extracted with preg_match_all() above. | ||
continue; | ||
} | ||
|
||
if ( empty( $class_name ) ) { | ||
// Find the ID of each image by the class. | ||
// TODO: It would be preferable to use the $processor->class_list() method but there seems to be some typing issues with PHPStan. | ||
$class_name = $processor->get_attribute( 'class' ); | ||
if ( ! is_string( $class_name ) || ! preg_match( '/(?:^|\s)wp-image-([1-9]\d*)(?:\s|$)/i', $class_name, $matches ) ) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is more robust than before since it constraints looking for the class name inside the |
||
continue; | ||
} | ||
|
||
// Make sure we use the last item on the list of matches. | ||
$attachment_id = (int) $class_name[1]; | ||
|
||
if ( ! $attachment_id ) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will never be zero because the regex is now |
||
continue; | ||
} | ||
|
||
$images[ $img ] = $attachment_id; | ||
$images[ $img ] = (int) $matches[1]; | ||
} | ||
|
||
$attachment_ids = array_unique( array_filter( array_values( $images ) ) ); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bah. I should have removed the comment as it is now irrelevant after 75cd653 per phpstan/phpstan#11262 (comment). I'll do so as part of another PR.