Completed
Push — develop ( 6f56c4...0d53f1 )
by Abdelrahman
01:21
created

RoutesDataTable::getBuilderParameters()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 13
rs 9.4285
cc 1
eloc 9
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
     * Display ajax response.
15
     *
16
     * @return \Illuminate\Http\JsonResponse
17
     */
18
    public function ajax()
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 datatables()->collection($routes)
0 ignored issues
show
Bug introduced by
The method collection does only exist in Yajra\DataTables\DataTables, but not in Yajra\DataTables\DataTableAbstract.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
34
                           ->make(true);
35
    }
36
37
    /**
38
     * Get columns.
39
     *
40
     * @return array
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use array<string,array<strin...tor|string|array|null>>.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
41
     */
42
    protected function getColumns()
43
    {
44
        return [
45
            'domain' => ['title' => trans('cortex/console::common.domain')],
46
            'uri' => ['title' => trans('cortex/console::common.uri')],
47
            'name' => ['title' => trans('cortex/console::common.name')],
48
            'methods' => ['title' => trans('cortex/console::common.methods')],
49
            'action' => ['title' => trans('cortex/console::common.action')],
50
            'middleware' => ['title' => trans('cortex/console::common.middleware')],
51
        ];
52
    }
53
54
    /**
55
     * Get filename for export.
56
     *
57
     * @return string
58
     */
59
    protected function filename()
60
    {
61
        return 'routes-export-'.date('Y-m-d').'-'.time();
62
    }
63
64
    /**
65
     * Get default builder parameters.
66
     *
67
     * @return array
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use array<string,boolean|str...|array<string,string>>>.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
68
     */
69
    protected function getBuilderParameters()
70
    {
71
        return [
72
            'keys' => 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