GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 637663...b3b3ba )
by butschster
12s
created

Custom::toArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace SleepingOwl\Admin\Display\Column;
4
5
use Closure;
6
use Illuminate\Database\Eloquent\Model;
7
use SleepingOwl\Admin\Display\TableColumn;
8
9
class Custom extends TableColumn
10
{
11
    /**
12
     * Callback to render column contents.
13
     * @var Closure
14
     */
15
    protected $callback;
16
17
    /**
18
     * @var string
19
     */
20
    protected $view = 'column.custom';
21
22
    /**
23
     * A field that can be ordered
24
     * @var string
25
     */
26
    protected $orderField;
27
28
    /**
29
     * Custom constructor.
30
     *
31
     * @param null|string $label
32
     * @param Closure $callback
33
     */
34 View Code Duplication
    public function __construct($label = null, Closure $callback = null)
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...
35
    {
36
        parent::__construct($label);
37
        if (! is_null($callback)) {
38
            $this->setCallback($callback);
39
        }
40
    }
41
42
    /**
43
     * @return Closure
44
     */
45
    public function getCallback()
46
    {
47
        return $this->callback;
48
    }
49
50
    /**
51
     * @param Closure $callback
52
     *
53
     * @return $this
54
     */
55
    public function setCallback(Closure $callback)
56
    {
57
        $this->callback = $callback;
58
59
        return $this;
60
    }
61
62
    /**
63
     * @param string $field
64
     *
65
     * @return $this
66
     */
67
    public function setOrderField($field)
68
    {
69
        $this->orderField = $field;
70
71
        return $this;
72
    }
73
74
    /**
75
     * @return string
76
     */
77
    public function getOrderField()
78
    {
79
        return $this->orderField;
80
    }
81
82
    /**
83
     * Get value from callback.
84
     *
85
     * @param Model $model
86
     *
87
     * @return mixed
88
     * @throws \Exception
89
     */
90
    protected function getValue(Model $model)
91
    {
92
        if (! is_callable($callback = $this->getCallback())) {
93
            throw new \Exception('Invalid custom column callback');
94
        }
95
96
        return call_user_func($callback, $model);
97
    }
98
99
    /**
100
     * @return array
101
     * @throws \Exception
102
     */
103
    public function toArray()
104
    {
105
        return parent::toArray() + [
106
            'value'  => $this->getValue($this->getModel()),
107
            'append' => $this->getAppends(),
108
        ];
109
    }
110
}
111