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
c 0
b 0
f 0
nc 1
nop 2
dl 0
loc 9
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\XMLSecurity\Exception;
6
7
use InvalidArgumentException as BuiltinInvalidArgumentException;
8
9
use function gettype;
10
use function is_object;
11
use function sprintf;
12
13
/**
14
 * Class InvalidArgumentException
15
 *
16
 * This exception is thrown when a parameter is passed to a method with the wrong type or contents.
17
 *
18
 * @package simplesamlphp/xml-security
19
 */
20
class InvalidArgumentException extends BuiltinInvalidArgumentException
21
{
22
    /**
23
     * @param string $expected description of expected type
24
     * @param mixed  $parameter the parameter that is not of the expected type.
25
     *
26
     * @return \SimpleSAML\XMLSecurity\Exception\InvalidArgumentException
27
     */
28
    public static function invalidType(string $expected, mixed $parameter): self
29
    {
30
        $message = sprintf(
31
            'Invalid Argument type: "%s" expected, "%s" given',
32
            $expected,
33
            is_object($parameter) ? $parameter::class : gettype($parameter),
34
        );
35
36
        return new self($message);
37
    }
38
}
39