Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix(HttpMicrodataParser): Use concrete DOMNode sub-types to fix polym…
…orphic calls

Signed-off-by: provokateurin <[email protected]>
  • Loading branch information
provokateurin authored and christianlupus committed Mar 5, 2025
commit 00c839d10d569a0382064e182b2834b3557c19f2
13 changes: 7 additions & 6 deletions lib/Helper/HTMLParser/HttpMicrodataParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace OCA\Cookbook\Helper\HTMLParser;

use DOMDocument;
use DOMElement;
use DOMNode;
use DOMNodeList;
use DOMXPath;
Expand Down Expand Up @@ -58,9 +59,9 @@ public function parse(DOMDocument $document, ?string $url): array {
/**
* Parse a DOM node that represents a recipe
*
* @param DOMNode $recipeNode The DOM node to parse
* @param DOMElement $recipeNode The DOM node to parse
*/
private function parseRecipe(DOMNode $recipeNode): void {
private function parseRecipe(DOMElement $recipeNode): void {
$this->searchSimpleProperties($recipeNode, 'name');
$this->searchSimpleProperties($recipeNode, 'keywords');
$this->searchSimpleProperties($recipeNode, 'category');
Expand All @@ -75,9 +76,9 @@ private function parseRecipe(DOMNode $recipeNode): void {

/**
* Make one final desperate attempt at getting the instructions
* @param DOMNode $recipeNode The recipe node to use
* @param DOMElement $recipeNode The recipe node to use
*/
private function fixupInstructions(DOMNode $recipeNode): void {
private function fixupInstructions(DOMElement $recipeNode): void {
if (
!isset($this->recipe['recipeInstructions']) ||
!$this->recipe['recipeInstructions'] || sizeof($this->recipe['recipeInstructions']) < 1
Expand Down Expand Up @@ -254,12 +255,12 @@ private function extractAttribute(DOMNodeList $nodes, array $attributes): array
* This can be used to extract a single attribute from the DOM tree.
* The attributes are evaluated first to last and the first found attribute is returned.
*
* @param DOMNode $node The node to evaluate
* @param DOMElement $node The node to evaluate
* @param array $attributes The possible attributes to check
* @throws AttributeNotFoundException If none of the named attributes is found
* @return string The value of the attribute
*/
private function extractSingeAttribute(DOMNode $node, array $attributes): string {
private function extractSingeAttribute(DOMElement $node, array $attributes): string {
foreach ($attributes as $attr) {
if ($node->hasAttribute($attr) && !empty($node->getAttribute($attr))) {
return $node->getAttribute($attr);
Expand Down
8 changes: 0 additions & 8 deletions tests/psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,6 @@
<code><![CDATA[$this->setJSONValue($json, '@type', 'Recipe')]]></code>
</InvalidOperand>
</file>
<file src="lib/Helper/HTMLParser/HttpMicrodataParser.php">
<UndefinedMethod>
<code><![CDATA[getAttribute]]></code>
<code><![CDATA[getAttribute]]></code>
<code><![CDATA[getElementsByTagName]]></code>
<code><![CDATA[hasAttribute]]></code>
</UndefinedMethod>
</file>
<file src="lib/Helper/UserFolderHelper.php">
<MissingDependency>
<code><![CDATA[$this->root]]></code>
Expand Down