InvalidDateException::__construct()   B
last analyzed

Complexity

Conditions 7
Paths 7

Size

Total Lines 23
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 19
c 1
b 0
f 0
dl 0
loc 23
rs 8.8333
cc 7
nc 7
nop 1
1
<?php declare(strict_types=1);
2
/**
3
 * This file is part of the Yasumi package.
4
 *
5
 * Copyright (c) 2015 - 2020 AzuyaLabs
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @author Sacha Telgenhof <[email protected]>
11
 */
12
13
namespace Yasumi\Exception;
14
15
use InvalidArgumentException;
16
17
/**
18
 * Class InvalidDateException.
19
 */
20
class InvalidDateException extends InvalidArgumentException implements Exception
21
{
22
23
    /**
24
     * Initializes the Exception instance
25
     *
26
     * @param mixed $argumentValue The value of the invalid argument
27
     */
28
    public function __construct($argumentValue)
29
    {
30
        $type = \gettype($argumentValue);
31
        switch ($type) {
32
            case 'boolean':
33
                $displayName = $argumentValue ? 'true' : 'false';
34
                break;
35
            case 'integer':
36
            case 'double':
37
                $displayName = (string) $argumentValue;
38
                break;
39
            case 'string':
40
                $displayName = $argumentValue;
41
                break;
42
            case 'object':
43
                $displayName = \get_class($argumentValue);
44
                break;
45
            default:
46
                $displayName = $type;
47
                break;
48
        }
49
50
        parent::__construct(\sprintf(\sprintf('\'%s\' is not a valid DateTime(Immutable) instance', $displayName)));
51
    }
52
}
53