WithAccessingMedia   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
c 1
b 0
f 0
dl 0
loc 21
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A getMedia() 0 19 3
1
<?php
2
3
namespace Spatie\MediaLibraryPro;
4
5
use Spatie\MediaLibrary\HasMedia;
0 ignored issues
show
Bug introduced by
The type Spatie\MediaLibrary\HasMedia was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use Spatie\MediaLibrary\MediaCollections\Models\Media;
0 ignored issues
show
Bug introduced by
The type Spatie\MediaLibrary\MediaCollections\Models\Media was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
8
trait WithAccessingMedia
9
{
10
    protected function getMedia(string $name, HasMedia $model, string $collection): array
11
    {
12
        return old($name) ? old($name) : $model
0 ignored issues
show
Bug Best Practice introduced by
The expression return old($name) ? old(...eyBy('uuid')->toArray() could return the type null|string which is incompatible with the type-hinted return array. Consider adding an additional type-check to rule them out.
Loading history...
13
            ->getMedia($collection)
14
            ->map(function (Media $media) {
15
                return [
16
                    'name' => $media->name,
17
                    'fileName' => $media->file_name,
18
                    'uuid' => $media->uuid,
19
                    'previewUrl' => $media->hasGeneratedConversion('preview') ? $media->getUrl('preview') : '',
20
                    'order' => $media->order_column,
21
                    'customProperties' => $media->custom_properties,
22
                    'extension' => $media->extension,
23
                    'size' => $media->size,
24
                    'createdAt' => $media->created_at->timestamp,
25
                ];
26
            })
27
            ->keyBy('uuid')
28
            ->toArray();
29
    }
30
}
31