HomeController   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 23
ccs 0
cts 13
cp 0
rs 10
c 1
b 0
f 0
wmc 7
lcom 0
cbo 5

1 Method

Rating   Name   Duplication   Size   Complexity  
B index() 0 20 7
1
<?php
2
3
namespace Anavel\Crud\Http\Controllers;
4
5
use Anavel\Crud\Contracts\Abstractor\ModelFactory as ModelAbstractorFactory;
6
use Anavel\Foundation\Http\Controllers\Controller;
7
use EasySlugger\Slugger;
8
use Gate;
9
use Illuminate\Http\RedirectResponse;
10
11
class HomeController extends Controller
12
{
13
    public function index(ModelAbstractorFactory $modelFactory)
14
    {
15
        $models = config('anavel-crud.models');
16
17
        if (empty($models)) {
18
            throw new \Exception('No models configured.');
19
        }
20
21
        foreach ($models as $modelName => $model) {
22
            $modelSlug = Slugger::slugify($modelName);
23
            $modelAbstractor = $modelFactory->getByName($modelSlug);
24
            $config = $modelAbstractor->getConfig();
25
26
            if (!array_key_exists('authorize', $config) || ($config['authorize'] === true && Gate::allows('adminIndex', $modelAbstractor->getInstance()) || $config['authorize'] === false)) {
27
                return new RedirectResponse(route('anavel-crud.model.index', $modelSlug));
0 ignored issues
show
Documentation introduced by
$modelSlug is of type string, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
28
            }
29
        }
30
31
        abort(403);
32
    }
33
}
34