Total Complexity | 6 |
Total Lines | 61 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
11 | trait HasMediaExtended |
||
12 | { |
||
13 | use HasMediaTrait; |
||
14 | |||
15 | /** |
||
16 | * Get the last media item of a media collection. |
||
17 | * |
||
18 | * @return Media|null |
||
19 | */ |
||
20 | public function getLastMedia(string $collectionName = 'default', array $filters = []) |
||
21 | { |
||
22 | $media = $this->getMedia($collectionName, $filters); |
||
23 | |||
24 | return $media->sortByDesc('created_at')->first(); |
||
25 | } |
||
26 | |||
27 | /* |
||
28 | * Get the url of the image for the given conversionName |
||
29 | * for first media for the given collectionName. |
||
30 | * If no profile is given, return the source's url. |
||
31 | */ |
||
32 | public function getLastMediaUrl(string $collectionName = 'default', string $conversionName = ''): string |
||
33 | { |
||
34 | $media = $this->getLastMedia($collectionName); |
||
35 | |||
36 | if (! $media) { |
||
37 | return ''; |
||
38 | } |
||
39 | |||
40 | return $media->getUrl($conversionName); |
||
41 | } |
||
42 | |||
43 | /** |
||
44 | * Register Media Conversion. |
||
45 | * |
||
46 | * @param \Spatie\MediaLibrary\Models\Media $media |
||
47 | */ |
||
48 | public function registerMediaConversions(Media $media = null) |
||
49 | { |
||
50 | $dimensions = $this->getMediaDimensions(); |
||
51 | |||
52 | foreach ($dimensions as $dimension => $collection) { |
||
53 | $this->addMediaConversion($collection) |
||
54 | ->width($dimension) |
||
55 | ->height($dimension) |
||
56 | ->performOnCollections($collection); |
||
57 | } |
||
58 | } |
||
59 | |||
60 | /** |
||
61 | * List of dimension and it's collection name. |
||
62 | */ |
||
63 | public function getMediaDimensions(): array |
||
72 | ]; |
||
73 | } |
||
74 | } |
||
75 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths