Completed
Push — master ( 047880...b09c02 )
by Kamil
92:08 queued 74:48
created

DelegatingTemplateEventRenderer   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 26
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A render() 0 11 2
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
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 Sylius\Bundle\UiBundle\Renderer;
15
16
use Sylius\Bundle\UiBundle\Registry\TemplateBlockRegistryInterface;
17
18
final class DelegatingTemplateEventRenderer implements TemplateEventRendererInterface
19
{
20
    /** @var TemplateBlockRegistryInterface */
21
    private $templateBlockRegistry;
22
23
    /** @var TemplateBlockRendererInterface */
24
    private $templateBlockRenderer;
25
26
    public function __construct(TemplateBlockRegistryInterface $templateBlockRegistry, TemplateBlockRendererInterface $templateBlockRenderer)
27
    {
28
        $this->templateBlockRegistry = $templateBlockRegistry;
29
        $this->templateBlockRenderer = $templateBlockRenderer;
30
    }
31
32
    public function render(string $eventName, array $context = []): string
33
    {
34
        $templateBlocks = $this->templateBlockRegistry->findEnabledForEvent($eventName);
35
        $renderedTemplates = [];
36
37
        foreach ($templateBlocks as $templateBlock) {
38
            $renderedTemplates[] = $this->templateBlockRenderer->render($eventName, $templateBlock, $context);
39
        }
40
41
        return implode("\n", $renderedTemplates);
42
    }
43
}
44