LanguageMap::setClosed()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php declare(strict_types = 1);
2
3
namespace JSKOS;
4
5
use InvalidArgumentException;
6
7
/**
8
 * Abstract base class of language maps.
9
 */
10
abstract class LanguageMap extends Container
11
{
12
    use Constructor;
13
14
    protected function setField($key, $value, $strict)
15
    {
16
        try {
17
            $this->offsetSet($key, $value);
18
        } catch (InvalidArgumentException $e) {
19
            if ($strict) {
20
                throw $e;
21
            }
22
        }
23
    }
24
25
    /**
26
     * Language maps are always closed world, so this does nothing.
27
     * @param Boolean $closed
28
     */
29
    public function setClosed(bool $closed = true)
30
    {
31
    }
32
33
    /**
34
     * Set an value at the given language or language range.
35
     * @param mixed $lang
36
     * @param mixed $value
37
     */
38
    public function offsetSet($lang, $value)
39
    {
40
        if (DataType::isLanguageOrRange($lang)) {
41
            if (is_null($value)) {
42
                unset($this->members[$lang]);
43
            } else {
44
                $this->members[$lang] = static::checkMember($value);
45
            }
46
        } else {
47
            throw new InvalidArgumentException(
48
                'JSKOS\LanguageMap may only use language tags or ranges as index'
49
            );
50
        }
51
    }
52
53
    /**
54
     * Unset a value with given language or language range.
55
     * @param mixed $lang
56
     */
57
    public function offsetUnset($lang)
58
    {
59
        unset($this->members[$lang]);
60
    }
61
}
62