Passed
Pull Request — master (#38)
by Teye
05:43
created

NullHandling::validate()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 10
ccs 6
cts 6
cp 1
rs 10
cc 2
nc 2
nop 1
crap 2
1
<?php
2
declare(strict_types=1);
3
4
namespace Level23\Druid\Types;
5
6
use InvalidArgumentException;
7
8
/**
9
 * Class NullHandling
10
 *
11
 * @package Level23\Druid\Types
12
 */
13
class NullHandling extends Enum
0 ignored issues
show
Bug introduced by
A parse error occurred: Syntax error, unexpected T_ENUM, expecting T_STRING or T_NAME_QUALIFIED or T_NAME_FULLY_QUALIFIED or T_NAME_RELATIVE on line 13 at column 27
Loading history...
14
{
15
    public const NULL_STRING  = 'nullString';
16
    public const EMPTY_STRING = 'emptyString';
17
    public const RETURN_NULL  = 'returnNull';
18
19
    /**
20
     * @param string $nullHandling
21
     *
22
     * @return string
23
     * @throws InvalidArgumentException
24
     */
25 5
    public static function validate(string $nullHandling): string
26
    {
27 5
        if (!NullHandling::isValidValue($nullHandling)) {
28 1
            throw new InvalidArgumentException(
29 1
                'The given NullHandling value is invalid: ' . $nullHandling . '. ' .
30 1
                'Allowed are: ' . implode(',', NullHandling::values())
31
            );
32
        }
33
34 4
        return $nullHandling;
35
    }
36
}