Passed
Push — dependabot/composer/orchestra/... ( 137c82...0b1a28 )
by
unknown
04:18
created

ReplaceAsset   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 17
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 7 1
1
<?php
2
3
namespace Thinktomorrow\AssetLibrary\Application;
4
5
use Thinktomorrow\AssetLibrary\Asset;
6
use Thinktomorrow\AssetLibrary\HasAsset;
7
8
class ReplaceAsset
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, $replace, $with)
19
    {
20 2
        $old = $model->assetRelation()->findOrFail($replace);
21
22 2
        $old->delete();
23
24 2
        app(AddAsset::class)->add($model, Asset::findOrFail($with), $old->pivot->type, $old->pivot->locale);
25 2
    }
26
}
27