Completed
Pull Request — master (#6)
by Carlos C
02:44
created

AbstractInvalidTypeException   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 0
cbo 1
dl 0
loc 25
ccs 5
cts 5
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 3
1
<?php namespace GenericCollections\Exceptions;
2
3
/**
4
 * AbstractInvalidTypeException
5
 *
6
 * This abstract class provides a template for the extended classes:
7
 * - InvalidKeyTypeException
8
 * - InvalidElementTypeException
9
 * - InvalidValueTypeException
10
 * - InvalidDefaultValueTypeException
11
 *
12
 * @package GenericCollections\Exceptions
13
 */
14
abstract class AbstractInvalidTypeException extends GenericCollectionsException
15
{
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