Passed
Pull Request — master (#38)
by Teye
07:11
created

MultiValueHandling   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 10
c 1
b 0
f 0
dl 0
loc 23
ccs 7
cts 7
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A validate() 0 11 2
1
<?php
2
declare(strict_types=1);
3
4
namespace Level23\Druid\Types;
5
6
use InvalidArgumentException;
7
8
/**
9
 * Class MultiValueHandling
10
 *
11
 * @package Level23\Druid\Types
12
 */
13
final class MultiValueHandling extends Enum
14
{
15
    public const SORTED_ARRAY = 'SORTED_ARRAY';
16
    public const SORTED_SET   = 'SORTED_SET';
17
    public const ARRAY        = 'ARRAY';
18
19
    /**
20
     * @param string $multiValueHandling
21
     *
22
     * @return string
23
     * @throws InvalidArgumentException
24
     */
25 12
    public static function validate(string $multiValueHandling): string
26
    {
27 12
        $multiValueHandling = strtoupper($multiValueHandling);
28 12
        if (!MultiValueHandling::isValidValue($multiValueHandling)) {
29 5
            throw new InvalidArgumentException(
30 5
                'The given MultiValueHandling type is invalid: ' . $multiValueHandling . '. ' .
31 5
                'Allowed are: ' . implode(', ', MultiValueHandling::values())
32
            );
33
        }
34
35 7
        return $multiValueHandling;
36
    }
37
}