PostExecuteEventSubscriber   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 62
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 1
cbo 3
dl 62
loc 62
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getSubscribedEvents() 7 7 1
A bulkImport() 11 11 1
A bulkPurge() 11 11 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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\BulkFixtureEvent;
9
use Doctrine\Fixture\Event\BulkImportFixtureEventListener;
10
use Doctrine\Fixture\Event\BulkPurgeFixtureEventListener;
11
use Nnx\DoctrineFixtureModule\Event\FixtureExecutorEvent;
12
13
14
15
/**
16
 * Class PostExecuteEventSubscriber
17
 *
18
 * @package Nnx\DoctrineFixtureModule\Listener
19
 */
20 View Code Duplication
class PostExecuteEventSubscriber
0 ignored issues
show
Duplication introduced by
This class 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...
21
    extends
0 ignored issues
show
Coding Style introduced by
The extends keyword must be on the same line as the class name
Loading history...
22
        AbstractExecuteEventSubscriber
0 ignored issues
show
Coding Style introduced by
Expected 1 space before "AbstractExecuteEventSubscriber"; 8 found
Loading history...
Coding Style introduced by
Expected 0 spaces between "AbstractExecuteEventSubscriber" and comma; 1 found
Loading history...
23
    implements
0 ignored issues
show
Coding Style introduced by
The implements keyword must be on the same line as the class name
Loading history...
24
        PostExecuteEventSubscriberInterface,
0 ignored issues
show
Coding Style introduced by
Expected 4 spaces before interface name; 8 found
Loading history...
25
        BulkImportFixtureEventListener,
0 ignored issues
show
Coding Style introduced by
Expected 4 spaces before interface name; 8 found
Loading history...
26
        BulkPurgeFixtureEventListener
0 ignored issues
show
Coding Style introduced by
Expected 4 spaces before interface name; 8 found
Loading history...
27
{
28
29
    /**
30
     * Идендфикатор для менеджера событий
31
     *
32
     * @var array
33
     */
34
    protected $eventIdentifier = [
35
        PostExecuteEventSubscriberInterface::class
36
    ];
37
38
    /**
39
     * {@inheritdoc}
40
     */
41
    public function getSubscribedEvents()
42
    {
43
        return [
44
            BulkImportFixtureEventListener::BULK_IMPORT,
45
            BulkPurgeFixtureEventListener::BULK_PURGE,
46
        ];
47
    }
48
49
    /**
50
     * {@inheritdoc}
51
     * @throws \Nnx\DoctrineFixtureModule\Executor\Exception\RuntimeException
52
     */
53
    public function bulkImport(BulkFixtureEvent $event)
54
    {
55
        $workflowExecutorEvent = clone $this->getPrototypeEvent();
56
        $workflowExecutorEvent->setName(FixtureExecutorEvent::END_EXECUTE_FIXTURES_EVENT);
57
        $workflowExecutorEvent->setMethod(FixtureExecutorEvent::IMPORT);
58
        $executor = $this->getExecutor();
59
        $workflowExecutorEvent->setExecutor($executor);
60
        $workflowExecutorEvent->setTarget($executor);
61
62
        $this->getEventManager()->trigger($workflowExecutorEvent);
63
    }
64
65
66
    /**
67
     * {@inheritdoc}
68
     * @throws \Nnx\DoctrineFixtureModule\Executor\Exception\RuntimeException
69
     */
70
    public function bulkPurge(BulkFixtureEvent $event)
71
    {
72
        $workflowExecutorEvent = clone $this->getPrototypeEvent();
73
        $workflowExecutorEvent->setName(FixtureExecutorEvent::END_EXECUTE_FIXTURES_EVENT);
74
        $workflowExecutorEvent->setMethod(FixtureExecutorEvent::PURGE);
75
        $executor = $this->getExecutor();
76
        $workflowExecutorEvent->setExecutor($executor);
77
        $workflowExecutorEvent->setTarget($executor);
78
79
        $this->getEventManager()->trigger($workflowExecutorEvent);
80
    }
81
}
82