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

Immutable::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 ICanBoogie\Render\Engine;
15
use ICanBoogie\Render\EngineProvider;
16
use IteratorAggregate;
17
use Traversable;
18
19
/**
20
 * An immutable engine provider.
21
 *
22
 * @implements IteratorAggregate<string, Engine>
23
 *     Where _key_ is a file extension.
24
 */
25
final class Immutable implements EngineProvider, IteratorAggregate
26
{
27
    private readonly Mutable $mutable;
28
29
    /**
30
     * @param array<string, Engine> $engines
31
     *     Where _key_ is an extension e.g. ".php" and _value_ is an Engine.
32
     */
33
    public function __construct(array $engines = [])
34
    {
35
        $this->mutable = new Mutable();
0 ignored issues
show
Bug introduced by
The property mutable is declared read-only in ICanBoogie\Render\EngineProvider\Immutable.
Loading history...
36
37
        foreach ($engines as $extension => $engine) {
38
            $this->mutable->add_engine($extension, $engine);
39
        }
40
    }
41
42
    public function engine_for_extension(string $extension): ?Engine
43
    {
44
        return $this->mutable->engine_for_extension($extension);
45
    }
46
47
    public function getIterator(): Traversable
48
    {
49
        return $this->mutable->getIterator();
50
    }
51
}
52