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

JoinType::validate()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 11
ccs 7
cts 7
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 JoinType
10
 *
11
 * @package Level23\Druid\Types
12
 */
13
final class JoinType extends Enum
14
{
15
    public const INNER = 'INNER';
16
    public const LEFT  = 'LEFT';
17
18
    /**
19
     * @param string $joinType
20
     *
21
     * @return string
22
     * @throws InvalidArgumentException
23
     */
24 11
    public static function validate(string $joinType): string
25
    {
26 11
        $joinType = strtoupper($joinType);
27 11
        if (!JoinType::isValidValue($joinType)) {
28 3
            throw new InvalidArgumentException(
29 3
                'The given join type is invalid: ' . $joinType . '. ' .
30 3
                'Allowed are: ' . implode(', ', JoinType::values())
31
            );
32
        }
33
34 8
        return $joinType;
35
    }
36
}