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 — analysis-rdw4o3 ( a6c473 )
by butschster
12:11
created

Column::setWidth()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace SleepingOwl\Admin\Form\Columns;
4
5
use Exception;
6
use KodiComponents\Support\HtmlAttributes;
7
use SleepingOwl\Admin\Contracts\Form\Columns\ColumnInterface;
8
use SleepingOwl\Admin\Form\FormElements;
9
use SleepingOwl\Admin\Traits\Width;
10
11
class Column extends FormElements implements ColumnInterface
12
{
13
    use HtmlAttributes, Width;
14
15
    /**
16
     * @var int
17
     */
18
    protected $size = 'col-md-';
19
20
    /**
21
     * @var string
22
     */
23
    protected $view = 'form.element.column';
24
25
    /**
26
     * @throws \Exception
27
     */
28
    public function initialize()
29
    {
30
        parent::initialize();
31
32
        $this->setHtmlAttribute('class', $this->getClass());
33
    }
34
35
    /**
36
     * @return string
37
     */
38
    public function getSize()
39
    {
40
        return $this->size;
41
    }
42
43
    /**
44
     * @param string $size
45
     *
46
     * @return $this
47
     */
48
    public function setSize($size)
49
    {
50
        if (strpos($size, 'col-') === false) {
51
            $size = 'col-'.$size.'-';
52
        }
53
54
        $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...
55
56
        return $this;
57
    }
58
59
    /**
60
     * @return string
61
     * @throws \Exception
62
     */
63
    protected function getClass()
64
    {
65
        $width = $this->getWidth();
66
        if (is_numeric($width)) {
67
            $class = $this->getSize().$width;
68
        } elseif (is_array($width) && count($width)) {
69
            $class = implode(' ', $width);
70
        } elseif (is_string($width)) {
71
            $class = $width;
72
        } else {
73
            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)');
74
        }
75
76
        return $class;
77
    }
78
79
    /**
80
     * @return array
81
     * @throws \Exception
82
     */
83
    public function toArray()
84
    {
85
        return parent::toArray() + [
86
            'width' => $this->getWidth(),
87
            'elements' => $this->getElements()->onlyVisible(),
88
            'attributes' => $this->htmlAttributesToString(),
89
        ];
90
    }
91
}
92