GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 160b61...162853 )
by Alireza
9s
created

CrudController::validateEntity()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 2
eloc 3
nc 2
nop 1
1
<?php
2
namespace Serverfireteam\Panel;
3
4
use Illuminate\Routing\Controller;
5
6
class CrudController extends Controller
7
{
8
    const ID_COLUMN = 'id';
9
10
    public    $grid;
11
    public    $entity;
12
    public    $set;
13
    public    $edit;
14
    public    $filter;
15
    protected $lang;
16
    public    $helper_message;
17
18
    public function __construct(\Lang $lang)
19
    {
20
       // $this->entity = $params['entity'];
21
        $route = \App::make('route');
22
        $this->lang = $lang;
23
        $this->route = $route;
0 ignored issues
show
Bug introduced by
The property route does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
24
        if($route = $route::current())
25
        {
26
            $routeParamters = $route->parameters();
27
            if(isset($routeParamters['entity']))
28
                $this->setEntity($routeParamters['entity']);
29
        }
30
    }
31
32
    /**
33
    * @param string $entity name of the entity
34
    */
35
    public function all($entity)
36
    {
37
        //$this->addStylesToGrid();
38
    }
39
40
    /**
41
    * @param string $entity name of the entity
42
    */
43
    public function edit($entity)
44
    {
45
46
    }
47
48
    public function getEntity() {
49
        return $this->entity;
50
    }
51
52
    public function setEntity($entity) {
53
        $this->entity = $entity;
54
    }
55
56
    public function getEntityModel() {
57
58
        $entity = $this->getEntity();
59
60
        $appHelper = new libs\AppHelper;
61
62
        $modelClass = $appHelper->getModel($entity);
63
64
        return new $modelClass;
65
    }
66
67
    public function addStylesToGrid($orderByColumn = self::ID_COLUMN, $paginateCount = 10)
68
    {
69
        $this->grid->edit('edit', trans('panel::fields.edit'), 'show|modify|delete');
70
71
72
        if ($orderByColumn === self::ID_COLUMN) {
73
            $orderByColumn = $this->getEntityModel()->getKeyName();
74
        }
75
76
        $this->grid->orderBy($orderByColumn, 'desc');
77
        $this->grid->paginate($paginateCount);
78
    }
79
80
    public function addHelperMessage($message)
81
    {
82
        $this->helper_message = $message;
83
    }
84
85
    /**
86
     * Check whether a link is defined for the given URL / model name
87
     * @param $url
88
     * @throws \Exception
89
     */
90
    private function validateEntity($url) {
91
        if (!\Links::all()->pluck('url')->contains($url)) {
92
            throw new \Exception('This url is not set yet!');
93
        }
94
    }
95
96
    public function returnView()
97
    {
98
        $this->validateEntity($this->entity);
99
        return \View::make('panelViews::all', array(
100
         'grid'           => $this->grid,
101
         'filter'         => $this->filter,
102
         'title'          => $this->entity ,
103
         'current_entity' => $this->entity,
104
         'import_message' => (\Session::has('import_message')) ? \Session::get('import_message') : ''
105
        ));
106
    }
107
108
    public function returnEditView()
109
    {
110
        $this->validateEntity($this->entity);
111
        return \View::make('panelViews::edit', array('title'		 => $this->entity,
112
                                'edit' 		 => $this->edit,
113
                        'helper_message' => $this->helper_message));
114
    }
115
116
    public function finalizeFilter() {
117
        $lang = \App::make('lang');
0 ignored issues
show
Unused Code introduced by
$lang is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
118
        $this->filter->submit($this->lang->get('panel::fields.search'));
119
        $this->filter->reset($this->lang->get('panel::fields.reset'));
120
    }
121
}
122