Completed
Push — develop ( de5894...783f37 )
by Abdelrahman
01:33
created

ContactsDataTable::ajax()   A

Complexity

Conditions 3
Paths 1

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 13
rs 9.4285
cc 3
eloc 8
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cortex\Contacts\DataTables\Adminarea;
6
7
use Cortex\Contacts\Models\Contact;
8
use Illuminate\Database\Eloquent\Builder;
9
use Cortex\Foundation\DataTables\AbstractDataTable;
10
use Cortex\Contacts\Transformers\Adminarea\ContactTransformer;
11
12
class ContactsDataTable extends AbstractDataTable
13
{
14
    /**
15
     * {@inheritdoc}
16
     */
17
    protected $model = Contact::class;
18
19
    /**
20
     * {@inheritdoc}
21
     */
22
    protected $transformer = ContactTransformer::class;
23
24
    /**
25
     * Display ajax response.
26
     *
27
     * @return \Illuminate\Http\JsonResponse
28
     */
29
    public function ajax()
30
    {
31
        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...
32
            ->setTransformer($this->transformer)
33
            ->filterColumn('country_code', function (Builder $builder, $keyword) {
34
                $countryCode = collect(countries())->search(function($country) use ($keyword) {
35
                    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...
36
                });
37
38
                ! $countryCode || $builder->where('country_code', $countryCode);
39
            })
40
            ->make(true);
41
    }
42
43
    /**
44
     * Get columns.
45
     *
46
     * @return array
47
     */
48
    protected function getColumns(): array
49
    {
50
        $link = config('cortex.foundation.route.locale_prefix')
51
            ? '"<a href=\""+routes.route(\'adminarea.contacts.edit\', {contact: 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 152 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...
52
            : '"<a href=\""+routes.route(\'adminarea.contacts.edit\', {contact: full.id})+"\">"+data+"</a>"';
53
54
        return [
55
            'full_name' => ['title' => trans('cortex/contacts::common.full_name'), 'render' => $link, 'responsivePriority' => 0],
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 129 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...
56
            'email' => ['title' => trans('cortex/contacts::common.email')],
57
            'phone' => ['title' => trans('cortex/contacts::common.phone')],
58
            'country_code' => ['title' => trans('cortex/contacts::common.country')],
59
            'language_code' => ['title' => trans('cortex/contacts::common.language'), 'visible' => false],
60
            'source' => ['title' => trans('cortex/contacts::common.source'), 'visible' => false],
61
            'method' => ['title' => trans('cortex/contacts::common.method'), 'visible' => false],
62
            'created_at' => ['title' => trans('cortex/contacts::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 136 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...
63
            'updated_at' => ['title' => trans('cortex/contacts::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 136 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...
64
        ];
65
    }
66
}
67