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 ( a3eb64...37c075 )
by cao
03:26
created

ControllerContainer::setUriPrefix()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace PhpBoot\Controller;
4
use PhpBoot\Application;
5
use Symfony\Component\HttpFoundation\Request;
6
7
/**
8
 * Class ControllerContainer
9
 */
10
class ControllerContainer
11
{
12 4
    public function __construct($className)
13
    {
14 4
        $this->className = $className;
15 4
    }
16
    /**
17
     * 添加路由
18
     * @param Route $route
19
     * @param string $actionName class method
20
     * @return void
21
     */
22 4
    public function addRoute($actionName, Route $route)
23
    {
24 4
        !array_key_exists($actionName, $this->routes) or \PhpBoot\abort("repeated @route for {$this->className}::$actionName");
0 ignored issues
show
Comprehensibility Best Practice introduced by
Using logical operators such as or instead of || is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
25 4
        $this->routes[$actionName] = $route;
26 4
    }
27
    /**
28
     * 获取路由列表
29
     * @return Route[]
30
     */
31 2
    public function getRoutes()
32
    {
33 2
        return $this->routes;
34
    }
35
36
    /**
37
     * 获取路由列表
38
     * @param Route[] $routes
39
     */
40
    public function setRoutes($routes)
41
    {
42
        $this->routes = $routes;
43
    }
44
    /**
45
     * 获取指定名称的路由
46
     * @param $actionName
47
     * @return Route|false
48
     */
49 7
    public function getRoute($actionName)
50
    {
51 7
        if (array_key_exists($actionName, $this->routes)){
52 7
            return $this->routes[$actionName];
53
        }
54
        return false;
55
    }
56
57 1
    static public function dispatch(
0 ignored issues
show
Coding Style introduced by
As per PSR2, the static declaration should come after the visibility declaration.
Loading history...
58
        Application $app,
59
        $className,
60
        $actionName,
61
        Route $route,
62
        Request $request)
63
    {
64 1
        $ctrl = $app->get($className);
65 1
        return $route->invoke($app, [$ctrl, $actionName], $request);
66
    }
67
    
68
//    /**
0 ignored issues
show
Unused Code Comprehensibility introduced by
44% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
69
//     * 应用路由, 使路由生效
70
//     * @param RouteCollector $r
71
//     * @return RouteCollector
72
//     */
73
//    public function build(RouteCollector $r)
74
//    {
75
//        foreach ($this->routes as $actionName=>$route){
76
//            $r->addRoute(
77
//                $route->getMethod(),
78
//                $route->getUri(),
79
//                new SerializableFunc(self::class.'::dispatch', $this->className, $actionName, $route)
80
//            );
81
//        }
82
//        return $r;
83
//    }
84
85
    /**
86
     * @return string
87
     */
88 4
    public function getClassName()
89
    {
90 4
        return $this->className;
91
    }
92
93
    /**
94
     * 获取uri前缀
95
     * @return string
96
     */
97 4
    public function getUriPrefix()
98
    {
99 4
        return $this->prefix;
100
    }
101
102
    /**
103
     * 设置uri前缀
104
     * @param string $prefix
105
     */
106 4
    public function setUriPrefix($prefix)
107
    {
108 4
        $this->prefix = $prefix;
109 4
    }
110
111
    /**
112
     * @return string
113
     */
114
    public function getFileName()
115
    {
116
        return $this->fileName;
117
    }
118
119
    /**
120
     * @param string $fileName
121
     */
122 4
    public function setFileName($fileName)
123
    {
124 4
        $this->fileName = $fileName;
125 4
    }
126
127
    /**
128
     * @param string $description
129
     */
130 4
    public function setDescription($description)
131
    {
132 4
        $this->description = $description;
133 4
    }
134
135
    /**
136
     * @return string
137
     */
138 1
    public function getDescription()
139
    {
140 1
        return $this->description;
141
    }
142
143
    /**
144
     * @return string
145
     */
146 1
    public function getSummary()
147
    {
148 1
        return $this->summary;
149
    }
150
151
    /**
152
     * @param string $summary
153
     */
154 4
    public function setSummary($summary)
155
    {
156 4
        $this->summary = $summary;
157 4
    }
158
159
    /**
160
     * @var string
161
     * the prefix path for all routes of the controller
162
     */
163
    private $prefix;
164
165
    /**
166
     * @var string
167
     */
168
    private $className;
169
170
    /**
171
     * @var Route[]
172
     */
173
    private $routes=[];
174
175
    /**
176
     * @var string
177
     */
178
    private $description='';
179
    /**
180
     * @var string
181
     */
182
    private $summary='';
183
184
    /**
185
     * @var string
186
     */
187
    private $fileName;
188
}