gwTypeExceptionInfo::fetch()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 2 Features 1
Metric Value
c 3
b 2
f 1
dl 0
loc 11
rs 9.4286
cc 2
eloc 7
nc 2
nop 0
1
<?php
2
3
namespace Gwa\Exception;
4
5
/**
6
 * An exception info container for type exceptions.
7
 */
8
class gwTypeExceptionInfo extends gwCoreExceptionInfo implements gwiExceptionInfo
9
{
10
    /**
11
     * @var mixed
12
     */
13
    protected $value;
14
15
    /**
16
     * @var array
17
     */
18
    protected $types;
19
20
    /**
21
     * @var string
22
     */
23
    protected $note;
24
25
    /**
26
     * Constructor.
27
     *
28
     * @param mixed        $value the actual value that caused the exception
29
     * @param array|string $types a list of legal types
30
     * @param string       $note  an optional note
31
     */
32
    public function __construct($value, $types, $note = '')
33
    {
34
        $this->value = $value;
35
        $this->types = is_array($types) ? $types : [$types];
36
        $this->note = $note;
37
    }
38
39
    /**
40
     * @return string
41
     */
42
    public function fetch()
43
    {
44
        $value = $this->getAsString($this->value);
45
        $values = implode(', ', $this->types);
46
        $output = sprintf('%s MUST BE one of the following types [%s]', $value, $values);
47
        if ($this->note) {
48
            $output .= ' ('.$this->note.')';
49
        }
50
51
        return $output;
52
    }
53
}
54