Bookmark::setLoader()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 5
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Tleckie\Translate;
6
7
use ArrayIterator;
8
use Tleckie\Translate\Bookmark\BookmarkInterface;
9
use Tleckie\Translate\Catalogue\CatalogueInterface;
10
use Tleckie\Translate\Loader\LoaderInterface;
11
12
/**
13
 * Class Bookmark
14
 *
15
 * @package  Tleckie\Translate
16
 * @category Bookmark
17
 * @author   Teodoro Leckie Westberg <[email protected]>
18
 */
19
class Bookmark implements BookmarkInterface
20
{
21
    /**
22
     * @var ArrayIterator<CatalogueInterface>
23
     */
24
    protected ArrayIterator $catalogs;
25
26
    /**
27
     * @var LoaderInterface
28
     */
29
    protected LoaderInterface $loader;
30
31
    /**
32
     * Bookmark constructor.
33
     */
34
    public function __construct()
35
    {
36
        $this->catalogs = new ArrayIterator();
37
    }
38
39
    /**
40
     * @inheritdoc
41
     */
42
    public function setLoader(LoaderInterface $loader): BookmarkInterface
43
    {
44
        $this->loader = $loader;
45
46
        return $this;
47
    }
48
49
    /**
50
     * @inheritdoc
51
     */
52
    public function getCatalogue(string $locale): CatalogueInterface
53
    {
54
        if ($this->hasCatalogue($locale)) {
55
            return $this->catalogs[$locale];
56
        }
57
58
        return $this->catalogs[$locale] = new Catalogue($this->loader->load($locale));
59
    }
60
61
    /**
62
     * @inheritdoc
63
     */
64
    public function hasCatalogue(string $locale): bool
65
    {
66
        return isset($this->catalogs[$locale]);
67
    }
68
}
69