Passed
Push — master ( ab23d3...456c2a )
by Ferry
05:06
created

SubModuleController   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
c 1
b 0
f 0
dl 0
loc 24
rs 10
wmc 5

1 Method

Rating   Name   Duplication   Size   Complexity  
A getSubModule() 0 21 5
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: User
5
 * Date: 8/15/2019
6
 * Time: 11:47 PM
7
 */
8
9
namespace crocodicstudio\crudbooster\controllers;
10
11
use Illuminate\Support\Facades\Cache;
12
13
trait SubModuleController
14
{
15
16
    public function getSubModule($subModuleKey) {
17
        if(!module()->canBrowse()) return cb()->redirect(cb()->getAdminUrl(),cbLang("you_dont_have_privilege_to_this_area"));
18
        if(!verifyReferalUrl()) return cb()->redirect(module()->url(),"It looks like your url is incorrect");
19
20
        if($subModule = Cache::get("subModule".$subModuleKey)) {
21
            $foreignKey = $subModule['foreignKey'];
22
            $foreignValue = $subModule['foreignValue'];
23
24
            $query = $this->repository();
0 ignored issues
show
Bug introduced by
It seems like repository() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

24
            /** @scrutinizer ignore-call */ 
25
            $query = $this->repository();
Loading history...
25
            $query->where($foreignKey, $foreignValue);
26
            $result = $query->paginate( request("limit")?:cbConfig("LIMIT_TABLE_DATA") );
27
            $data['result'] = $result;
0 ignored issues
show
Comprehensibility Best Practice introduced by
$data was never initialized. Although not strictly required by PHP, it is generally a good practice to add $data = array(); before regardless.
Loading history...
28
29
            $data['additionalHeaderTitle'] = $subModule['parentTitle'];
30
            $data['additionalHeaderContent'] = $subModule['info'];
31
            $data['subModuleKey'] = $subModuleKey;
32
33
            return view("crudbooster::module.index.index", array_merge($data, $this->data));
34
        }
35
36
        return cb()->redirect(module()->url(),"It looks like your url is incorrect");
37
    }
38
39
}