Completed
Pull Request — master (#293)
by
unknown
02:49
created

Validator   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 87.5%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 0
cbo 0
dl 0
loc 36
ccs 7
cts 8
cp 0.875
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A validateParamString() 0 6 2
A validateParamBool() 0 6 2
1
<?php
2
3
namespace League\Fractal\Helper;
4
5
use InvalidArgumentException;
6
7
/**
8
 * Validator for function params.
9
 *
10
 * @package League\Fractal\Helper
11
 */
12
final class Validator
13
{
14
    const NOT_VALID_PARAM_TYPE = 'Param received "%s" is not valid. Should be %s.';
15
16
    /**
17
     * Evaluates that a parameter received on a function is type string.
18
     *
19
     * @param string $name The name of the parameter that is being evaluated.
20
     * @param mixed $value Value received on the function to be evaluated as string.
21
     *
22
     * @return void
23
     * @throws Not valid param received on function.
24
     */
25 2
    public static function validateParamString($name, $value)
26
    {
27 2
        if (!is_string($value)) {
28 1
            throw new InvalidArgumentException(sprintf(static::NOT_VALID_PARAM_TYPE, $name, 'string'));
29
        }
30 1
    }
31
32
    /**
33
     * Evaluates that a parameter received on a function is type boolean.
34
     *
35
     * @param string $name The name of the parameter that is being evaluated.
36
     * @param mixed $value Value received on the function to be evaluated as boolean.
37
     *
38
     * @return void
39
     * @throws Not valid param received on function.
40
     */
41 1
    public static function validateParamBool($name, $value)
42
    {
43 1
        if (!is_bool($value)) {
44 1
            throw new InvalidArgumentException(sprintf(static::NOT_VALID_PARAM_TYPE, $name, 'boolean'));
45
        }
46
    }
47
}
48