InvalidArgumentException   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 5
c 0
b 0
f 0
dl 0
loc 17
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A invalidType() 0 9 2
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