Passed
Push — add-option-to-change-output ( 0c1513 )
by Shinji
03:29
created

TraceFormatterFactory::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 0
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
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\Output\TraceFormatter\CallTraceFormatter;
17
use PhpProfiler\Inspector\Settings\OutputSettings\OutputSettings;
18
19
class TraceFormatterFactory
20
{
21
    /** @var array<string, TemplatedCallTraceFormatter> */
22
    private array $cache = [];
23
24
    public function __construct(
25
        private TemplatePathResolverInterface $template_path_resolver
26
    ) {
27
    }
28
29
    public function createFromSettings(OutputSettings $settings): CallTraceFormatter
30
    {
31
        if (!isset($this->cache[$settings->template_name])) {
32
            $this->cache[$settings->template_name] = new TemplatedCallTraceFormatter(
33
                $this->template_path_resolver,
34
                $settings->template_name
35
            );
36
        }
37
        return $this->cache[$settings->template_name];
38
    }
39
}
40