Passed
Push — master ( 9aef17...9e5266 )
by Gabriel
05:26
created

HasMediaTrait::hydrateMediaRepository()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 13
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3.2098

Importance

Changes 2
Bugs 1 Features 1
Metric Value
cc 3
eloc 6
c 2
b 1
f 1
nc 4
nop 1
dl 0
loc 13
ccs 5
cts 7
cp 0.7143
crap 3.2098
rs 10
1
<?php
2
3
namespace ByTIC\MediaLibrary\HasMedia;
4
5
use ByTIC\MediaLibrary\Collections\Collection;
6
use ByTIC\MediaLibrary\HasMedia\StandardCollections\FilesShortcodes;
7
use ByTIC\MediaLibrary\HasMedia\StandardCollections\ImageShortcodes;
8
use ByTIC\MediaLibrary\MediaRepository\HasMediaRepositoryTrait;
9
use ByTIC\MediaLibrary\MediaRepository\MediaRepository;
10
11
/**
12
 * Trait HasMediaTrait.
13
 */
14
trait HasMediaTrait
15
{
16 1
    use HasMediaRepositoryTrait;
17 1
    use Traits\AddMediaTrait;
18 1
    use Traits\HasMediaFilesystemTrait;
19 1
    use Traits\HasMediaConversionsTrait;
20 1
    use Traits\HasMediaConstraintsTrait;
21 1
    use Traits\HasMediaPropertiesTrait;
22 1
    use ImageShortcodes;
23 1
    use FilesShortcodes;
24
25
    /**
26
     * Get media collection by its collectionName.
27
     *
28
     * @param string         $collectionName
29
     * @param array|callable $filters
30
     *
31
     * @return Collection
32
     */
33 7
    public function getMedia(string $collectionName = 'default', $filters = []): Collection
34
    {
35 7
        return $this->getMediaRepository()->getFilteredCollection($collectionName, $filters);
0 ignored issues
show
Bug introduced by
It seems like $filters can also be of type callable; however, parameter $filter of ByTIC\MediaLibrary\Media...getFilteredCollection() 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

35
        return $this->getMediaRepository()->getFilteredCollection($collectionName, /** @scrutinizer ignore-type */ $filters);
Loading history...
36
    }
37
38
    /**
39
     * @param MediaRepository $mediaRepository
40
     *
41
     * @return MediaRepository
42
     */
43 7
    protected function hydrateMediaRepository($mediaRepository)
44
    {
45 7
        $mediaRepository->setRecord($this);
0 ignored issues
show
Bug introduced by
$this of type ByTIC\MediaLibrary\HasMedia\HasMediaTrait is incompatible with the type Nip\Records\Record expected by parameter $record of ByTIC\MediaLibrary\Media...Repository::setRecord(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

45
        $mediaRepository->setRecord(/** @scrutinizer ignore-type */ $this);
Loading history...
46
47 7
        if (method_exists($this, 'registerMediaCollections')) {
48
            $this->registerMediaCollections($mediaRepository);
49
        }
50
51 7
        if (method_exists($this, 'hydrateMediaRepositoryCustom')) {
52
            $this->hydrateMediaRepositoryCustom($mediaRepository);
53
        }
54
55 7
        return $mediaRepository;
56
    }
57
}
58