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

SubTheme   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 30
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A render() 0 3 1
1
<?php
2
3
4
namespace TheCodingMachine\CMS\Theme;
5
6
7
use Psr\Http\Message\StreamInterface;
8
use TheCodingMachine\CMS\RenderableInterface;
9
10
/**
11
 * This class is an adaptator around a theme that adds additional information in the context.
12
 */
13
class SubTheme implements RenderableInterface
14
{
15
    /**
16
     * @var RenderableInterface
17
     */
18
    private $theme;
19
    /**
20
     * @var mixed[]
21
     */
22
    private $additionalContext;
23
24
    /**
25
     * @param RenderableInterface $theme
26
     * @param mixed[] $additionalContext
27
     */
28
    public function __construct(RenderableInterface $theme, array $additionalContext)
29
    {
30
        $this->theme = $theme;
31
        $this->additionalContext = $additionalContext;
32
    }
33
34
    /**
35
     * Renders (as a stream) the data passed in parameter.
36
     *
37
     * @param mixed[] $context
38
     * @return StreamInterface
39
     */
40
    public function render(array $context): StreamInterface
41
    {
42
        return $this->theme->render(array_merge($this->additionalContext, $context));
43
    }
44
}
45