InvalidTypeException   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 0
loc 27
ccs 18
cts 18
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A buildMessage() 0 16 2
1
<?php
2
3
/*
4
 * This file is part of the JVal package.
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
namespace JVal\Exception\Constraint;
11
12
use JVal\Context;
13
use JVal\Exception\ConstraintException;
14
15
class InvalidTypeException extends ConstraintException
16
{
17
    private $expectedType;
18
19 37
    public function __construct(Context $context, $expected)
20
    {
21 37
        $this->expectedType = $expected;
22 37
        parent::__construct($context);
23 37
    }
24
25 37
    protected function buildMessage()
26
    {
27 37
        if (is_array($this->expectedType)) {
28 5
            $this->message = sprintf(
29 5
                '%s type must be one of the following: %s',
30 5
                $this->getTargetNode(),
31 5
                implode(', ', $this->expectedType)
32 5
            );
33 5
        } else {
34 32
            $this->message = sprintf(
35 32
                '%s must be of type %s',
36 32
                $this->getTargetNode(),
37 32
                $this->expectedType
38 32
            );
39
        }
40 37
    }
41
}
42