ReplaceAsset   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 18
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
use Spatie\MediaLibrary\MediaCollections\Exceptions\FileCannotBeAdded;
8
9
class ReplaceAsset
10
{
11
    /**
12
     * Remove the asset and attaches a new one.
13
     *
14
     * @param $replace
15
     * @param $with
16
     * @param $type
17
     * @param $locale
18
     * @throws FileCannotBeAdded
19
     */
20 3
    public function handle(HasAsset $model, $replace, $with, $type, $locale)
21
    {
22 3
        $old = $model->assetRelation()->findOrFail($replace);
23
24 3
        app(AddAsset::class)->add($model, Asset::findOrFail($with), $type, $locale);
25
26 3
        app(DetachAsset::class)->detach($model, $old->id, $type, $locale);
0 ignored issues
show
Bug introduced by
The method detach() does not exist on Illuminate\Contracts\Foundation\Application. ( Ignorable by Annotation )

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

26
        app(DetachAsset::class)->/** @scrutinizer ignore-call */ detach($model, $old->id, $type, $locale);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Bug introduced by
The type Thinktomorrow\AssetLibrary\Application\DetachAsset 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...
27 3
    }
28
}
29