BaseSize   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 1
dl 0
loc 61
ccs 17
cts 17
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 18 4
A get() 0 4 1
A getRange() 0 4 1
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