Completed
Pull Request — master (#276)
by Kristof
07:05
created

Language::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 1
1
<?php
2
3
namespace CultuurNet\UDB3;
4
5
class Language
6
{
7
    protected $code;
8
    /**
9
     * @param $code
10
     */
11
    public function __construct($code)
12
    {
13
        if (!preg_match('/^[a-z]{2}$/', $code)) {
14
            throw new \InvalidArgumentException(
15
                'Invalid language code: ' . $code
16
            );
17
        }
18
        $this->code = $code;
19
    }
20
21
    public function __toString()
22
    {
23
        return $this->code;
24
    }
25
26
    public function getCode()
27
    {
28
        return $this->code;
29
    }
30
}
31