InvalidArgumentException   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 3
Bugs 1 Features 0
Metric Value
c 3
b 1
f 0
dl 0
loc 33
rs 10
wmc 2
lcom 0
cbo 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A validateArgument() 0 16 2
1
<?php
2
namespace Crossjoin\Json\Exception;
3
4
/**
5
 * Class InvalidArgumentException
6
 *
7
 * @package Crossjoin\Json\Exception
8
 * @author Christoph Ziegenberg <[email protected]>
9
 */
10
class InvalidArgumentException extends \InvalidArgumentException implements JsonException
11
{
12
    const TYPE_INTEGER = 'integer';
13
    const TYPE_STRING  = 'string';
14
    const TYPE_BOOLEAN = 'boolean';
15
16
    /** @noinspection MoreThanThreeArgumentsInspection */
17
    /**
18
     * @param $expectedType
19
     * @param $argumentName
20
     * @param $currentValue
21
     * @param $code
22
     *
23
     * @return bool
24
     * @throws \Crossjoin\Json\Exception\InvalidArgumentException
25
     */
26
    public static function validateArgument($expectedType, $argumentName, $currentValue, $code)
27
    {
28
        if (gettype($currentValue) !== $expectedType) {
29
            throw new self(
30
                sprintf(
31
                    "%s expected for argument '%s'. Got '%s'.",
32
                    ucfirst(strtolower($expectedType)),
33
                    $argumentName,
34
                    gettype($currentValue)
35
                ),
36
                $code
37
            );
38
        }
39
40
        return true;
41
    }
42
}
43