Skip to content

Commit

Permalink
Add type checks to fix PHPStan 1.5.4 analysis (#7025)
Browse files Browse the repository at this point in the history
  • Loading branch information
westonruter committed Apr 5, 2022
1 parent 04bcc06 commit e1082fe
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 6 additions & 2 deletions includes/sanitizers/class-amp-gallery-block-sanitizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,19 @@ public function sanitize() {
*/
protected function get_caption_element( DOMElement $img_element ) {
$figcaption_element = null;

if ( isset( $img_element->nextSibling->nodeName ) && Tag::FIGCAPTION === $img_element->nextSibling->nodeName ) {
if (
isset( $img_element->nextSibling->nodeName )
&& $img_element->nextSibling instanceof DOMElement
&& Tag::FIGCAPTION === $img_element->nextSibling->nodeName
) {
$figcaption_element = $img_element->nextSibling;
}

// If 'Link To' is selected, the image will be wrapped in an <a>, so search for the sibling of the <a>.
if (
! $figcaption_element
&& isset( $img_element->parentNode->nextSibling->nodeName )
&& $img_element->parentNode->nextSibling instanceof DOMElement
&& Tag::FIGCAPTION === $img_element->parentNode->nextSibling->nodeName
) {
$figcaption_element = $img_element->parentNode->nextSibling;
Expand Down
2 changes: 1 addition & 1 deletion includes/sanitizers/class-amp-o2-player-sanitizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ private function create_amp_o2_player( Document $dom, DOMElement $node ) {
$parent_node = $node->parentNode;

// Remove the ID from the original node so that PHP DOM doesn't fail to set it on the replacement element.
if ( $parent_node->hasAttribute( Attribute::ID ) ) {
if ( $parent_node instanceof DOMElement && $parent_node->hasAttribute( Attribute::ID ) ) {
$component_attributes['id'] = $parent_node->getAttribute( Attribute::ID );
$parent_node->removeAttribute( Attribute::ID );
}
Expand Down

0 comments on commit e1082fe

Please sign in to comment.