Passed
Branch 6.0 (c154c1)
by Olivier
11:35
created

Mutable::getIterator()   A

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
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
/*
4
 * This file is part of the ICanBoogie package.
5
 *
6
 * (c) Olivier Laviale <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace ICanBoogie\Render\EngineProvider;
13
14
use ArrayIterator;
15
use ICanBoogie\Render\Engine;
16
use ICanBoogie\Render\ExtensionResolver;
17
use ICanBoogie\Render\MutableEngineProvider;
18
use IteratorAggregate;
19
use Traversable;
20
21
/**
22
 * A mutable engine provider.
23
 *
24
 * @implements IteratorAggregate<string, Engine>
25
 *     Where _key_ is a file extension.
26
 */
27
final class Mutable implements MutableEngineProvider, IteratorAggregate
28
{
29
    /**
30
     * @var array<string, Engine>
31
     *     Where _key_ is an extension e.g. ".php" and _value_ is an Engine.
32
     */
33
    private array $engines = [];
34
35
    public function engine_for_extension(string $extension): ?Engine
36
    {
37
        ExtensionResolver::assert_extension($extension);
38
39
        return $this->engines[$extension] ?? null;
40
    }
41
42
    public function add_engine(string $extension, Engine $engine): void
43
    {
44
        ExtensionResolver::assert_extension($extension);
45
46
        $this->engines[$extension] = $engine;
47
    }
48
49
    public function getIterator(): Traversable
50
    {
51
        return new ArrayIterator($this->engines);
52
    }
53
}
54