Completed
Push — master ( 3f296a...337f79 )
by Adrian
11:40 queued 04:56
created

HomeController::index()   B

Complexity

Conditions 7
Paths 4

Size

Total Lines 21
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 56

Importance

Changes 3
Bugs 1 Features 0
Metric Value
cc 7
eloc 11
c 3
b 1
f 0
nc 4
nop 1
dl 0
loc 21
ccs 0
cts 13
cp 0
crap 56
rs 7.551
1
<?php
2
namespace Anavel\Crud\Http\Controllers;
3
4
use Anavel\Foundation\Http\Controllers\Controller;
5
use EasySlugger\Slugger;
6
use Illuminate\Http\RedirectResponse;
7
use Anavel\Crud\Contracts\Abstractor\ModelFactory as ModelAbstractorFactory;
8
use Gate;
9
10
class HomeController extends Controller
11
{
12
    public function index(ModelAbstractorFactory $modelFactory)
13
    {
14
        $models = config('anavel-crud.models');
15
16
        if (empty($models)) {
17
            throw new \Exception("No models configured.");
18
        }
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