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.

Middleware   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 46
ccs 0
cts 17
cp 0
rs 10
c 0
b 0
f 0
wmc 7
lcom 1
cbo 3

1 Method

Rating   Name   Duplication   Size   Complexity  
C register() 0 30 7
1
<?php
2
/**
3
 * Kotori.php
4
 *
5
 * A Tiny Model-View-Controller PHP Framework
6
 *
7
 * This content is released under the Apache 2 License
8
 *
9
 * Copyright (c) 2015-2017 Kotori Technology. All rights reserved.
10
 *
11
 * Licensed under the Apache License, Version 2.0 (the "License");
12
 * you may not use this file except in compliance with the License.
13
 * You may obtain a copy of the License at
14
 *
15
 *     http://www.apache.org/licenses/LICENSE-2.0
16
 *
17
 * Unless required by applicable law or agreed to in writing, software
18
 * distributed under the License is distributed on an "AS IS" BASIS,
19
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
 * See the License for the specific language governing permissions and
21
 * limitations under the License.
22
 */
23
24
/**
25
 * Middleware Class
26
 *
27
 * @package     Kotori
28
 * @subpackage  Core
29
 * @author      Kokororin
30
 * @link        https://kotori.love
31
 */
32
namespace Kotori\Core;
33
34
use Kotori\Exception\ConfigException;
35
use Kotori\Exception\NotFoundException;
36
37
class Middleware
38
{
39
    /**
40
     * Registered middlewares
41
     *
42
     * @var array
43
     */
44
    protected static $middlewares = [];
45
46
    /**
47
     * Register a middleware
48
     *
49
     * @param  string $middleware
50
     * @return void
51
     */
52
    public static function register($middleware)
53
    {
54
        $config = Container::get('config')->get('middleware');
55
56
        if (isset($config[$middleware])) {
57
            if (in_array($middleware, array_values(self::$middlewares))) {
58
                throw new ConfigException('middleware has already registered');
59
            }
60
61
            array_push(self::$middlewares, $middleware);
62
            $middlewares = $config[$middleware];
63
64
            if (!is_array($middlewares)) {
65
                throw new ConfigException('middleware config must be an array');
66
            }
67
68
            foreach ($middlewares as $className) {
69
                if (!class_exists($className)) {
70
                    throw new NotFoundException('middleware class ' . $className . ' is not found');
71
                }
72
73
                $class = new $className;
74
                if (!method_exists($class, 'handle')) {
75
                    throw new NotFoundException('middleware class should implement a handle() method');
76
                }
77
78
                $class->handle(Container::get('request'), Container::get('response'));
79
            }
80
        }
81
    }
82
}
83