gwTypeExceptionInfo   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 2
A fetch() 0 11 2
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