Completed
Push — master ( 079626...bbb9de )
by Níckolas Daniel
04:49
created

createImageCollectionFromPageVariable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 12
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
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,
1 ignored issue
show
Bug introduced by
It seems like $page->category can also be of type Illuminate\Support\HigherOrderCollectionProxy; however, parameter $category of PODEntender\Domain\Model\Post\Post::__construct() does only seem to accept string, 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 ignore-type  annotation

34
            /** @scrutinizer ignore-type */ $page->category,
Loading history...
35 3
            $this->createImageCollectionFromPageVariable($page),
36 3
            $page->tags ?? [],
0 ignored issues
show
Bug introduced by
It seems like $page->tags ?? array() can also be of type Illuminate\Support\HigherOrderCollectionProxy; however, parameter $tags of PODEntender\Domain\Model\Post\Post::__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 ignore-type  annotation

36
            /** @scrutinizer ignore-type */ $page->tags ?? [],
Loading history...
37 3
            \DateTimeImmutable::createFromMutable($date->setTimestamp($page->date)),
0 ignored issues
show
Bug introduced by
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 ignore-type  annotation

37
            \DateTimeImmutable::createFromMutable($date->setTimestamp(/** @scrutinizer ignore-type */ $page->date)),
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
        return 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
Bug introduced by
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 ignore-type  annotation

57
            /** @scrutinizer ignore-type */ $page->tags ?? [],
Loading history...
58 1
            \DateTimeImmutable::createFromMutable($date->setTimestamp($page->date)),
0 ignored issues
show
Bug introduced by
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 ignore-type  annotation

58
            \DateTimeImmutable::createFromMutable($date->setTimestamp(/** @scrutinizer ignore-type */ $page->date)),
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
67 4
    private function createImageCollectionFromPageVariable(PageVariable $page): PostImageCollection
68
    {
69 4
        $episode = $page->episode;
70
71 4
        $cover = new PostImage(
72 4
            $page->getBaseUrl() . $episode['cover']['url'],
73 4
            $episode['cover']['title'] ?? '',
74 4
            $episode['cover']['alt'] ?? '',
75 4
            true
76
        );
77
78 4
        return new PostImageCollection([$cover]);
79
    }
80
}
81