CreateCommand   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 4
dl 0
loc 71
ccs 21
cts 21
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
createTemplate() 0 1 ?
A resolve() 0 19 1
A setTemplateType() 0 6 1
1
<?php
2
3
namespace Synapse\Cmf\Framework\Theme\Template\Domain\Command;
4
5
use Synapse\Cmf\Framework\Theme\TemplateType\Model\TemplateTypeInterface;
6
use Synapse\Cmf\Framework\Theme\Template\Entity\Template;
7
use Synapse\Cmf\Framework\Theme\Template\Event\Event as TemplateEvent;
8
use Synapse\Cmf\Framework\Theme\Template\Event\Events as TemplateEvents;
9
use Synapse\Cmf\Framework\Theme\Zone\Entity\ZoneCollection;
10
11
/**
12
 * Template creation command representation.
13
 */
14
abstract class CreateCommand extends AbstractCommand
15
{
16
    /**
17
     * @var string
18
     */
19
    private $templateClass;
20
21
    /**
22
     * @var TemplateTypeInterface
23
     */
24
    protected $templateType;
25
26
    /**
27
     * Construct.
28
     *
29
     * @param string $templateClass
30
     */
31 2
    public function __construct($templateClass = Template::class)
32
    {
33 2
        $this->templateClass = $templateClass;
34 2
        $this->zones = new ZoneCollection();
35 2
    }
36
37
    /**
38
     * Template object creation method.
39
     *
40
     * @param string $templateClass
41
     *
42
     * @return TemplateInterface
43
     */
44
    abstract protected function createTemplate($templateClass);
45
46
    /**
47
     * Template creation method.
48
     *
49
     * @return Template
50
     */
51 2
    public function resolve()
52
    {
53 2
        $this->template = $this->createTemplate($this->templateClass);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->createTemplate($this->templateClass) of type object<Synapse\Cmf\Frame...mand\TemplateInterface> is incompatible with the declared type object<Synapse\Cmf\Frame...odel\TemplateInterface> of property $template.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
54 2
        $this->template->setZones($this->zones);
55
56 2
        $this->assertEntityIsValid($this->template, array('Template', 'creation'));
57
58 2
        $this->eventDispatcher->addListener(
59 2
            TemplateEvents::TEMPLATE_CREATED,
60 2
            $handler = array($this, 'onTemplateCreated')
61 1
        );
62 2
        $this->fireEvent(
63 2
            TemplateEvents::TEMPLATE_CREATED,
64 2
            new TemplateEvent($this->template, $this)
65 1
        );
66 2
        $this->eventDispatcher->removeListener(TemplateEvents::TEMPLATE_CREATED, $handler);
67
68 2
        return $this->template;
69
    }
70
71
    /**
72
     * Define action template type.
73
     *
74
     * @param TemplateTypeInterface $templateType
75
     *
76
     * @return self
77
     */
78 2
    public function setTemplateType(TemplateTypeInterface $templateType)
79
    {
80 2
        $this->templateType = $templateType;
81
82 2
        return $this;
83
    }
84
}
85