Passed
Pull Request — master (#2)
by David
02:02
created

BlockRenderer::renderBlock()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 2
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
1
<?php
2
namespace TheCodingMachine\CMS\Block;
3
4
5
use Psr\Http\Message\StreamInterface;
6
use TheCodingMachine\CMS\Theme\ThemeFactoryInterface;
7
8
class BlockRenderer implements BlockRendererInterface
9
{
10
    /**
11
     * @var ThemeFactoryInterface
12
     */
13
    private $themeFactory;
14
15
    public function __construct(ThemeFactoryInterface $themeFactory)
16
    {
17
        $this->themeFactory = $themeFactory;
18
    }
19
20
21
    /**
22
     * Renders a block.
23
     *
24
     * @param BlockInterface $page
25
     * @param mixed[] $additionalContext
26
     * @return StreamInterface
27
     */
28
    public function renderBlock(BlockInterface $page, array $additionalContext = []): StreamInterface
29
    {
30
        $theme = $this->themeFactory->createTheme($page->getThemeDescriptor());
31
32
        $context = array_merge($page->getContext(), $additionalContext);
33
34
        return $theme->render($context);
35
    }
36
}
37