Test Failed
Push — master ( a29797...6ce97f )
by huang
06:37
created

Routing::execute()   C

Complexity

Conditions 7
Paths 5

Size

Total Lines 33
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 23
nc 5
nop 2
dl 0
loc 33
rs 6.7272
c 0
b 0
f 0
1
<?php
2
/**
3
 * @author    jan huang <[email protected]>
4
 * @copyright 2016
5
 *
6
 * @see      https://www.github.com/janhuang
7
 * @see      https://fastdlabs.com
8
 */
9
10
namespace FastD\Console;
11
12
use Symfony\Component\Console\Command\Command;
13
use Symfony\Component\Console\Helper\Table;
14
use Symfony\Component\Console\Input\InputInterface;
15
use Symfony\Component\Console\Output\OutputInterface;
16
17
/**
18
 * Class Route.
19
 */
20
class Routing extends Command
21
{
22
    public function configure()
23
    {
24
        $this
25
            ->setName('route')
26
            ->setHelp('Show all route')
27
            ->setDescription('Show you defined routes.')
28
        ;
29
    }
30
31
    /**
32
     * @param InputInterface  $input
33
     * @param OutputInterface $output
34
     *
35
     * @return mixed
36
     */
37
    public function execute(InputInterface $input, OutputInterface $output)
38
    {
39
        $table = new Table($output);
40
        $rows = [];
41
        $table->setHeaders(array('Path', 'Method', 'Callback', 'Middleware'));
42
        foreach (route()->aliasMap as $routes) {
43
            foreach ($routes as $route) {
44
                $m = [];
45
                $middleware = $route->getMiddleware();
46
                if (is_array($middleware)) {
47
                    foreach ($middleware as $value) {
48
                        if (is_object($value)) {
49
                            $m[] = get_class($value);
50
                        } else {
51
                            $m[] = $value;
52
                        }
53
                    }
54
                } elseif (is_object($middleware)) {
55
                    $m[] = get_class($middleware);
56
                }
57
                $rows[] = [
58
                    $route->getPath(),
59
                    $route->getMethod(),
60
                    $route->getCallback(),
61
                    implode(',', $m),
62
                ];
63
            }
64
        }
65
66
        $table->setRows($rows);
67
68
        $table->render();
69
    }
70
}
71