RoutesDataTable   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 3
dl 0
loc 68
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A query() 0 17 2
A ajax() 0 5 1
A getColumns() 0 11 1
A filename() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cortex\Console\DataTables\Adminarea;
6
7
use Illuminate\Routing\Route;
8
use Cortex\Foundation\DataTables\AbstractDataTable;
9
use Illuminate\Support\Facades\Route as RouteFacade;
10
11
class RoutesDataTable extends AbstractDataTable
12
{
13
    /**
14
     * {@inheritdoc}
15
     */
16
    protected $createButton = false;
17
18
    /**
19
     * Get the query object to be processed by dataTables.
20
     *
21
     * @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Query\Builder|\Illuminate\Support\Collection
22
     */
23
    public function query()
24
    {
25
        $routes = collect(RouteFacade::getRoutes());
26
27
        $routes->transform(function (Route $route, $key) {
0 ignored issues
show
Unused Code introduced by
The parameter $key is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
28
            return [
29
                'domain' => (string) $route->getDomain(),
30
                'uri' => (string) $route->uri() === '/' ? '/' : '/'.$route->uri(),
31
                'name' => (string) $route->getName(),
32
                'methods' => (string) implode(', ', $route->methods()),
33
                'action' => (string) $route->getActionName(),
34
                'middleware' => (string) implode(', ', $route->gatherMiddleware()),
35
            ];
36
        });
37
38
        return $routes;
39
    }
40
41
    /**
42
     * Display ajax response.
43
     *
44
     * @return \Illuminate\Http\JsonResponse
45
     */
46
    public function ajax()
47
    {
48
        return datatables($this->query())
49
            ->make(true);
50
    }
51
52
    /**
53
     * Get columns.
54
     *
55
     * @return array
56
     */
57
    protected function getColumns(): array
58
    {
59
        return [
60
            'domain' => ['title' => trans('cortex/console::common.domain')],
61
            'uri' => ['title' => trans('cortex/console::common.uri')],
62
            'name' => ['title' => trans('cortex/console::common.name')],
63
            'methods' => ['title' => trans('cortex/console::common.methods')],
64
            'action' => ['title' => trans('cortex/console::common.action')],
65
            'middleware' => ['title' => trans('cortex/console::common.middleware')],
66
        ];
67
    }
68
69
    /**
70
     * Get filename for export.
71
     *
72
     * @return string
73
     */
74
    protected function filename(): string
75
    {
76
        return 'routes-export-'.date('Y-m-d').'-'.time();
77
    }
78
}
79