Completed
Push — develop ( 0e2361...50a387 )
by Abdelrahman
01:29
created

PagesDataTable   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 80
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 1

Importance

Changes 0
Metric Value
wmc 5
lcom 2
cbo 1
dl 0
loc 80
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A query() 0 7 1
A getParameters() 0 12 1
A ajax() 0 9 1
A getColumns() 0 16 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cortex\Pages\DataTables\Tenantarea;
6
7
use Rinvex\Pages\Contracts\PageContract;
8
use Cortex\Foundation\DataTables\AbstractDataTable;
9
use Cortex\Pages\Transformers\Tenantarea\PageTransformer;
10
11
class PagesDataTable extends AbstractDataTable
12
{
13
    /**
14
     * {@inheritdoc}
15
     */
16
    protected $model = PageContract::class;
17
18
    /**
19
     * {@inheritdoc}
20
     */
21
    protected $transformer = PageTransformer::class;
22
23
    /**
24
     * Get the query object to be processed by dataTables.
25
     *
26
     * @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Query\Builder|\Illuminate\Support\Collection
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use \Illuminate\Database\Que...tabase\Eloquent\Builder.

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...
27
     */
28
    public function query()
29
    {
30
        $locale = app()->getLocale();
31
        $query = app($this->model)->query()->orderBy('sort_order', 'ASC')->orderBy("title->\${$locale}", 'ASC');
32
33
        return $this->applyScopes($query);
34
    }
35
36
    /**
37
     * Get parameters.
38
     *
39
     * @return array
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use array<string,boolean|str...string,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...
40
     */
41
    protected function getParameters()
42
    {
43
        return [
44
            'keys' => true,
45
            'autoWidth' => false,
46
            '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...
47
            'buttons' => [
48
                ['extend' => 'create', 'text' => '<i class="fa fa-plus"></i> '.trans('cortex/foundation::common.new')], 'print', 'reset', 'reload', 'export',
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 157 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...
49
                ['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...
50
            ],
51
        ];
52
    }
53
54
    /**
55
     * Display ajax response.
56
     *
57
     * @return \Illuminate\Http\JsonResponse
58
     */
59
    public function ajax()
60
    {
61
        $transformer = app($this->transformer);
62
63
        return datatables()->eloquent($this->query())
0 ignored issues
show
Bug introduced by
The method eloquent 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...
64
                           ->setTransformer($transformer)
65
                           ->orderColumn('title', 'title->"$.'.app()->getLocale().'" $1')
66
                           ->make(true);
67
    }
68
69
    /**
70
     * Get columns.
71
     *
72
     * @return array
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use array<string,array>.

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...
73
     */
74
    protected function getColumns()
75
    {
76
        $link = config('cortex.foundation.route.locale_prefix')
77
            ? '"<a href=\""+routes.route(\'tenantarea.pages.edit\', {page: full.slug, locale: \''.$this->request->segment(1).'\'})+"\">"+data+"</a>"'
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 149 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
            : '"<a href=\""+routes.route(\'tenantarea.pages.edit\', {page: full.slug})+"\">"+data+"</a>"';
79
80
        return [
81
            'title' => ['title' => trans('cortex/pages::common.title'), 'render' => $link, 'responsivePriority' => 0],
82
            'uri' => ['title' => trans('cortex/pages::common.uri')],
83
            'route' => ['title' => trans('cortex/pages::common.route')],
84
            'view' => ['title' => trans('cortex/pages::common.view')],
85
            'middleware' => ['title' => trans('cortex/pages::common.middleware')],
86
            'created_at' => ['title' => trans('cortex/pages::common.created_at'), 'render' => "moment(data).format('MMM Do, YYYY')"],
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 133 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...
87
            'updated_at' => ['title' => trans('cortex/pages::common.updated_at'), 'render' => "moment(data).format('MMM Do, YYYY')"],
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 133 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...
88
        ];
89
    }
90
}
91