RouterCommand   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 24
dl 0
loc 72
rs 10
c 0
b 0
f 0
wmc 7

4 Methods

Rating   Name   Duplication   Size   Complexity  
A actionContainer() 0 10 1
A actionIndex() 0 10 2
A getRoutes() 0 9 2
A getTable() 0 8 2
1
<?php
2
3
namespace App\Ship\Command;
4
5
use Rudra\Container\Facades\Rudra;
6
use Rudra\Cli\ConsoleFacade as Cli;
7
use Rudra\Router\RouterFacade as Router;
8
9
class RouterCommand
10
{
11
    /**
12
     * Returns all routes
13
     * ------------------
14
     * Возвращает все маршруты
15
     */
16
    public function actionIndex(): void
17
    {
18
        $_SERVER["REQUEST_METHOD"] = 'GET';
19
        $_SERVER["REQUEST_URI"]    = '';
20
21
        foreach (Rudra::config()->get('containers') as $container => $item) {
22
            $mask = "|%-3.3s|%-45.45s|%-7.7s|%-65.65s|%-25.25s| x |" . PHP_EOL;
23
            Cli::printer(strtoupper($container) . PHP_EOL, "yellow");
24
            printf("\e[5;35m" . $mask . "\e[m", " ", "route", "method", "controller", "action");
25
            $this->getTable($this->getRoutes($container));
26
        }
27
    }
28
29
    /**
30
     * Returns the route of the module
31
     * -------------------------------
32
     * Возвращает маршрут модуля
33
     */
34
    public function actionContainer(): void
35
    {
36
        $_SERVER["REQUEST_METHOD"] = 'GET';
37
        $_SERVER["REQUEST_URI"]    = '';
38
39
        Cli::printer("Enter container name: ", "magneta");
40
        $link = trim(Cli::reader());
41
        $mask = "|%-3.3s|%-45.45s|%-7.7s|%-65.65s|%-25.25s| x |" . PHP_EOL;
42
        printf("\e[5;35m" . $mask . "\e[m", " ", "route", "method", "controller", "action");
43
        $this->getTable($this->getRoutes($link));
44
    }
45
46
    /**
47
     * Forms a table
48
     * -------------
49
     * Формирует таблицу
50
     *
51
     * @param array $data
52
     */
53
    protected function getTable(array $data): void
54
    {
55
        $mask = "|%-3.3s|%-45.45s|%-7.7s|%-65.65s|%-25.25s| x |" . PHP_EOL;
56
        $i    = 1;
57
58
        foreach ($data as $routes) {
59
            printf("\e[5;36m" . $mask . "\e[m", $i, $routes[0]['url'], $routes[0]['method'], $routes[0]['controller'], $routes[0]['action'] ?? "actionIndex");
60
            $i++;
61
        }
62
    }
63
64
    /**
65
     * Builds route files from modules
66
     * -------------------------------
67
     * Собирает файлы маршрутов из модулей
68
     *
69
     * @param string $container
70
     * @return array
71
     */
72
    protected function getRoutes(string $container): array
73
    {
74
        $path = "app/Containers/" . ucfirst($container) . "/routes";
75
76
        if (file_exists($path . ".php")) {
77
            return Router::annotationCollector(require $path . ".php", true, Rudra::config()->get("attributes"));
0 ignored issues
show
Unused Code introduced by
The call to Rudra\Router\RouterFacade::annotationCollector() has too many arguments starting with true. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

77
            return Router::/** @scrutinizer ignore-call */ annotationCollector(require $path . ".php", true, Rudra::config()->get("attributes"));

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. Please note the @ignore annotation hint above.

Loading history...
78
        }
79
80
        return [];
81
    }
82
}
83