Test Failed
Push — 0.6 ( 1e942f...a96f06 )
by Ben
05:42 queued 01:43
created

SortAssets   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 18
rs 10
c 0
b 0
f 0
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 8 2
1
<?php
2
3
namespace Thinktomorrow\AssetLibrary\Application;
4
5
use Thinktomorrow\AssetLibrary\HasAsset;
6
7
class SortAssets
8
{
9
    /**
10
     * Remove the asset and attaches a new one.
11
     *
12
     * @param $replace
13
     * @param $with
14
     * @throws \Spatie\MediaLibrary\Exceptions\FileCannotBeAdded
15
     * @throws \Thinktomorrow\AssetLibrary\Exceptions\AssetUploadException
16
     */
17
    public function handle(HasAsset $model, $type, $sorting)
18
    {
19
        $files = $model->assets($type);
20
        $files->each(function ($asset) use ($model, $sorting) {
21
            if (in_array($asset->id, $sorting)) {
22
                $pivot = $model->assetRelation->find($asset->id)->pivot;
0 ignored issues
show
Bug introduced by
Accessing assetRelation on the interface Thinktomorrow\AssetLibrary\HasAsset suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
23
                $pivot->order = array_search($asset->id, $sorting);
24
                $pivot->save();
25
            }
26
        });
27
    }
28
}
29