Test Failed
Pull Request — master (#77)
by Terzi
05:49
created

AdminRequest::resolveModel()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 5
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 11
rs 10
1
<?php
2
3
namespace Terranet\Administrator;
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\Foundation\Http\FormRequest;
0 ignored issues
show
Bug introduced by
The type Illuminate\Foundation\Http\FormRequest 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...
7
use Terranet\Administrator\Contracts\Module;
8
use Terranet\Administrator\Contracts\Services\Finder;
9
10
class AdminRequest extends FormRequest
11
{
12
    public function authorize()
13
    {
14
        return true;
15
    }
16
17
    public function rules()
18
    {
19
        return [];
20
    }
21
22
    /**
23
     * Resolve resource based on router parameters.
24
     *
25
     * @return null|Module
26
     */
27
    public function resource(): ?Module
28
    {
29
        return once(function () {
30
            return tap(Architect::resourceForKey($this->route()->parameter('module')), function ($resource) {
31
                abort_if(is_null($resource), 404);
0 ignored issues
show
Bug introduced by
The function abort_if 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

31
                /** @scrutinizer ignore-call */ 
32
                abort_if(is_null($resource), 404);
Loading history...
32
            });
33
        });
34
    }
35
36
    /**
37
     * Resolve current model.
38
     *
39
     * @param $id
40
     * @return null|Model
41
     */
42
    public function resolveModel($id): ?Model
43
    {
44
        return once(function () use ($id) {
45
            /** @var Finder $finder */
46
            $finder = $this->resource()->finder();
47
48
            if ($finder) {
0 ignored issues
show
introduced by
$finder is of type Terranet\Administrator\Contracts\Services\Finder, thus it always evaluated to true.
Loading history...
49
                abort_unless($item = $finder->find($id), 404);
0 ignored issues
show
Bug introduced by
The function abort_unless 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

49
                /** @scrutinizer ignore-call */ 
50
                abort_unless($item = $finder->find($id), 404);
Loading history...
50
            }
51
52
            return $item ?? null;
53
        });
54
    }
55
}
56