BaseSize::__construct()   A
last analyzed

Complexity

Conditions 4
Paths 2

Size

Total Lines 18
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 4

Importance

Changes 0
Metric Value
dl 0
loc 18
ccs 13
cts 13
cp 1
rs 9.2
c 0
b 0
f 0
cc 4
eloc 11
nc 2
nop 2
crap 4
1
<?php
2
3
/**
4
 * This file is part of InFw\File package.
5
 */
6
7
namespace InFw\Size;
8
9
use InFw\Range\RangeInterface;
10
11
/**
12
 * Class Size.
13
 */
14
class BaseSize implements SizeInterface
15
{
16
    /**
17
     * Size.
18
     *
19
     * @var int
20
     */
21
    private $size;
22
23
    /**
24
     * Size range.
25
     *
26
     * @var RangeInterface
27
     */
28
    private $range;
29
30
    /**
31
     * Size constructor.
32
     *
33
     * @param $size
34
     * @param RangeInterface $range
35
     */
36 15
    public function __construct($size, RangeInterface $range)
37
    {
38 15
        $this->range = $range;
39
40
        if (
41 15
            false === is_int($size)
42 13
            || $size < $this->range->getMin()
43 10
            || $size > $this->range->getMax()
44 5
        ) {
45 6
            throw new \InvalidArgumentException(sprintf(
46 6
                'Size must be between %s and %s.',
47 6
                $this->range->getMin(),
48 6
                $this->range->getMax()
49 2
            ));
50
        }
51
52 9
        $this->size = $size;
53 9
    }
54
55
    /**
56
     * Get size as a number.
57
     *
58
     * @return int
59
     */
60 6
    public function get()
61
    {
62 6
        return $this->size;
63
    }
64
65
    /**
66
     * Get size range.
67
     *
68
     * @return RangeInterface
69
     */
70 6
    public function getRange()
71
    {
72 6
        return $this->range;
73
    }
74
}
75