Completed
Push — master ( 3560db...6e658b )
by
unknown
08:14
created

LoadContactPhoneData::getDependencies()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 6
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 6
loc 6
rs 9.4286
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
3
namespace OroCRM\Bundle\ContactBundle\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\ContactBundle\Entity\ContactPhone;
10
11 View Code Duplication
class LoadContactPhoneData 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...
12
{
13
    const FIRST_ENTITY_NAME  = '1111111';
14
    const SECOND_ENTITY_NAME = '2222222';
15
    const THIRD_ENTITY_NAME  = '3333333';
16
17
    public function getDependencies()
18
    {
19
        return [
20
            'OroCRM\Bundle\ContactBundle\Tests\Functional\DataFixtures\LoadContactEntitiesData'
21
        ];
22
    }
23
24
    /**
25
     * @var array
26
     */
27
    protected $contactEmailData = [
28
        [
29
            'phone' => self::FIRST_ENTITY_NAME,
30
            'primary'  => true,
31
        ],
32
        [
33
            'phone' => self::SECOND_ENTITY_NAME,
34
            'primary'  => false,
35
        ],
36
        [
37
            'phone' => self::THIRD_ENTITY_NAME,
38
            'primary'  => false,
39
        ]
40
    ];
41
42
    /**
43
     * {@inheritdoc}
44
     */
45
    public function load(ObjectManager $manager)
46
    {
47
        $contact = $this->getReference('Contact_' . LoadContactEntitiesData::FIRST_ENTITY_NAME);
48
        foreach ($this->contactEmailData as $contactEmailData) {
49
            $contactPhone = new ContactPhone();
50
            $contactPhone->setPrimary($contactEmailData['primary']);
51
            $contactPhone->setOwner($contact);
52
            $contactPhone->setPhone($contactEmailData['phone']);
53
54
            $this->setReference('ContactPhone_Several_' . $contactEmailData['phone'], $contactPhone);
55
            $manager->persist($contactPhone);
56
        }
57
58
        $contact2 = $this->getReference('Contact_' . LoadContactEntitiesData::SECOND_ENTITY_NAME);
59
        $contactPhone = new ContactPhone();
60
        $contactPhone->setPrimary($this->contactEmailData[0]['primary']);
61
        $contactPhone->setOwner($contact2);
62
        $contactPhone->setPhone($this->contactEmailData[0]['phone']);
63
        $this->setReference('ContactPhone_Single_' . $this->contactEmailData[0]['phone'], $contactPhone);
64
        $manager->persist($contactPhone);
65
66
        $manager->flush();
67
    }
68
}
69