UpdateCommand::resolve()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 18
ccs 0
cts 15
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 11
nc 1
nop 0
crap 2
1
<?php
2
3
namespace Synapse\Cmf\Framework\Theme\Template\Domain\Command;
4
5
use Synapse\Cmf\Framework\Theme\Template\Event\Event as TemplateEvent;
6
use Synapse\Cmf\Framework\Theme\Template\Event\Events as TemplateEvents;
7
use Synapse\Cmf\Framework\Theme\Template\Model\TemplateInterface;
8
9
/**
10
 * Template edition command representation.
11
 */
12
class UpdateCommand extends AbstractCommand
13
{
14
    /**
15
     * Initialisation function.
16
     *
17
     * @param TemplateInterface $template
18
     */
19
    public function init(TemplateInterface $template)
20
    {
21
        $this->template = $template;
22
        $this->zones = $template->getZones()
23
            ->sortByZoneType()->indexByZoneType()
24
        ;
25
26
        return $this;
27
    }
28
29
    /**
30
     * @see ActionInterface::resolve()
31
     */
32
    public function resolve()
33
    {
34
        $this->template->setZones($this->zones);
35
36
        $this->template->denormalize($this->normalize('update'));
37
38
        $this->assertEntityIsValid($this->template, array('Template', 'edition'));
39
40
        $this->eventDispatcher->addListener(
41
            TemplateEvents::TEMPLATE_EDITED,
42
            $handler = array($this, 'onTemplateCreated')
43
        );
44
        $this->fireEvent(
45
            TemplateEvents::TEMPLATE_EDITED,
46
            new TemplateEvent($this->template, $this)
0 ignored issues
show
Compatibility introduced by
$this->template of type object<Synapse\Cmf\Frame...odel\TemplateInterface> is not a sub-type of object<Synapse\Cmf\Frame...mplate\Entity\Template>. It seems like you assume a concrete implementation of the interface Synapse\Cmf\Framework\Th...Model\TemplateInterface to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
47
        );
48
        $this->eventDispatcher->removeListener(TemplateEvents::TEMPLATE_EDITED, $handler);
49
    }
50
}
51