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

Memoize   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 17
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A resolve() 0 5 1
A __construct() 0 3 1
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