Completed
Push — master ( 1f61fc...a65ba6 )
by Korotkov
22:49
created

BaseMiddleware::handleArray()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 6
nc 2
nop 1
1
<?php
2
/**
3
 * Date: 17.04.17
4
 * Time: 14:19
5
 *
6
 * @author    : Korotkov Danila <[email protected]>
7
 * @copyright Copyright (c) 2016, Korotkov Danila
8
 * @license   http://www.gnu.org/licenses/gpl.html GNU GPLv3.0
9
 */
10
11
namespace App\Http;
12
13
14
use Rudra\SetContainerTrait;
15
16
17
/**
18
 * Class Middleware
19
 *
20
 * @package stub
21
 */
22
class BaseMiddleware
23
{
24
25
    use SetContainerTrait;
26
27
    /**
28
     * @param null $middleware
29
     *
30
     * @return bool
31
     */
32 View Code Duplication
    public function __invoke($middleware = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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...
33
    {
34
        // StartMiddleware
35
36
        if ($middleware[0][1]['int'] % 2) {
37
            echo json_encode($_SERVER);
38
        }
39
40
        // EndMiddleware
41
42
        $this->next($middleware);
43
    }
44
45
    /**
46
     * @param $middleware
47
     */
48
    protected function next($middleware)
49
    {
50
        $this->container()->get('router')->handleMiddleware($middleware, 1);
51
    }
52
}
53