SubThemeFactory   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 31
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A createTheme() 0 6 2
A canCreateTheme() 0 3 1
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