Completed
Push — develop ( ee07fb...8b6463 )
by Abdelrahman
01:18
created

RoutesDataTable::getBuilderParameters()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 14
rs 9.4285
cc 1
eloc 10
nc 1
nop 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
     * {@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
     * Get columns.
43
     *
44
     * @return array
45
     */
46
    protected function getColumns(): array
47
    {
48
        return [
49
            'domain' => ['title' => trans('cortex/console::common.domain')],
50
            'uri' => ['title' => trans('cortex/console::common.uri')],
51
            'name' => ['title' => trans('cortex/console::common.name')],
52
            'methods' => ['title' => trans('cortex/console::common.methods')],
53
            'action' => ['title' => trans('cortex/console::common.action')],
54
            'middleware' => ['title' => trans('cortex/console::common.middleware')],
55
        ];
56
    }
57
58
    /**
59
     * Get filename for export.
60
     *
61
     * @return string
62
     */
63
    protected function filename(): string
64
    {
65
        return 'routes-export-'.date('Y-m-d').'-'.time();
66
    }
67
}
68