RemoveSelected::canDelete()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 6
ccs 1
cts 1
cp 1
crap 1
rs 10
1
<?php
2
3
namespace Terranet\Administrator\Actions;
4
5
use Illuminate\Database\Eloquent\Model;
0 ignored issues
show
Bug introduced by
The type Illuminate\Database\Eloquent\Model 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 Illuminate\Http\Request;
7
use Terranet\Administrator\Contracts\Module;
8
use Terranet\Administrator\Traits\Actions\BatchSkeleton;
9
use Terranet\Administrator\Traits\Actions\Skeleton;
10
11
class RemoveSelected
12
{
13
    use Skeleton, BatchSkeleton;
14
15
    /**
16
     * Delete collection elements.
17
     *
18
     * @param Model $eloquent
19
     * @param Request $request
20
     *
21
     * @return mixed
22 1
     */
23
    public function handle(Model $eloquent, Request $request)
24 1
    {
25
        return $this->fetchForDelete($eloquent, $request)
26 1
            ->each(function ($item) {
27 1
                return $this->canDelete($item) ? $item->delete() : $item;
28
            });
29
    }
30
31
    /**
32
     * Check if deletion of each item is authorized.
33
     *
34
     * @param Model $eloquent
35
     *
36
     * @return bool
37 1
     */
38
    protected function canDelete(Model $eloquent)
39 1
    {
40
        /** @var Module $resource */
41
        $resource = app('scaffold.module');
0 ignored issues
show
Bug introduced by
The function app was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

41
        $resource = /** @scrutinizer ignore-call */ app('scaffold.module');
Loading history...
42
43
        return $resource->actions()->authorize('delete', $eloquent);
44
    }
45
46
    /**
47
     * @param Model $eloquent
48 1
     * @param Request $request
49
     *
50 1
     * @return \Illuminate\Database\Eloquent\Builder[]|\Illuminate\Database\Eloquent\Collection|Model[]
0 ignored issues
show
Bug introduced by
The type Illuminate\Database\Eloquent\Collection 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...
51 1
     */
52 1
    protected function fetchForDelete(Model $eloquent, Request $request)
53
    {
54
        return $eloquent->newQueryWithoutScopes()
55
            ->whereIn('id', $request->get('collection', []))
56
            ->get();
57
    }
58 1
59
    /**
60 1
     * @return string
61
     */
62
    protected function icon()
63
    {
64
        return 'fa-trash';
65
    }
66
}
67