InvalidArgumentException::create()   B
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 30
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 30
rs 8.5806
cc 4
eloc 21
nc 4
nop 5
1
<?php
2
3
/**
4
 * This file is part of the Axstrad library.
5
 *
6
 * (c) Dan Kempster <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 *
11
 * @copyright 2014-2015 Dan Kempster <[email protected]>
12
 */
13
14
namespace Axstrad\Common\Exception;
15
16
use Axstrad\Common\Util\Debug;
17
18
/**
19
 * Axstrad\Common\Exception\InvalidArgumentException
20
 *
21
 * @author Dan Kempster <[email protected]>
22
 * @license MIT
23
 * @package Axstrad/Common
24
 * @subpackage Exception
25
 */
26
class InvalidArgumentException extends \InvalidArgumentException implements
27
    Exception
28
{
29
    /**
30
     * Invalid Argument exception factory
31
     *
32
     * @param string $expected
33
     * @param mixed $actual
34
     * @param null|integer $paramNo
35
     * @param null|integer $code
36
     * @param null|\Exception $previous
37
     * @return InvalidArgumentException A new instance of self
38
     */
39
    public static function create(
40
        $expected,
41
        $actual,
42
        $paramNo = null,
43
        $code = null,
44
        $previous = null
45
    ) {
46
        $msgMsk = 'Expected %1$s. Got %2$s';
47
48
        if ($paramNo !== null) {
49
            $msgMsk = 'Param #%3$s '.lcfirst($msgMsk);
50
        }
51
52
        if ($code !== null) {
53
            $msgMsk = '[%4$s] '.$msgMsk;
54
        }
55
56
        $class = get_called_class();
57
        return new $class(
58
            sprintf(
59
                $msgMsk,
60
                $expected,
61
                Debug::summarise($actual),
62
                $paramNo,
63
                $code
64
            ),
65
            is_int($code) ? $code : null,
66
            $previous
67
        );
68
    }
69
}
70