RunFixtureEventSubscriber::purge()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 9

Duplication

Lines 12
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 12
loc 12
rs 9.4285
cc 1
eloc 9
nc 1
nop 1
1
<?php
2
/**
3
 * @link    https://github.com/nnx-framework/doctrine-fixture-module
4
 * @author  Malofeykin Andrey  <[email protected]>
5
 */
6
namespace Nnx\DoctrineFixtureModule\Listener;
7
8
use Doctrine\Fixture\Event\FixtureEvent;
9
use Doctrine\Fixture\Event\ImportFixtureEventListener;
10
use Doctrine\Fixture\Event\PurgeFixtureEventListener;
11
use Nnx\DoctrineFixtureModule\Event\FixtureEvent as ExecuteFixtureEvent;
12
use Nnx\DoctrineFixtureModule\Executor\ExecutorAwareTrait;
13
use Zend\EventManager\EventManagerAwareTrait;
14
15
16
/**
17
 * Class RunFixtureEventSubscriber
18
 *
19
 * @package Nnx\DoctrineFixtureModule\Listener
20
 */
21
class RunFixtureEventSubscriber
22
    implements
0 ignored issues
show
Coding Style introduced by
The implements keyword must be on the same line as the class name
Loading history...
23
        RunFixtureEventSubscriberInterface,
0 ignored issues
show
Coding Style introduced by
Expected 4 spaces before interface name; 8 found
Loading history...
24
        ExecuteEventSubscriberInterface,
0 ignored issues
show
Coding Style introduced by
Expected 4 spaces before interface name; 8 found
Loading history...
25
        ImportFixtureEventListener,
0 ignored issues
show
Coding Style introduced by
Expected 4 spaces before interface name; 8 found
Loading history...
26
        PurgeFixtureEventListener
0 ignored issues
show
Coding Style introduced by
Expected 4 spaces before interface name; 8 found
Loading history...
27
{
28
29
    use EventManagerAwareTrait, ExecutorAwareTrait;
30
31
    /**
32
     * Идендфикатор для менеджера событий
33
     *
34
     * @var array
35
     */
36
    protected $eventIdentifier = [
37
        RunFixtureEventSubscriberInterface::class
38
    ];
39
    /**
40
     * Прототип для объекта события
41
     *
42
     * @var ExecuteFixtureEvent
43
     */
44
    protected $prototypeEvent;
45
46
    /**
47
     * {@inheritdoc}
48
     */
49
    public function getSubscribedEvents()
50
    {
51
        return [
52
            ImportFixtureEventListener::IMPORT,
53
            PurgeFixtureEventListener::PURGE,
54
        ];
55
    }
56
57
    /**
58
     * {@inheritdoc}
59
     * @throws \Nnx\DoctrineFixtureModule\Executor\Exception\RuntimeException
60
     */
61 View Code Duplication
    public function import(FixtureEvent $event)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
62
    {
63
        $workflowExecutorEvent = clone $this->getPrototypeEvent();
64
        $workflowExecutorEvent->setName(ExecuteFixtureEvent::EXECUTE_FIXTURE_EVENT);
65
        $workflowExecutorEvent->setMethod(ExecuteFixtureEvent::IMPORT);
66
        $executor = $this->getExecutor();
67
        $workflowExecutorEvent->setExecutor($executor);
68
        $workflowExecutorEvent->setTarget($executor);
69
        $workflowExecutorEvent->setFixture($event->getFixture());
70
71
        $this->getEventManager()->trigger($workflowExecutorEvent);
72
    }
73
74
    /**
75
     * {@inheritdoc}
76
     * @throws \Nnx\DoctrineFixtureModule\Executor\Exception\RuntimeException
77
     */
78 View Code Duplication
    public function purge(FixtureEvent $event)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
79
    {
80
        $workflowExecutorEvent = clone $this->getPrototypeEvent();
81
        $workflowExecutorEvent->setName(ExecuteFixtureEvent::EXECUTE_FIXTURE_EVENT);
82
        $workflowExecutorEvent->setMethod(ExecuteFixtureEvent::PURGE);
83
        $executor = $this->getExecutor();
84
        $workflowExecutorEvent->setExecutor($executor);
85
        $workflowExecutorEvent->setTarget($executor);
86
        $workflowExecutorEvent->setFixture($event->getFixture());
87
88
        $this->getEventManager()->trigger($workflowExecutorEvent);
89
    }
90
91
92
93
    /**
94
     * Возвращает прототип для объекта события
95
     *
96
     * @return ExecuteFixtureEvent
97
     */
98
    public function getPrototypeEvent()
99
    {
100
        if (null === $this->prototypeEvent) {
101
            $prototypeEvent = new ExecuteFixtureEvent();
102
            $this->setPrototypeEvent($prototypeEvent);
103
        }
104
        return $this->prototypeEvent;
105
    }
106
107
    /**
108
     * Устанавливает прототип для объекта события
109
     *
110
     * @param ExecuteFixtureEvent $prototypeEvent
111
     *
112
     * @return $this
113
     */
114
    public function setPrototypeEvent(ExecuteFixtureEvent $prototypeEvent)
115
    {
116
        $this->prototypeEvent = $prototypeEvent;
117
118
        return $this;
119
    }
120
}
121