Completed
Push — 1.9 ( d8eb28...5c3e2e )
by
unknown
61:52 queued 29s
created

GuestCustomerDataConverter   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 72
Duplicated Lines 6.94 %

Coupling/Cohesion

Components 2
Dependencies 3

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 8
lcom 2
cbo 3
dl 5
loc 72
rs 10
c 2
b 1
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getHeaderConversionRules() 0 4 1
A getBackendHeader() 0 4 1
A extractCustomersValues() 0 10 2
B convertToImportFormat() 5 22 4

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
namespace OroCRM\Bundle\MagentoBundle\ImportExport\Converter;
4
5
use Oro\Bundle\IntegrationBundle\ImportExport\DataConverter\AbstractTreeDataConverter;
6
7
class GuestCustomerDataConverter extends AbstractTreeDataConverter
8
{
9
    /**
10
     * @var array
11
     */
12
    public static $conversionRules = [
13
        'customerEmail' => 'email',
14
        'customer_firstname' => 'firstName',
15
        'customer_lastname' => 'lastName',
16
        'createdAt' => 'createdAt',
17
        'updatedAt' => 'updatedAt',
18
        'store_id' => 'store:originId',
19
        'storeName' => 'createdIn',
20
    ];
21
22
    /**
23
     * @param array $orderData
24
     * @return array
25
     */
26
    public static function extractCustomersValues(array $orderData)
27
    {
28
        $customerData = array_intersect_key($orderData, self::$conversionRules);
29
30
        if (!empty($orderData['store']['originId'])) {
31
            $customerData['store_id'] = $orderData['store']['originId'];
32
        }
33
34
        return $customerData;
35
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40
    protected function getHeaderConversionRules()
41
    {
42
        return self::$conversionRules;
43
    }
44
45
    /**
46
     * {@inheritdoc}
47
     */
48
    public function convertToImportFormat(array $importedRecord, $skipNullValues = true)
49
    {
50 View Code Duplication
        if ($this->context && $this->context->hasOption('channel')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
51
            $importedRecord['store:channel:id'] = $this->context->getOption('channel');
52
            $importedRecord['website:channel:id'] = $this->context->getOption('channel');
53
            $importedRecord['group:channel:id'] = $this->context->getOption('channel');
54
        }
55
56
        // extract view from 'website\nstore\view' string
57
        if (!empty($importedRecord['storeName'])) {
58
            $createdIn = explode("\n", $importedRecord['storeName']);
59
            $importedRecord['storeName'] = end($createdIn);
60
        }
61
62
        $importedRecord = parent::convertToImportFormat($importedRecord, $skipNullValues);
63
        $importedRecord = AttributesConverterHelper::addUnknownAttributes($importedRecord, $this->context);
64
65
        $importedRecord['confirmed'] = false;
66
        $importedRecord['guest'] = true;
67
68
        return $importedRecord;
69
    }
70
71
    /**
72
     * {@inheritdoc}
73
     */
74
    protected function getBackendHeader()
75
    {
76
        return array_values($this->getHeaderConversionRules());
77
    }
78
}
79