PODEntender /
estatista
| 1 | <?php |
||||
| 2 | |||||
| 3 | namespace PODEntender\Infrastructure\Domain\Factory; |
||||
| 4 | |||||
| 5 | use PODEntender\Domain\Model\FileProcessing\RssFeedConfiguration; |
||||
| 6 | use PODEntender\Domain\Model\Post\AudioEpisode; |
||||
| 7 | use PODEntender\Domain\Model\Post\Post; |
||||
| 8 | use PODEntender\Domain\Model\Post\PostImage; |
||||
| 9 | use PODEntender\Domain\Model\Post\PostImageCollection; |
||||
| 10 | use TightenCo\Jigsaw\PageVariable; |
||||
| 11 | |||||
| 12 | class JigsawPostFactory |
||||
| 13 | { |
||||
| 14 | private $feedConfiguration; |
||||
| 15 | |||||
| 16 | 4 | public function __construct(RssFeedConfiguration $feedConfiguration) |
|||
| 17 | { |
||||
| 18 | 4 | $this->feedConfiguration = $feedConfiguration; |
|||
| 19 | 4 | } |
|||
| 20 | |||||
| 21 | 3 | public function newPostFromPageVariable(PageVariable $page): Post |
|||
| 22 | { |
||||
| 23 | 3 | $date = new \DateTime(); |
|||
| 24 | |||||
| 25 | 3 | $episode = $page->episode; |
|||
| 26 | |||||
| 27 | 3 | return new Post( |
|||
| 28 | 3 | $page->episode['guid'] ?? $page->getUrl(), |
|||
| 29 | 3 | $page->getUrl(), |
|||
| 30 | 3 | $episode['title'], |
|||
| 31 | 3 | $episode['description'], |
|||
| 32 | 3 | $episode['author'], |
|||
| 33 | 3 | $page->getContent(), |
|||
| 34 | 3 | $page->category, |
|||
| 35 | 3 | $this->createImageCollectionFromPageVariable($page), |
|||
| 36 | 3 | $page->tags ?? [], |
|||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||
| 37 | 3 | \DateTimeImmutable::createFromMutable($date->setTimestamp($page->date)), |
|||
|
0 ignored issues
–
show
It seems like
$page->date can also be of type Illuminate\Support\HigherOrderCollectionProxy; however, parameter $unixtimestamp of DateTime::setTimestamp() does only seem to accept integer, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 38 | 3 | \DateTimeImmutable::createFromMutable($date->setTimestamp($episode['date'])) |
|||
| 39 | ); |
||||
| 40 | } |
||||
| 41 | |||||
| 42 | 1 | public function newAudioEpisodeFromPageVariable(PageVariable $page): AudioEpisode |
|||
| 43 | { |
||||
| 44 | 1 | $date = new \DateTime(); |
|||
| 45 | |||||
| 46 | 1 | $episode = $page->episode; |
|||
| 47 | |||||
| 48 | 1 | $episode = new AudioEpisode( |
|||
| 49 | 1 | $page->episode['guid'] ?? $page->getUrl(), |
|||
| 50 | 1 | $page->getUrl(), |
|||
| 51 | 1 | $episode['title'], |
|||
| 52 | 1 | $episode['description'], |
|||
| 53 | 1 | $episode['author'] ?? '', |
|||
| 54 | 1 | $page->getContent(), |
|||
| 55 | 1 | $page->get('category'), |
|||
| 56 | 1 | $this->createImageCollectionFromPageVariable($page), |
|||
| 57 | 1 | $page->tags ?? [], |
|||
|
0 ignored issues
–
show
It seems like
$page->tags ?? array() can also be of type Illuminate\Support\HigherOrderCollectionProxy; however, parameter $tags of PODEntender\Domain\Model...oEpisode::__construct() does only seem to accept array, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 58 | 1 | \DateTimeImmutable::createFromMutable($date->setTimestamp($page->date)), |
|||
|
0 ignored issues
–
show
It seems like
$page->date can also be of type Illuminate\Support\HigherOrderCollectionProxy; however, parameter $unixtimestamp of DateTime::setTimestamp() does only seem to accept integer, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 59 | 1 | \DateTimeImmutable::createFromMutable($date->setTimestamp($episode['date'])), |
|||
| 60 | 1 | $this->feedConfiguration->explicit(), |
|||
| 61 | 1 | $episode['audioDuration'] ?? '00:00:00', |
|||
| 62 | 1 | $episode['audioUrl'], |
|||
| 63 | 1 | $page->getBaseUrl() . $episode['cover']['url'] ?? '' |
|||
| 64 | ); |
||||
| 65 | |||||
| 66 | 1 | foreach ($page->redirects ?? [] as $url) { |
|||
| 67 | $episode->addRedirect($url); |
||||
| 68 | } |
||||
| 69 | |||||
| 70 | 1 | return $episode; |
|||
| 71 | } |
||||
| 72 | |||||
| 73 | 4 | private function createImageCollectionFromPageVariable(PageVariable $page): PostImageCollection |
|||
| 74 | { |
||||
| 75 | 4 | $episode = $page->episode; |
|||
| 76 | |||||
| 77 | 4 | $cover = new PostImage( |
|||
| 78 | 4 | $page->getBaseUrl() . $episode['cover']['url'], |
|||
| 79 | 4 | $episode['cover']['title'] ?? '', |
|||
| 80 | 4 | $episode['cover']['alt'] ?? '', |
|||
| 81 | 4 | true |
|||
| 82 | ); |
||||
| 83 | |||||
| 84 | 4 | return new PostImageCollection([$cover]); |
|||
| 85 | } |
||||
| 86 | } |
||||
| 87 |