GeoipsDataTable   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 58
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A ajax() 0 13 3
A getColumns() 0 16 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cortex\Statistics\DataTables\Adminarea;
6
7
use Rinvex\Statistics\Models\Geoip;
8
use Illuminate\Database\Eloquent\Builder;
9
use Cortex\Foundation\DataTables\AbstractDataTable;
10
use Cortex\Statistics\Transformers\Adminarea\GeoipTransformer;
11
12
class GeoipsDataTable extends AbstractDataTable
13
{
14
    /**
15
     * {@inheritdoc}
16
     */
17
    protected $model = Geoip::class;
18
19
    /**
20
     * {@inheritdoc}
21
     */
22
    protected $transformer = GeoipTransformer::class;
23
24
    /**
25
     * {@inheritdoc}
26
     */
27
    protected $createButton = false;
28
29
    /**
30
     * Display ajax response.
31
     *
32
     * @return \Illuminate\Http\JsonResponse
33
     */
34
    public function ajax()
35
    {
36
        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...
37
            ->setTransformer(app($this->transformer))
38
            ->filterColumn('country_code', function (Builder $builder, $keyword) {
39
                $countryCode = collect(countries())->search(function ($country) use ($keyword) {
40
                    return mb_strpos($country['name'], $keyword) !== false || mb_strpos($country['emoji'], $keyword) !== false;
41
                });
42
43
                ! $countryCode || $builder->where('country_code', $countryCode);
44
            })
45
            ->make(true);
46
    }
47
48
    /**
49
     * Get columns.
50
     *
51
     * @return array
52
     */
53
    protected function getColumns(): array
54
    {
55
        return [
56
            'client_ip' => ['title' => trans('cortex/statistics::common.client_ip'), 'responsivePriority' => 0],
57
            'latitude' => ['title' => trans('cortex/statistics::common.latitude')],
58
            'longitude' => ['title' => trans('cortex/statistics::common.longitude')],
59
            'country_code' => ['title' => trans('cortex/statistics::common.country_code'), 'render' => 'full.country_emoji+" "+data'],
60
            'client_ips' => ['title' => trans('cortex/statistics::common.client_ips'), 'visible' => false],
61
            'is_from_trusted_proxy' => ['title' => trans('cortex/statistics::common.is_from_trusted_proxy')],
62
            'division_code' => ['title' => trans('cortex/statistics::common.division_code')],
63
            'postal_code' => ['title' => trans('cortex/statistics::common.postal_code')],
64
            'timezone' => ['title' => trans('cortex/statistics::common.timezone')],
65
            'city' => ['title' => trans('cortex/statistics::common.city')],
66
            'count' => ['title' => trans('cortex/statistics::common.count')],
67
        ];
68
    }
69
}
70