Completed
Push — master ( 88ab05...dae06d )
by Song
02:49
created

BelongsTo::display()   A

Complexity

Conditions 4
Paths 2

Size

Total Lines 19

Duplication

Lines 5
Ratio 26.32 %

Importance

Changes 0
Metric Value
cc 4
nc 2
nop 2
dl 5
loc 19
rs 9.6333
c 0
b 0
f 0
1
<?php
2
3
namespace Encore\Admin\Grid\Displayers;
4
5
use Encore\Admin\Admin;
6
use Encore\Admin\Grid\Selectable;
7
8
class BelongsTo extends AbstractDisplayer
9
{
10
    /**
11
     * @param int $multiple
12
     *
13
     * @return string
14
     */
15 View Code Duplication
    protected function getLoadUrl($selectable, $multiple = 0)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
16
    {
17
        $selectable = str_replace('\\', '_', $selectable);
18
        $args = [$multiple];
19
20
        return route('admin.handle-selectable', compact('selectable', 'args'));
21
    }
22
23
    /**
24
     * @return mixed
25
     */
26
    protected function getOriginalData()
27
    {
28
        return $this->getColumn()->getOriginal();
29
    }
30
31
    /**
32
     * @param string $selectable
33
     * @param string $column
34
     *
35
     * @return string
36
     */
37
    public function display($selectable = null, $column = '')
38
    {
39 View Code Duplication
        if (!class_exists($selectable) || !is_subclass_of($selectable, Selectable::class)) {
0 ignored issues
show
Bug introduced by
Due to PHP Bug #53727, is_subclass_of might return inconsistent results on some PHP versions if \Encore\Admin\Grid\Selectable::class can be an interface. If so, you could instead use ReflectionClass::implementsInterface.
Loading history...
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
40
            throw new \InvalidArgumentException(
41
                "[Class [{$selectable}] must be a sub class of Encore\Admin\Grid\Selectable"
42
            );
43
        }
44
45
        return Admin::component('admin::grid.inline-edit.belongsto', [
46
            'modal'     => sprintf('modal-grid-selector-%s', $this->getClassName()),
47
            'key'       => $this->getKey(),
48
            'original'  => $this->getOriginalData(),
49
            'value'     => $this->getValue(),
50
            'resource'  => $this->getResource(),
51
            'name'      => $column ?: $this->getName(),
52
            'relation'  => get_called_class(),
53
            'url'       => $this->getLoadUrl($selectable, get_called_class() == BelongsToMany::class),
0 ignored issues
show
Documentation introduced by
get_called_class() == \E...rs\BelongsToMany::class is of type boolean, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
54
        ]);
55
    }
56
}
57