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

Validator::validateParamBool()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.0625

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
ccs 3
cts 4
cp 0.75
rs 9.4285
cc 2
eloc 3
nc 2
nop 2
crap 2.0625
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