Completed
Push — develop ( e7ac13...3f57bc )
by Abdelrahman
01:30
created

TenantsDataTable   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 79
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 3

Importance

Changes 0
Metric Value
wmc 7
lcom 2
cbo 3
dl 0
loc 79
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A query() 0 6 1
B ajax() 0 26 4
A getColumns() 0 17 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cortex\Tenants\DataTables\Adminarea;
6
7
use Cortex\Tenants\Models\Tenant;
8
use Illuminate\Database\Eloquent\Builder;
9
use Cortex\Foundation\DataTables\AbstractDataTable;
10
use Cortex\Tenants\Transformers\Adminarea\TenantTransformer;
11
12
class TenantsDataTable extends AbstractDataTable
13
{
14
    /**
15
     * {@inheritdoc}
16
     */
17
    protected $model = Tenant::class;
18
19
    /**
20
     * {@inheritdoc}
21
     */
22
    protected $transformer = TenantTransformer::class;
23
24
    /**
25
     * Get the query object to be processed by dataTables.
26
     *
27
     * @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\Query\Builder|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...
28
     */
29
    public function query()
30
    {
31
        $query = app($this->model)->query();
32
33
        return $this->applyScopes($query);
34
    }
35
36
    /**
37
     * Display ajax response.
38
     *
39
     * @return \Illuminate\Http\JsonResponse
40
     */
41
    public function ajax()
42
    {
43
        return datatables($this->query())
0 ignored issues
show
Bug introduced by
The method setTransformer does only exist in Yajra\DataTables\DataTableAbstract, but not in Yajra\DataTables\DataTables.

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...
44
            ->setTransformer(app($this->transformer))
45
            ->filterColumn('owner.username', function (Builder $builder, $keyword) {
46
                $builder->whereHas('owner', function (Builder $builder) use ($keyword) {
47
                    $builder->where('username', 'like', "%{$keyword}%");
48
                });
49
            })
50
            ->filterColumn('country_code', function (Builder $builder, $keyword) {
51
                $countryCode = collect(countries())->search(function ($country) use ($keyword) {
52
                    return mb_strpos($country['name'], $keyword) !== false || mb_strpos($country['emoji'], $keyword) !== false;
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 127 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...
53
                });
54
55
                ! $countryCode || $builder->where('country_code', $countryCode);
56
            })
57
            ->filterColumn('language_code', function (Builder $builder, $keyword) {
58
                $languageCode = collect(languages())->search(function ($language) use ($keyword) {
59
                    return mb_strpos($language['name'], $keyword) !== false;
60
                });
61
62
                ! $languageCode || $builder->where('language_code', $languageCode);
63
            })
64
            ->orderColumn('name', 'name->"$.'.app()->getLocale().'" $1')
65
            ->make(true);
66
    }
67
68
    /**
69
     * Get columns.
70
     *
71
     * @return array
72
     */
73
    protected function getColumns(): array
74
    {
75
        $link = config('cortex.foundation.route.locale_prefix')
76
            ? '"<a href=\""+routes.route(\'adminarea.tenants.edit\', {tenant: full.id, locale: \''.$this->request->segment(1).'\'})+"\">"+data+"</a>"'
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 150 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...
77
            : '"<a href=\""+routes.route(\'adminarea.tenants.edit\', {tenant: full.id})+"\">"+data+"</a>"';
78
79
        return [
80
            'name' => ['title' => trans('cortex/tenants::common.name'), 'render' => $link.'+(full.is_active ? " <i class=\"text-success fa fa-check\"></i>" : " <i class=\"text-danger fa fa-close\"></i>")', 'responsivePriority' => 0],
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 233 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...
81
            'email' => ['title' => trans('cortex/tenants::common.email')],
82
            'phone' => ['title' => trans('cortex/tenants::common.phone')],
83
            'owner' => ['title' => trans('cortex/tenants::common.owner'), 'data' => 'owner.username'],
84
            'country_code' => ['title' => trans('cortex/tenants::common.country'), 'render' => 'full.country_emoji+" "+data'],
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 126 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...
85
            'language_code' => ['title' => trans('cortex/tenants::common.language')],
86
            'created_at' => ['title' => trans('cortex/tenants::common.created_at'), 'render' => "moment(data).format('MMMM Do YYYY, hh:mm:ss A')"],
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 147 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/tenants::common.updated_at'), 'render' => "moment(data).format('MMMM Do YYYY, hh:mm:ss A')"],
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 147 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