InvalidArgumentException::invalidType()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 1
nop 2
dl 0
loc 9
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\SAML2\Exception;
6
7
use InvalidArgumentException as BuiltinInvalidArgumentException;
8
9
use function get_class;
10
use function gettype;
11
use function is_object;
12
use function sprintf;
13
14
class InvalidArgumentException extends BuiltinInvalidArgumentException
15
{
16
    /**
17
     * @param string $expected description of expected type
18
     * @param mixed  $parameter the parameter that is not of the expected type.
19
     *
20
     * @return \SimpleSAML\SAML2\Exception\InvalidArgumentException
21
     */
22
    public static function invalidType(string $expected, $parameter): InvalidArgumentException
23
    {
24
        $message = sprintf(
25
            'Invalid Argument type: "%s" expected, "%s" given',
26
            $expected,
27
            is_object($parameter) ? get_class($parameter) : gettype($parameter),
28
        );
29
30
        return new self($message);
31
    }
32
}
33