Completed
Pull Request — master (#38)
by Philippe
08:29 queued 04:23
created

SortAssets   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 18
ccs 6
cts 6
cp 1
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 8 2
1
<?php
2
3
namespace Thinktomorrow\AssetLibrary\Models\Application;
4
5
use Thinktomorrow\AssetLibrary\Models\Asset;
6
use Thinktomorrow\AssetLibrary\Interfaces\HasAsset;
7
8
class SortAssets
9
{
10
    /**
11
     * Remove the asset and attaches a new one.
12
     *
13
     * @param $replace
14
     * @param $with
15
     * @throws \Spatie\MediaLibrary\Exceptions\FileCannotBeAdded
16
     * @throws \Thinktomorrow\AssetLibrary\Exceptions\AssetUploadException
17
     */
18 2
    public function handle(HasAsset $model, $type, $sorting)
19
    {
20 2
        $files = $model->assets($type);
0 ignored issues
show
Bug introduced by
The method assets() does not exist on Thinktomorrow\AssetLibrary\Interfaces\HasAsset. Since it exists in all sub-types, consider adding an abstract or default implementation to Thinktomorrow\AssetLibrary\Interfaces\HasAsset. ( Ignorable by Annotation )

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

20
        /** @scrutinizer ignore-call */ 
21
        $files = $model->assets($type);
Loading history...
21
        $files->each(function ($asset) use ($model, $sorting) {
22 2
            if (in_array($asset->id, $sorting)) {
23 2
                $pivot = $model->assetRelation->find($asset->id)->pivot;
0 ignored issues
show
Bug introduced by
Accessing assetRelation on the interface Thinktomorrow\AssetLibrary\Interfaces\HasAsset suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
24 2
                $pivot->order = array_search($asset->id, $sorting);
25 2
                $pivot->save();
26
            }
27 2
        });
28 2
    }
29
}
30