LocaleCollection   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
dl 0
loc 49
rs 10
c 1
b 0
f 0
wmc 7

5 Methods

Rating   Name   Duplication   Size   Complexity  
A fromArrayLocales() 0 8 2
A fromArray() 0 8 2
A toArray() 0 3 1
A isEmpty() 0 3 1
A add() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Lochmueller\LanguageDetection\Domain\Collection;
6
7
use Lochmueller\LanguageDetection\Domain\Model\Dto\LocaleValueObject;
8
9
class LocaleCollection
10
{
11
    /**
12
     * @var array<LocaleValueObject>
13
     */
14
    protected array $locales = [];
15
16
    public function add(LocaleValueObject $locale): void
17
    {
18
        $this->locales[] = $locale;
19
    }
20
21
    /**
22
     * @return array<LocaleValueObject>
23
     */
24
    public function toArray(): array
25
    {
26
        return $this->locales;
27
    }
28
29
    public function isEmpty(): bool
30
    {
31
        return $this->locales === [];
32
    }
33
34
    /**
35
     * @param array<string> $locales
36
     */
37
    public static function fromArray(array $locales): self
38
    {
39
        $collection = new self();
40
        foreach ($locales as $item) {
41
            $collection->add(new LocaleValueObject($item));
42
        }
43
44
        return $collection;
45
    }
46
47
    /**
48
     * @param array<LocaleValueObject> $locales
49
     */
50
    public static function fromArrayLocales(array $locales): self
51
    {
52
        $collection = new self();
53
        foreach ($locales as $item) {
54
            $collection->add($item);
55
        }
56
57
        return $collection;
58
    }
59
}
60