gwRangeExceptionInfo   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 4
Bugs 3 Features 2
Metric Value
wmc 5
c 4
b 3
f 2
lcom 1
cbo 1
dl 0
loc 72
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A fetch() 0 14 2
A getMaximum() 0 4 1
A getMinimum() 0 4 1
1
<?php
2
3
namespace Gwa\Exception;
4
5
/**
6
 * An exception info container for out of range exceptions.
7
 */
8
class gwRangeExceptionInfo extends gwCoreExceptionInfo implements gwiExceptionInfo
9
{
10
    /**
11
     * @var int
12
     */
13
    protected $value;
14
15
    /**
16
     * @var int
17
     */
18
    protected $maximum;
19
20
    /**
21
     * @var int
22
     */
23
    protected $minimum;
24
25
    /**
26
     * @var string
27
     */
28
    protected $note;
29
30
    /**
31
     * Constructor.
32
     *
33
     * @param int    $value   the actual value that caused the exception
34
     * @param int    $minimum the minimum legal value
35
     * @param int    $maximum the maximum legal value
36
     * @param string $note    an optional note
37
     */
38
    public function __construct($value, $minimum, $maximum, $note = '')
39
    {
40
        $this->value = $value;
41
        $this->minimum = $minimum;
42
        $this->maximum = $maximum;
43
        $this->note = $note;
44
    }
45
46
    /**
47
     * @return string
48
     */
49
    public function fetch()
50
    {
51
        $output = sprintf(
52
            '%s MUST BE within the range of [%s to %s]',
53
            $this->value,
54
            $this->minimum,
55
            $this->maximum
56
        );
57
        if ($this->note) {
58
            $output .= ' ('.$this->note.')';
59
        }
60
61
        return $output;
62
    }
63
64
    /**
65
     * @return int
66
     */
67
    public function getMaximum()
68
    {
69
        return $this->maximum;
70
    }
71
72
    /**
73
     * @return int
74
     */
75
    public function getMinimum()
76
    {
77
        return $this->minimum;
78
    }
79
}
80