Panel::setWidth()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
dl 0
loc 7
ccs 0
cts 4
cp 0
crap 2
rs 10
c 0
b 0
f 0
eloc 3
nc 1
nop 1
1
<?php
2
3
namespace Terranet\Administrator\Dashboard;
4
5
use Terranet\Administrator\Contracts\Services\Widgetable;
6
7
abstract class Panel implements Widgetable
8
{
9
    protected $width = 6;
10
11
    public function setWidth($width = 6)
12
    {
13
        $this->validateWidth($width);
14
15
        $this->width = (int) $width;
16
17
        return $this;
18
    }
19
20
    public function width()
21
    {
22
        return $this->width;
23
    }
24
25
    /**
26
     * @param $width
27
     *
28
     * @throws \Exception
29
     */
30
    protected function validateWidth($width)
31
    {
32
        if (!\in_array($width, range(1, 12, 1), true)) {
33
            throw new \Exception('Width must be between 1 and 12.');
34
        }
35
    }
36
}
37