Completed
Push — master ( 88e368...e2f64d )
by Maxime
02:26
created

BaseDatatable   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 0
cbo 1
dl 0
loc 26
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A addTranslationAction() 0 15 2
A addDefaultAction() 0 4 1
1
<?php namespace Distilleries\Expendable\Http\Datatables;
2
3
use Distilleries\DatatableBuilder\EloquentDatatable;
4
use Distilleries\Expendable\Models\Language;
5
use Distilleries\Expendable\Models\Translation;
6
7
abstract class BaseDatatable extends EloquentDatatable {
8
9
10
    // ------------------------------------------------------------------------------------------------
11
    public function addTranslationAction($template = 'expendable::admin.form.components.datatable.translations', $route = '')
12
    {
13
        $this->add('translation', function ($model) use ($template, $route) {
14
15
            $languages    = Language::withoutCurrentLanguage()->get();
0 ignored issues
show
Bug introduced by
The method withoutCurrentLanguage() does not exist on Distilleries\Expendable\Models\Language. Did you maybe mean scopeWithoutCurrentLanguage()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
16
            $translations = Translation::byElement($model)->pluck('id_element','iso')->toArray();
0 ignored issues
show
Bug introduced by
The method byElement() does not exist on Distilleries\Expendable\Models\Translation. Did you maybe mean scopeByElement()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
17
            return view($template, array(
0 ignored issues
show
Bug introduced by
The method render does only exist in Illuminate\View\View, but not in Illuminate\Contracts\View\Factory.

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...
18
                'languages'    => $languages,
19
                'translations' => $translations,
20
                'data'         => $model->toArray(),
21
                'route'        => !empty($route) ? $route . '@' : $this->getControllerNameForAction() . '@'
22
            ))->render();
23
        });
24
25
    }
26
27
    // ------------------------------------------------------------------------------------------------
28
    public function addDefaultAction($template = 'expendable::admin.form.components.datatable.actions', $route = '')
29
    {
30
        parent::addDefaultAction($template, $route);
31
    }
32
}