♻️ Refactores parser

For #4
This commit is contained in:
Shikiryu committed 2023-04-06 11:07:06 +02:00
1 parent 4783124a1d
commit bc0e818bbc
11 files changed
+438 -337

No files matched your search

+17 -1
View File
@@ -4,7 +4,7 @@ namespace Shikiryu\SRSS\Entity;
use Shikiryu\SRSS\Entity\Channel\Image;
class Channel
class Channel implements SRSSElement
{
public string $title;
public string $link;
@@ -28,4 +28,20 @@ class Channel
public ?string $skipDays;
public array $required = ['title', 'link', 'description'];
/**
* @return bool
*/
public function isValid(): bool
{
return count(array_filter($this->required, fn($field) => !empty($this->{$field}))) === 0;
}
/**
* @return array
*/
public function toArray(): array
{
return get_object_vars($this);
}
}
+16 -1
View File
@@ -2,7 +2,7 @@
namespace Shikiryu\SRSS\Entity;
class Item
class Item implements SRSSElement
{
public ?string $title;
public ?string $link;
@@ -15,5 +15,20 @@ class Item
public ?string $pubDate;
public ?string $source;
/**
* @var \Shikiryu\SRSS\Entity\Media\Content[]
*/
public array $medias = [];
public array $required = ['description'];
public function isValid(): bool
{
return count(array_filter($this->required, fn($field) => !empty($this->{$field}))) === 0;
}
public function toArray(): array
{
return get_object_vars($this);
}
}
-1
View File
@@ -58,7 +58,6 @@ class Content extends DomDocument
}
}
/**
* main getter for properties
*
+16
View File
@@ -0,0 +1,16 @@
<?php
namespace Shikiryu\SRSS\Entity;
interface SRSSElement
{
/**
* @return bool
*/
public function isValid(): bool;
/**
* @return array
*/
public function toArray(): array;
}