Completed
Push — master ( a81ea2...e23c5c )
by Gabriel
03:24
created

HasMediaTrait   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Test Coverage

Coverage 77.78%

Importance

Changes 3
Bugs 1 Features 1
Metric Value
eloc 15
c 3
b 1
f 1
dl 0
loc 41
ccs 7
cts 9
cp 0.7778
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getMedia() 0 3 1
A hydrateMediaRepository() 0 13 3
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
    use HasMediaRepositoryTrait;
17
    use Traits\AddMediaTrait;
18
    use Traits\HasMediaFilesystemTrait;
19
    use Traits\HasMediaConversionsTrait;
20
    use Traits\HasMediaPropertiesTrait;
21
    use ImageShortcodes;
22
    use FilesShortcodes;
23
24
    /**
25
     * Get media collection by its collectionName.
26
     *
27
     * @param string         $collectionName
28
     * @param array|callable $filters
29
     *
30
     * @return Collection
31
     */
32 7
    public function getMedia(string $collectionName = 'default', $filters = []): Collection
33
    {
34 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

34
        return $this->getMediaRepository()->getFilteredCollection($collectionName, /** @scrutinizer ignore-type */ $filters);
Loading history...
35
    }
36
37
    /**
38
     * @param MediaRepository $mediaRepository
39
     *
40
     * @return MediaRepository
41
     */
42 7
    protected function hydrateMediaRepository($mediaRepository)
43
    {
44 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

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