Panel::validateWidth()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
dl 0
loc 4
ccs 0
cts 3
cp 0
crap 6
rs 10
c 0
b 0
f 0
eloc 2
nc 2
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