diff options
| author | wn_ <invalid@email.com> | 2024-12-10 20:31:16 +0000 |
|---|---|---|
| committer | wn_ <invalid@email.com> | 2024-12-14 12:26:59 +0000 |
| commit | a1bd6cea1bbb3041ee8e2ba44a80cd2ea0b8209f (patch) | |
| tree | 7b52637ba8866c2efec6eb5a0c8adb75474038d6 /classes/FeedItem_Common.php | |
| parent | 333bab90a7d4d159d001e3f0579b10cced763249 (diff) | |
Use native typing in more places and clean up 'FeedEnclosure' a bit.
Diffstat (limited to 'classes/FeedItem_Common.php')
| -rw-r--r-- | classes/FeedItem_Common.php | 61 |
1 files changed, 25 insertions, 36 deletions
diff --git a/classes/FeedItem_Common.php b/classes/FeedItem_Common.php index 1471dc3e3..5b30ab20c 100644 --- a/classes/FeedItem_Common.php +++ b/classes/FeedItem_Common.php @@ -1,19 +1,10 @@ <?php abstract class FeedItem_Common extends FeedItem { - /** @var DOMElement */ - protected $elem; - - /** @var DOMDocument */ - protected $doc; - - /** @var DOMXPath */ - protected $xpath; - - function __construct(DOMElement $elem, DOMDocument $doc, DOMXPath $xpath) { - $this->elem = $elem; - $this->xpath = $xpath; - $this->doc = $doc; - + function __construct( + protected readonly DOMElement $elem, + protected readonly DOMDocument $doc, + protected readonly DOMXPath $xpath, + ) { try { $source = $elem->getElementsByTagName("source")->item(0); @@ -97,13 +88,13 @@ abstract class FeedItem_Common extends FeedItem { $enclosures = $this->xpath->query("media:content", $this->elem); foreach ($enclosures as $enclosure) { - $enc = new FeedEnclosure(); - - $enc->type = clean($enclosure->getAttribute("type")); - $enc->link = clean($enclosure->getAttribute("url")); - $enc->length = clean($enclosure->getAttribute("length")); - $enc->height = clean($enclosure->getAttribute("height")); - $enc->width = clean($enclosure->getAttribute("width")); + $enc = new FeedEnclosure( + type: clean($enclosure->getAttribute('type')), + link: clean($enclosure->getAttribute('url')), + length: clean($enclosure->getAttribute('length')), + height: clean($enclosure->getAttribute('height')), + width: clean($enclosure->getAttribute('width')), + ); $medium = clean($enclosure->getAttribute("medium")); if (!$enc->type && $medium) { @@ -119,17 +110,17 @@ abstract class FeedItem_Common extends FeedItem { $enclosures = $this->xpath->query("media:group", $this->elem); foreach ($enclosures as $enclosure) { - $enc = new FeedEnclosure(); - /** @var DOMElement|null */ $content = $this->xpath->query("media:content", $enclosure)->item(0); if ($content) { - $enc->type = clean($content->getAttribute("type")); - $enc->link = clean($content->getAttribute("url")); - $enc->length = clean($content->getAttribute("length")); - $enc->height = clean($content->getAttribute("height")); - $enc->width = clean($content->getAttribute("width")); + $enc = new FeedEnclosure( + type: clean($content->getAttribute('type')), + link: clean($content->getAttribute('url')), + length: clean($content->getAttribute('length')), + height: clean($content->getAttribute('height')), + width: clean($content->getAttribute('width')), + ); $medium = clean($content->getAttribute("medium")); if (!$enc->type && $medium) { @@ -151,14 +142,12 @@ abstract class FeedItem_Common extends FeedItem { $enclosures = $this->xpath->query("media:thumbnail", $this->elem); foreach ($enclosures as $enclosure) { - $enc = new FeedEnclosure(); - - $enc->type = "image/generic"; - $enc->link = clean($enclosure->getAttribute("url")); - $enc->height = clean($enclosure->getAttribute("height")); - $enc->width = clean($enclosure->getAttribute("width")); - - array_push($encs, $enc); + $encs[] = new FeedEnclosure( + type: 'image/generic', + link: clean($enclosure->getAttribute('url')), + height: clean($enclosure->getAttribute('height')), + width: clean($enclosure->getAttribute('width')), + ); } return $encs; |