Completed
Push — master ( 252438...82275d )
by Markus
03:16
created

ContextMergeConverter   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 39
Duplicated Lines 41.03 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 56.25%

Importance

Changes 4
Bugs 1 Features 0
Metric Value
wmc 7
c 4
b 1
f 0
lcom 1
cbo 4
dl 16
loc 39
ccs 9
cts 16
cp 0.5625
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getSubscribedEvents() 7 7 1
A onImportPrepare() 9 9 3
A onImportFinish() 0 5 1
A convert() 0 8 2

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
namespace Mathielen\DataImport\ItemConverter;
3
4
use Ddeboer\DataImport\ItemConverter\ItemConverterInterface;
5
use Mathielen\DataImport\Event\ImportProcessEvent;
6
use Mathielen\ImportEngine\Import\Import;
7
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
8
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
9
10
class ContextMergeConverter implements ItemConverterInterface, EventSubscriberInterface
11
{
12
13
    private $currentContext;
14
15 View Code Duplication
    public static function getSubscribedEvents()
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...
16
    {
17
        return array(
18
            ImportProcessEvent::AFTER_PREPARE => array('onImportPrepare', 0),
19
            ImportProcessEvent::AFTER_FINISH => array('onImportFinish', 0),
20
        );
21
    }
22
23 4 View Code Duplication
    public function onImportPrepare(ImportProcessEvent $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...
24
    {
25
        //merge converter only works if context is an array
26 4
        if (!($event->getContext() instanceof Import) || !is_array($event->getContext()->getRun()->getContext())) {
27 3
            return;
28
        }
29
30 1
        $this->currentContext = $event->getContext()->getRun()->getContext();
31 1
    }
32
33
    public function onImportFinish(ImportProcessEvent $event, $eventName, EventDispatcherInterface $eventDispatcher)
0 ignored issues
show
Unused Code introduced by
The parameter $event is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $eventName is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
34
    {
35
        //remove the subscriber when its done
36
        $eventDispatcher->removeSubscriber($this);
37
    }
38
39 4
    public function convert($input)
40
    {
41 4
        if (!$this->currentContext) {
42 3
            return $input;
43
        }
44
45 1
        return array_merge($this->currentContext, $input);
46
    }
47
48
}
49