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
Pull Request — master (#971)
by Dave
22:56 queued 17:27
created

Column::getClass()   A

Complexity

Conditions 5
Paths 4

Size

Total Lines 14
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 0
Metric Value
cc 5
eloc 10
nc 4
nop 0
dl 0
loc 14
ccs 0
cts 5
cp 0
crap 30
rs 9.6111
c 0
b 0
f 0
1
<?php
2
3
namespace SleepingOwl\Admin\Form\Columns;
4
5
use SleepingOwl\Admin\Form\FormElements;
6
use KodiComponents\Support\HtmlAttributes;
7
use SleepingOwl\Admin\Contracts\Form\Columns\ColumnInterface;
8
9
class Column extends FormElements implements ColumnInterface
10
{
11
    use HtmlAttributes;
12
13
    /**
14
     * @var int
15
     */
16
    protected $width;
17
18
    /**
19
     * @var int
20
     */
21
    protected $size = 'col-md-';
22
23
    /**
24
     * @var string
25
     */
26
    protected $view = 'form.element.column';
27
28
    public function initialize()
29
    {
30
        parent::initialize();
31
32
        $this->setHtmlAttribute('class', $this->getClass());
33
    }
34
35
    /**
36
     * @param int|array|string $width
37
     *
38
     * @return $this
39
     */
40
    public function setWidth($width)
41
    {
42
        $this->width = $width;
43
44
        return $this;
45
    }
46
47
    /**
48
     * @return int|array|string
49
     */
50
    public function getWidth()
51
    {
52
        return $this->width;
53
    }
54
55
    /**
56
     * @return string
57
     */
58
    public function getSize()
59
    {
60
        return $this->size;
61
    }
62
63
    /**
64
     * @param string $size
65
     *
66
     * @return $this
67
     */
68
    public function setSize($size)
69
    {
70
        if (strpos($size, 'col-') === false) {
71
            $size = 'col-'.$size.'-';
72
        }
73
74
        $this->size = $size;
0 ignored issues
show
Documentation Bug introduced by
The property $size was declared of type integer, but $size is of type string. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
75
76
        return $this;
77
    }
78
79
    /**
80
     * @return string
81
     * @throws \Exception
82
     */
83
    protected function getClass()
84
    {
85
        $width = $this->getWidth();
86
        if (is_numeric($width)) {
0 ignored issues
show
introduced by
The condition is_numeric($width) is always true.
Loading history...
87
            $class = $this->getSize().$width;
88
        } elseif (is_array($width) && count($width)) {
89
            $class = implode(' ', $width);
90
        } elseif (is_string($width)) {
91
            $class = $width;
92
        } else {
93
            throw new \Exception('Column width should be integer (numeric), string (for example: col-sm-12 col-md-6) or array (list of the Bootstrap classes)');
94
        }
95
96
        return $class;
97
    }
98
99
    /**
100
     * @return array
101
     * @throws \Exception
102
     */
103
    public function toArray()
104
    {
105
        return parent::toArray() + [
106
            'width' => $this->getWidth(),
107
            'elements' => $this->getElements()->onlyVisible(),
108
            'attributes' => $this->htmlAttributesToString(),
109
        ];
110
    }
111
}
112