LocaleCollection::isEmpty()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 1
b 0
f 0
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