AbstractInvalidTypeException::__construct()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 4
nc 4
nop 5
crap 3
1
<?php
2
namespace GenericCollections\Exceptions;
3
4
/**
5
 * AbstractInvalidTypeException
6
 *
7
 * This abstract class provides a template for the extended classes:
8
 * - InvalidKeyTypeException
9
 * - InvalidElementTypeException
10
 * - InvalidValueTypeException
11
 * - InvalidDefaultValueTypeException
12
 *
13
 * @package GenericCollections\Exceptions
14
 */
15
abstract class AbstractInvalidTypeException extends GenericCollectionsException
16
{
17
    /**
18
     * This property define the name of the property
19
     * @var string
20
     */
21
    protected $propertyName = '';
22
23
    /**
24
     * Invalid Property Type
25
     *
26
     * @param string            $container      Description of the container, like 'Map'
27
     * @param string            $expectedType   Description of the expected type
28
     * @param mixed             $source         Object name or object that throws the exception
29
     * @param int               $code           Exception code
30
     * @param \Exception|null   $previous       Previous exception
31
     */
32 11
    public function __construct($container, $expectedType, $source, $code = 0, \Exception $previous = null)
33
    {
34 11
        $source = (is_object($source)) ? get_class($source) : (is_string($source) ? $source : '(unknown)');
35 11
        $message = "Invalid {$this->propertyName} type; the $container $source was expecting a $expectedType type";
36 11
        parent::__construct($message, $code, $previous);
37 11
    }
38
}
39