Completed
Push — master ( 72efb5...e53b1a )
by Vítor
02:42
created

src/Controller/Http/RoutesController.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * ZfDebugModule. Console commands and other utilities for debugging ZF2 apps.
4
 *
5
 * @license http://www.opensource.org/licenses/mit-license.html MIT License
6
 * @copyright 2016 Vítor Brandão <[email protected]>
7
 */
8
9
namespace Noiselabs\ZfDebugModule\Controller\Http;
10
11
use Noiselabs\ZfDebugModule\Module;
12
use Noiselabs\ZfDebugModule\Package;
13
use Noiselabs\ZfDebugModule\Util\Routing\RouteCollection;
14
use Noiselabs\ZfDebugModule\Util\Routing\RouteMatcher;
15
use Zend\Http\Request;
16
use Zend\Http\Response;
17
use Zend\Mvc\Controller\AbstractActionController;
18
use Zend\View\Model\JsonModel;
19
use Zend\View\Model\ViewModel;
20
21
class RoutesController extends AbstractActionController
22
{
23
    /**
24
     * @var RouteCollection
25
     */
26
    private $routeCollection;
27
    /**
28
     * @var RouteMatcher
29
     */
30
    private $routeMatcher;
31
32
    /**
33
     * RoutesController constructor.
34
     *
35
     * @param RouteCollection $routeCollection
36
     * @param RouteMatcher $routeMatcher
37
     */
38
    public function __construct(RouteCollection $routeCollection, RouteMatcher $routeMatcher)
39
    {
40
        $this->routeCollection = $routeCollection;
41
        $this->routeMatcher = $routeMatcher;
42
    }
43
44
    /**
45
     * @return Response
46
     */
47
    public function indexAction()
48
    {
49
        return $this->redirect()->toRoute(Package::NAME . '/routes/list');
50
    }
51
52
    /**
53
     * @return ViewModel
54
     */
55
    public function listAllAction()
56
    {
57
        $this->layout(Module::DEFAULT_LAYOUT);
58
        $view = new ViewModel([
59
            'routeCollection' => $this->routeCollection,
60
        ]);
61
        $view->setTemplate(Package::FQPN . '/routes/list-all');
62
63
        return $view;
64
    }
65
66
    /**
67
     * @return ViewModel
68
     */
69
    public function renderMatchRouteViewAction()
70
    {
71
        $this->layout(Module::DEFAULT_LAYOUT);
72
        $view = new ViewModel();
73
        $view->setTemplate(Package::FQPN . '/routes/match');
74
75
        return $view;
76
    }
77
78
    /**
79
     * @return JsonModel
80
     */
81
    public function matchRouteAction()
82
    {
83
        /** @var Request $request */
84
        $request = $this->getRequest();
0 ignored issues
show
$request is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
85
        $data = $this->params()->fromPost();
86
        $match = false;
87
        if (isset($data['method']) && !empty($data['method']) && isset($data['url']) && !empty($data['url'])) {
88
            $match = $this->routeMatcher->match($data['method'], $data['url']);
89
        }
90
91
        return new JsonModel(['match' => $match]);
92
    }
93
}
94