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.
Passed
Push — master ( c097a6...9587da )
by Steeven
02:27
created

Controller::__construct()   C

Complexity

Conditions 13
Paths 17

Size

Total Lines 73
Code Lines 51

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 13
eloc 51
nc 17
nop 1
dl 0
loc 73
rs 6.6166
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 * This file is part of the O2System Framework package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 *
8
 * @author         Steeve Andrian Salim
9
 * @copyright      Copyright (c) Steeve Andrian Salim
10
 */
11
12
// ------------------------------------------------------------------------
13
14
namespace O2System\Framework\Containers\Modules\DataStructures\Module;
15
16
// ------------------------------------------------------------------------
17
18
use O2System\Spl\Info\SplClassInfo;
19
20
/**
21
 * Class Controller
22
 * @package O2System\Framework\Containers\Modules\DataStructures\Module
23
 */
24
class Controller extends SplClassInfo
25
{
26
    /**
27
     * Controller::$methods
28
     *
29
     * @var array
30
     */
31
    public $methods = [];
32
33
    /**
34
     * Controller::$namespace
35
     *
36
     * @var string
37
     */
38
    public $namespace;
39
40
    // ------------------------------------------------------------------------
41
42
    /**
43
     * Controller::__construct
44
     *
45
     * @param string $className
46
     */
47
    public function __construct($className)
48
    {
49
        parent::__construct($className);
50
51
        if ( ! empty($this->name)) {
52
            $this->namespace = get_namespace($className);
53
54
            $nameParts = explode('\\', $this->name);
55
56
            $segments = [];
57
            foreach ($nameParts as $namePart) {
58
                if ( ! in_array(strtolower($namePart), [
59
                    'app',
60
                    'apps',
61
                    'modules',
62
                    'components',
63
                    'plugins',
64
                    'controllers',
65
                ])) {
66
                    $namePart = dash($namePart);
67
68
                    if ( ! in_array($namePart, $segments)) {
69
                        array_push($segments, $namePart);
70
                    }
71
                }
72
            }
73
74
            if ($methods = $this->getMethods(\ReflectionMethod::IS_PUBLIC)) {
75
                foreach ($methods as $method) {
76
                    if (strpos($method->name, '__') === false and ! in_array($method->name,
77
                            [
78
                                'route',
79
                                'getClassInfo',
80
                                'form',
81
                                'add',
82
                                'add-new',
83
                                'edit',
84
                                'create',
85
                                'read',
86
                                'update',
87
                                'delete',
88
                                'open',
89
                                'download',
90
                                'detail',
91
                                'overview',
92
                                'view',
93
                                'settings',
94
                                'setting',
95
                                'sendError',
96
                                'sendPayload'
97
                            ])) {
98
                        $methodSegments = $segments;
99
100
                        $method->segment = dash($method->name);
0 ignored issues
show
Bug introduced by
The property segment does not seem to exist on ReflectionMethod.
Loading history...
101
102
                        if ( ! in_array($method->name, $methodSegments) and $method->name !== 'index') {
103
                            array_push($methodSegments, dash($method->name));
104
                        }
105
106
                        $method->segments = implode('/', $methodSegments);
0 ignored issues
show
Bug introduced by
The property segments does not seem to exist on ReflectionMethod.
Loading history...
107
                        $method->hash = md5($method->segments);
0 ignored issues
show
Bug introduced by
The property hash does not seem to exist on ReflectionMethod.
Loading history...
108
109
                        $this->methods[$method->segment] = $method;
110
                    }
111
                }
112
            }
113
114
            if(empty($this->methods) and $this->hasMethod('route')) {
115
                $method = $this->getMethod('route');
116
                $method->segment = dash($method->name);
117
                $method->segments = implode('/', $segments);
118
                $method->hash = md5($method->segments);
119
                $this->methods[$method->segment] = $method;
120
            }
121
        }
122
    }
123
}