Passed
Push — master ( 699175...c40f63 )
by Vincent
02:43
created

InvalidArgumentHelper   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A factory() 0 12 2
1
<?php
2
declare (strict_types = 1);
3
4
/*
5
 * This file is inspired from PHPUnit\Util\InvalidArgumentHelper.
6
 */
7
namespace VGirol\JsonApiAssert;
8
9
/**
10
 * Factory for VGirol\JsonApiAssert\Exception
11
 *
12
 * @internal
13
 */
14
final class InvalidArgumentHelper
15
{
16
    /**
17
     * Creates a new instance of VGirol\JsonApiAssert\Exception with customized message.
18
     *
19
     * @param integer $argument
20
     * @param string $type
21
     * @param mixed $value
22
     * @return Exception
23
     */
24
    public static function factory(int $argument, string $type, $value = null): Exception
25
    {
26
        $stack = \debug_backtrace();
27
28
        return new Exception(
29
            \sprintf(
30
                Exception::INVALID_ARGUMENT,
31
                $argument,
32
                $value !== null ? ' (' . \gettype($value) . '#' . $value . ')' : ' (No Value)',
33
                $stack[1]['class'],
34
                $stack[1]['function'],
35
                $type
36
            )
37
        );
38
    }
39
}
40