Completed
Push — master ( 7453f0...ceb701 )
by Korotkov
04:38
created

MainMiddleware::__invoke()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 16
rs 9.4285
c 1
b 0
f 0
cc 2
eloc 6
nc 2
nop 1
1
<?php
2
3
/**
4
 * Date: 17.04.17
5
 * Time: 14:19
6
 *
7
 * @author    : Korotkov Danila <[email protected]>
8
 * @copyright Copyright (c) 2016, Korotkov Danila
9
 * @license   http://www.gnu.org/licenses/gpl.html GNU GPLv3.0
10
 */
11
12
namespace App\Http\Middleware;
13
14
15
use App\Http\BaseMiddleware;
16
17
18
/**
19
 * Class MainMiddleware
20
 *
21
 * @package App\Http\Middleware
22
 */
23
class MainMiddleware extends BaseMiddleware
24
{
25
26
    /**
27
     * @param null $middleware
28
     *
29
     * @return bool
30
     */
31
    public function __invoke($middleware = null)
0 ignored issues
show
Coding Style introduced by
__invoke uses the super-global variable $_SERVER which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
32
    {
33
        $middleware = $this->handleArray($middleware);
34
35
        // StartMiddleware
36
37
        if ($middleware[0][1]['int'] % 2) {
38
            echo json_encode($_SERVER);
39
        }
40
41
        $this->container()->set('middleware', 'middleware', 'raw');
0 ignored issues
show
Unused Code introduced by
The call to ContainerInterface::set() has too many arguments starting with 'raw'.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
42
43
        // EndMiddleware
44
45
        $this->next($middleware);
46
    }
47
}