Completed
Push — location_references ( 47d67d )
by
unknown
13:55
created

NamedReferencesCollection::hasReference()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace eZ\Publish\Core\LocationReference\NamedReferences;
6
7
use ArrayIterator;
8
use Countable;
9
use eZ\Publish\Core\Base\Exceptions\NotFoundException;
10
use IteratorAggregate;
11
use Traversable;
12
13
final class NamedReferencesCollection implements IteratorAggregate, Countable
14
{
15
    /** @var string[] */
16
    private $references;
17
18
    public function __construct(array $references)
19
    {
20
        $this->references = $references;
21
    }
22
23
    public function getReference(string $name): string
24
    {
25
        if (!$this->hasReference($name)) {
26
            throw new NotFoundException('named reference', $name);
27
        }
28
29
        return $this->references[$name];
30
    }
31
32
    public function hasReference(string $name): bool
33
    {
34
        return isset($this->references[$name]);
35
    }
36
37
    public function getIterator(): Traversable
38
    {
39
        return new ArrayIterator($this->references);
40
    }
41
42
    public function count(): int
43
    {
44
        return count($this->references);
45
    }
46
}
47