SubThemeFactory::createTheme()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 1
nop 1
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
namespace TheCodingMachine\CMS\Theme;
3
4
5
use TheCodingMachine\CMS\RenderableInterface;
6
7
class SubThemeFactory implements ThemeFactoryInterface
8
{
9
    /**
10
     * @var ThemeFactoryInterface
11
     */
12
    private $themeFactory;
13
14
    public function __construct(ThemeFactoryInterface $themeFactory)
15
    {
16
        $this->themeFactory = $themeFactory;
17
    }
18
19
    /**
20
     * Creates a theme object based on the descriptor object passed in parameter.
21
     *
22
     * @throws \TheCodingMachine\CMS\Theme\CannotHandleThemeDescriptorExceptionInterface Throws an exception if the factory cannot handle this descriptor.
23
     */
24
    public function createTheme(ThemeDescriptorInterface $descriptor): RenderableInterface
25
    {
26
        if (!$descriptor instanceof SubThemeDescriptor) {
27
            throw CannotHandleThemeDescriptorException::cannotHandleDescriptorClass(get_class($descriptor));
28
        }
29
        return new SubTheme($this->themeFactory->createTheme($descriptor->getThemeDescriptor()), $descriptor->getAdditionalContext());
30
    }
31
32
    /**
33
     * Returns true if this factory can handle the descriptor passed in parameter. False otherwise.
34
     */
35
    public function canCreateTheme(ThemeDescriptorInterface $descriptor): bool
36
    {
37
        return $descriptor instanceof SubThemeDescriptor;
38
    }
39
}
40