Completed
Push — master ( a18731...e2e070 )
by
unknown
99:54 queued 47:45
created

LoadB2bCustomerEmailData   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 59
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getDependencies() 6 6 1
B load() 24 24 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
3
namespace OroCRM\Bundle\SalesBundle\Tests\Functional\DataFixtures;
4
5
use Doctrine\Common\DataFixtures\AbstractFixture;
6
use Doctrine\Common\DataFixtures\DependentFixtureInterface;
7
use Doctrine\Common\Persistence\ObjectManager;
8
9
use OroCRM\Bundle\SalesBundle\Tests\Functional\DataFixtures\LoadB2bCustomerEntitiesData;
10
use OroCRM\Bundle\SalesBundle\Entity\B2bCustomerEmail;
11
12 View Code Duplication
class LoadB2bCustomerEmailData extends AbstractFixture implements DependentFixtureInterface
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...
13
{
14
    const FIRST_ENTITY_NAME  = '[email protected]';
15
    const SECOND_ENTITY_NAME = '[email protected]';
16
    const THIRD_ENTITY_NAME  = '[email protected]';
17
18
    public function getDependencies()
19
    {
20
        return [
21
            'OroCRM\Bundle\SalesBundle\Tests\Functional\DataFixtures\LoadB2bCustomerEntitiesData'
22
        ];
23
    }
24
25
    /**
26
     * @var array
27
     */
28
    protected $b2bCustomerEmailData = [
29
        [
30
            'email' => self::FIRST_ENTITY_NAME,
31
            'primary'  => true,
32
        ],
33
        [
34
            'email' => self::SECOND_ENTITY_NAME,
35
            'primary'  => false,
36
        ],
37
        [
38
            'email' => self::THIRD_ENTITY_NAME,
39
            'primary'  => false,
40
        ]
41
    ];
42
43
    /**
44
     * {@inheritdoc}
45
     */
46
    public function load(ObjectManager $manager)
47
    {
48
        $customer = $this->getReference('B2bCustomer_' . LoadB2bCustomerEntitiesData::FIRST_ENTITY_NAME);
49
50
        foreach ($this->b2bCustomerEmailData as $b2bCustomerEmailData) {
51
            $customerEmail = new B2bCustomerEmail();
52
            $customerEmail->setPrimary($b2bCustomerEmailData['primary']);
53
            $customerEmail->setOwner($customer);
54
            $customerEmail->setEmail($b2bCustomerEmailData['email']);
55
            $this->setReference('B2bCustomerEmail_Several_' . $b2bCustomerEmailData['email'], $customerEmail);
56
            $manager->persist($customerEmail);
57
        }
58
59
        $customer2 = $this->getReference('B2bCustomer_' . LoadB2bCustomerEntitiesData::SECOND_ENTITY_NAME);
60
        $customerEmail = new B2bCustomerEmail();
61
        $customerEmail->setPrimary($this->b2bCustomerEmailData[0]['primary']);
62
        $customerEmail->setOwner($customer2);
63
        $customerEmail->setEmail($this->b2bCustomerEmailData[0]['email']);
64
        $this->setReference('B2bCustomerEmail_Single_' . $this->b2bCustomerEmailData[0]['email'], $customerEmail);
65
        $manager->persist($customerEmail);
66
67
68
        $manager->flush();
69
    }
70
}
71