InvalidTypeException::buildMessage()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 16
ccs 14
cts 14
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 11
nc 2
nop 0
crap 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