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 ( 293910...0557d3 )
by Steeven
02:17
created

Commander::__construct()   C

Complexity

Conditions 12
Paths 17

Size

Total Lines 27
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 12
eloc 23
nc 17
nop 1
dl 0
loc 27
rs 6.9666
c 0
b 0
f 0

How to fix   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\Kernel\Cli\Router\DataStructures;
15
16
// ------------------------------------------------------------------------
17
18
use O2System\Spl\Info\SplClassInfo;
19
20
/**
21
 * Class Commander
22
 *
23
 * @package O2System\DataStructures
24
 */
25
class Commander extends SplClassInfo
26
{
27
    /**
28
     * Commander::$requestMethod
29
     *
30
     * @var string|null
31
     */
32
    private $requestMethod = null;
33
34
    /**
35
     * Commander::$requestMethodArgs
36
     *
37
     * @var array
38
     */
39
    private $requestMethodArgs = [];
40
41
    /**
42
     * Commander::$properties
43
     *
44
     * @var array
45
     */
46
    private $properties = [];
47
48
    /**
49
     * Commander::$instance
50
     *
51
     * @var \O2System\Kernel\Cli\Commander
52
     */
53
    private $instance;
54
55
    // ------------------------------------------------------------------------
56
57
    /**
58
     * Commander::__construct
59
     *
60
     * @param string $filePath
61
     */
62
    public function __construct($filePath)
63
    {
64
        if (is_object($filePath)) {
0 ignored issues
show
introduced by
The condition is_object($filePath) is always false.
Loading history...
65
            if ($filePath instanceof \O2System\Kernel\Cli\Commander) {
66
                parent::__construct($filePath);
67
                $this->instance = $filePath;
68
            }
69
        } elseif (is_string($filePath) && is_file($filePath)) {
70
            $className = prepare_class_name(pathinfo($filePath, PATHINFO_FILENAME));
71
            @list($namespaceDirectory, $subNamespace) = explode('Commanders', dirname($filePath));
72
            $classNamespace = loader()->getDirNamespace(
0 ignored issues
show
Bug introduced by
The function loader was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

72
            $classNamespace = /** @scrutinizer ignore-call */ loader()->getDirNamespace(
Loading history...
73
                    $namespaceDirectory
74
                ) . 'Commanders' . (empty($subNamespace) ? null : str_replace('/', '\\', $subNamespace)) . '\\';
75
            $className = $classNamespace . $className;
76
77
            if (class_exists('\O2System\Kernel\Cli\\' . $className)) {
78
                parent::__construct('\O2System\Kernel\Cli\\' . $className);
79
            } elseif (class_exists('\O2System\Framework\Cli\\' . $className)) {
80
                parent::__construct('\O2System\Framework\Cli\\' . $className);
81
            } elseif (class_exists('\O2System\Reactor\Cli\\' . $className)) {
82
                parent::__construct('\O2System\Reactor\Cli\\' . $className);
83
            } elseif (class_exists('\App\Cli\\' . $className)) {
84
                parent::__construct('\App\Cli\\' . $className);
85
            } elseif (class_exists('\App\\' . $className)) {
86
                parent::__construct('\App\\' . $className);
87
            } elseif (class_exists($className)) {
88
                parent::__construct($className);
89
            }
90
        }
91
    }
92
93
    // ------------------------------------------------------------------------
94
95
    /**
96
     * Commander::setProperties
97
     *
98
     * @param array $properties
99
     */
100
    public function setProperties(array $properties)
101
    {
102
        $this->properties = $properties;
103
    }
104
105
    // ------------------------------------------------------------------------
106
107
    /**
108
     * Commander::getParameter
109
     *
110
     * @return string
111
     */
112
    public function getParameter()
113
    {
114
        return strtolower(get_class_name($this->name));
115
    }
116
117
    // ------------------------------------------------------------------------
118
119
    /**
120
     * Commander::getInstance
121
     *
122
     * @return \O2System\Kernel\Cli\Commander|string
123
     */
124
    public function &getInstance()
125
    {
126
        if (empty($this->instance)) {
127
            $className = $this->name;
128
            $this->instance = new $className();
129
130
            if (count($this->properties)) {
131
                foreach ($this->properties as $key => $value) {
132
                    $setterMethodName = camelcase('set_' . $key);
133
134
                    if (method_exists($this->instance, $setterMethodName)) {
135
                        $this->instance->{$setterMethodName}($value);
136
                    } else {
137
                        $this->instance->{$key} = $value;
138
                    }
139
                }
140
            }
141
        }
142
143
        return $this->instance;
144
    }
145
146
    // ------------------------------------------------------------------------
147
148
    /**
149
     * Commander::getRequestMethod
150
     *
151
     * @return string|null
152
     */
153
    public function getRequestMethod()
154
    {
155
        return $this->requestMethod;
156
    }
157
158
    // ------------------------------------------------------------------------
159
160
    /**
161
     * Commander::setRequestMethod
162
     *
163
     * @param string $method
164
     *
165
     * @return static
166
     */
167
    public function setRequestMethod($method)
168
    {
169
        $this->requestMethod = $method;
170
171
        return $this;
172
    }
173
174
    // ------------------------------------------------------------------------
175
176
    /**
177
     * Commander::getRequestMethodArgs
178
     *
179
     * @return array
180
     */
181
    public function getRequestMethodArgs()
182
    {
183
        return $this->requestMethodArgs;
184
    }
185
186
    // ------------------------------------------------------------------------
187
188
    /**
189
     * Commander::setRequestMethodArgs
190
     *
191
     * @param array $arguments
192
     *
193
     * @return static
194
     */
195
    public function setRequestMethodArgs(array $arguments)
196
    {
197
        $arguments = array_values($arguments);
198
        array_unshift($arguments, null);
199
        unset($arguments[ 0 ]);
200
201
        $this->requestMethodArgs = $arguments;
202
203
        return $this;
204
    }
205
}