Completed
Push — develop ( 48afb1...ee07fb )
by Abdelrahman
13:24
created

RoutesDataTable::query()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 17
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 11
nc 1
nop 0
dl 0
loc 17
rs 9.4285
c 0
b 0
f 0
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
     * Get the query object to be processed by dataTables.
15
     *
16
     * @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Query\Builder|\Illuminate\Support\Collection
17
     */
18
    public function query()
19
    {
20
        $routes = collect(RouteFacade::getRoutes());
21
22
        $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...
23
            return [
24
                'domain' => (string) $route->getDomain(),
25
                'uri' => (string) $route->uri() === '/' ? '/' : '/'.$route->uri(),
26
                'name' => (string) $route->getName(),
27
                'methods' => (string) implode(', ', $route->methods()),
28
                'action' => (string) $route->getActionName(),
29
                'middleware' => (string) implode(', ', $route->gatherMiddleware()),
30
            ];
31
        });
32
33
        return $routes;
34
    }
35
36
    /**
37
     * Get columns.
38
     *
39
     * @return array
40
     */
41
    protected function getColumns(): array
42
    {
43
        return [
44
            'domain' => ['title' => trans('cortex/console::common.domain')],
45
            'uri' => ['title' => trans('cortex/console::common.uri')],
46
            'name' => ['title' => trans('cortex/console::common.name')],
47
            'methods' => ['title' => trans('cortex/console::common.methods')],
48
            'action' => ['title' => trans('cortex/console::common.action')],
49
            'middleware' => ['title' => trans('cortex/console::common.middleware')],
50
        ];
51
    }
52
53
    /**
54
     * Get filename for export.
55
     *
56
     * @return string
57
     */
58
    protected function filename(): string
59
    {
60
        return 'routes-export-'.date('Y-m-d').'-'.time();
61
    }
62
63
    /**
64
     * Get default builder parameters.
65
     *
66
     * @return array
67
     */
68
    protected function getBuilderParameters(): array
69
    {
70
        return [
71
            'keys' => true,
72
            'retrieve' => true,
73
            'autoWidth' => false,
74
            'dom' => "<'row'<'col-sm-6'B><'col-sm-6'f>> <'row'r><'row'<'col-sm-12't>> <'row'<'col-sm-5'i><'col-sm-7'p>>",
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 121 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
75
            'buttons' => [
76
                'print', 'reset', 'reload', 'export',
77
                ['extend' => 'colvis', 'text' => '<i class="fa fa-columns"></i> '.trans('cortex/foundation::common.columns').' <span class="caret"/>'],
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 151 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
78
                ['extend' => 'pageLength', 'text' => '<i class="fa fa-list-ol"></i> '.trans('cortex/foundation::common.limit').' <span class="caret"/>'],
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 153 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
79
            ],
80
        ];
81
    }
82
}
83