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 ( f28312...62896a )
by
unknown
02:33
created

Commander::setProperties()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

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