Completed
Pull Request — master (#41)
by Níckolas Daniel
05:03
created

JigsawParticipantRepository::all()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 15
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 21
ccs 15
cts 15
cp 1
rs 9.7666
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
namespace PODEntender\Infrastructure\Domain\Model\Participant;
4
5
use PODEntender\Domain\Model\Participant\Participant;
6
use PODEntender\Domain\Model\Participant\ParticipantCollection;
7
use PODEntender\Domain\Model\Participant\ParticipantRepository;
8
use TightenCo\Jigsaw\Jigsaw;
9
use TightenCo\Jigsaw\PageVariable;
10
11
class JigsawParticipantRepository implements ParticipantRepository
12
{
13
    private $jigsaw;
14
15 2
    public function __construct(Jigsaw $jigsaw)
16
    {
17 2
        $this->jigsaw = $jigsaw;
18 2
    }
19
20 1
    public function all(): ParticipantCollection
21
    {
22 1
        return new ParticipantCollection(
23 1
            $this->jigsaw
24 1
                ->getCollection('episodes')
25
                ->filter(function (PageVariable $page) {
26 1
                    return count($page->participants ?? []) > 0;
0 ignored issues
show
Bug introduced by
It seems like $page->participants ?? array() can also be of type Illuminate\Support\HigherOrderCollectionProxy; however, parameter $var of count() does only seem to accept Countable|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

26
                    return count(/** @scrutinizer ignore-type */ $page->participants ?? []) > 0;
Loading history...
27 1
                })
28
                ->map(function (PageVariable $page) {
29 1
                    return $page->participants;
30 1
                })
31 1
                ->flatten(1)
32
                ->map(function (array $participantMap) {
33 1
                    return new Participant(
34 1
                        $participantMap['name'],
35 1
                        $participantMap['picture'],
36 1
                        $participantMap['description']
37
                    );
38 1
                })
39
                ->unique(function (Participant $participant) {
40 1
                    return $participant->name();
41 1
                })
42
        );
43
    }
44
45 1
    public function byEpisode(string $number): ParticipantCollection
46
    {
47 1
        return new ParticipantCollection(
48 1
            $this->jigsaw
49 1
                ->getCollection('episodes')
50
                ->filter(function (PageVariable $page) use ($number) {
51 1
                    return $page->episode['number'] === $number && count($page->participants ?? []) > 0;
0 ignored issues
show
Bug introduced by
It seems like $page->participants ?? array() can also be of type Illuminate\Support\HigherOrderCollectionProxy; however, parameter $var of count() does only seem to accept Countable|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

51
                    return $page->episode['number'] === $number && count(/** @scrutinizer ignore-type */ $page->participants ?? []) > 0;
Loading history...
52 1
                })
53
                ->map(function (PageVariable $page) {
54 1
                    return $page->participants;
55 1
                })
56 1
                ->flatten(1)
57
                ->map(function (array $participantMap) {
58 1
                    return new Participant(
59 1
                        $participantMap['name'],
60 1
                        $participantMap['picture'],
61 1
                        $participantMap['description']
62
                    );
63 1
                })
64
        );
65
    }
66
}
67