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
Pull Request — master (#362)
by
unknown
11:00
created

MainController::entityUrl()   C

Complexity

Conditions 7
Paths 10

Size

Total Lines 46
Code Lines 31

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 46
rs 6.7272
c 0
b 0
f 0
cc 7
eloc 31
nc 10
nop 2
1
<?php
2
3
/* 
4
 * To change this license header, choose License Headers in Project Properties.
5
 * To change this template file, choose Tools | Templates
6
 * and open the template in the editor.
7
 */
8
9
namespace Serverfireteam\Panel;
10
11
use \Serverfireteam\Panel\libs\PanelElements;
12
use Illuminate\Routing\Controller;
13
use Symfony\Component\Finder\Finder;
14
15
class MainController extends Controller
16
{
17
18
19
    public function entityUrl($entity, $methods)
20
    {
21
        $appHelper = new libs\AppHelper();
0 ignored issues
show
Unused Code introduced by
$appHelper 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...
22
23
        if (\Links::isMain($entity)) {
24
            $controller_path = 'Serverfireteam\Panel\\'.$entity.'Controller';
25
        } else {
26
            $panel_path = \Config::get('panel.controllers');
27
            if (isset($panel_path)) {
28
                $controller_path = '\\'.$panel_path.'\\'.$entity.'Controller';
29
            } else {
30
                $controller_path = '';
31
                $finder = new Finder();
32
                $files = $finder->files()->name($entity."Controller.php")->in(
33
                    \App::basePath().'/app'
34
                );
35
                foreach ($files as $item) {
36
                    $fileContent = $item->getContents();
37
                    $controller_path = $this->getNameSpace(
38
                            $fileContent
39
                        )."\\".$entity."Controller";
40
                }
41
                if ($controller_path === '') {
42
                    throw new \Exception("Controller not found ( $entity.\"Controller.php\" ) ");
43
                }
44
            }
45
        }
46
47
        try {
48
            $controller = \App::make($controller_path);
49
        } catch (\Exception $ex) {
50
            throw new \Exception("Controller not found ( $controller_path ) ");
51
        }
52
53
        if (!method_exists($controller, $methods)) {
54
            throw new \Exception(
55
                'Controller does not implement the CrudController methods!'
56
            );
57
        } else {
58
            return $controller->callAction(
59
                $methods,
60
                array('entity' => $entity)
61
            );
62
        }
63
64
    }
65
66
    private function getNameSpace($fileContent)
67
    {
68
        if (preg_match('#^namespace\s+(.+?);$#sm', $fileContent, $m)) {
69
            return $m[1];
70
        }
71
        return null;
72
    }
73
}
74
75
76