Completed
Pull Request — master (#1)
by steven
02:54
created

Language   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 43
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 2
A toNative() 0 3 1
A __toString() 0 3 1
1
<?php
2
3
namespace VSV\GVQ_API\Question;
4
5
class Language
6
{
7
    /**
8
     * @var string
9
     */
10
    private $value;
11
12
    /**
13
     * @var string[]
14
     */
15
    private $supportedLanguages = [
16
        'nl',
17
        'fr',
18
    ];
19
20
    /**
21
     * @param string $value
22
     */
23
    public function __construct(string $value)
24
    {
25
        if (!in_array($value, $this->supportedLanguages)) {
26
            throw new \InvalidArgumentException(
27
                'Given language ' . $value . ' is not supported, only nl en fr are allowed.'
28
            );
29
        }
30
31
        $this->value = $value;
32
    }
33
34
    /**
35
     * @return string
36
     */
37
    public function toNative(): string
38
    {
39
        return $this->value;
40
    }
41
42
    /**
43
     * @return string
44
     */
45
    public function __toString(): string
46
    {
47
        return $this->toNative();
48
    }
49
}
50