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

Memoize::resolve()   A

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 3
dl 0
loc 5
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\TemplateResolver;
13
14
use ICanBoogie\Render\TemplateResolver;
15
16
use function implode;
17
18
/**
19
 * Memoize the results of the inner {@link TemplateResolver}.
20
 */
21
final class Memoize implements TemplateResolver
22
{
23
    /**
24
     * @var array<string, string|null>
25
     */
26
    private array $cache = [];
27
28
    public function __construct(
29
        private readonly TemplateResolver $inner
30
    ) {
31
    }
32
33
    public function resolve(string $name, array $extensions, array &$tried = []): ?string
34
    {
35
        $key = $name . ' # ' . implode(' ', $extensions);
36
37
        return $this->cache[$key] ??= $this->inner->resolve($name, $extensions, $tried);
38
    }
39
}
40