Completed
Push — master ( 2da503...38628d )
by Shinji
14s queued 11s
created

TemplatedTraceFormatterFactory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A createFromSettings() 0 9 2
1
<?php
2
3
/**
4
 * This file is part of the sj-i/php-profiler package.
5
 *
6
 * (c) sji <[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
declare(strict_types=1);
13
14
namespace PhpProfiler\Inspector\Output\TraceFormatter\Templated;
15
16
use PhpProfiler\Inspector\Settings\TemplatedTraceFormatterSettings\TemplateSettings;
17
18
final class TemplatedTraceFormatterFactory
19
{
20
    private TemplatePathResolverInterface $template_path_resolver;
21
    /** @var array<string, TemplatedCallTraceFormatter> */
22
    private array $cache = [];
23
24
    public function __construct(
25
        TemplatePathResolverInterface $template_path_resolver
26
    ) {
27
        $this->template_path_resolver = $template_path_resolver;
28
    }
29
30
    public function createFromSettings(TemplateSettings $settings): TemplatedCallTraceFormatter
31
    {
32
        if (!isset($this->cache[$settings->template_name])) {
33
            $this->cache[$settings->template_name] = new TemplatedCallTraceFormatter(
34
                $this->template_path_resolver,
35
                $settings->template_name
36
            );
37
        }
38
        return $this->cache[$settings->template_name];
39
    }
40
}
41