Completed
Push — 1.10 ( 3f8f95...f007bc )
by
unknown
09:16
created

LoadCampaignLeadsWidgetFixture::load()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 20
Code Lines 17

Duplication

Lines 20
Ratio 100 %

Importance

Changes 0
Metric Value
dl 20
loc 20
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 17
nc 2
nop 1
1
<?php
2
namespace OroCRM\Bundle\SalesBundle\Tests\Functional\Fixture;
3
4
use Doctrine\Common\DataFixtures\AbstractFixture;
5
use Doctrine\Common\Persistence\ObjectManager;
6
use OroCRM\Bundle\CampaignBundle\Entity\Campaign;
7
use OroCRM\Bundle\SalesBundle\Entity\Lead;
8
use Oro\Bundle\DashboardBundle\Entity\Dashboard;
9
use Oro\Bundle\DashboardBundle\Entity\Widget;
10
use Oro\Bundle\OrganizationBundle\Entity\Organization;
11
12
class LoadCampaignLeadsWidgetFixture extends AbstractFixture
13
{
14
    /**
15
     * @var Organization
16
     */
17
    protected $organization;
18
    /**
19
     * @var ObjectManager
20
     */
21
    protected $em;
22 View Code Duplication
    protected function createLeads()
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...
23
    {
24
        $createdAt = new \DateTime('2016-12-28 12:03:10', new \DateTimeZone('UTC'));
25
        for ($i = 1; $i < 4; $i++) {
26
            $this->createLead($createdAt, $i);
27
            $createdAt->add(new \DateInterval('P1D'));
28
        }
29
30
        //insert one lead for previous months
31
        $createdAt = new \DateTime('now', new \DateTimeZone('UTC'));
32
        $this->createLead($createdAt, ++$i);
33
        $createdAt->sub(new \DateInterval('P2M'));
34
        $this->createLead($createdAt, ++$i);
35
    }
36
37
    public function createLead($createdAt, $id)
38
    {
39
        $lead = new Lead();
40
        $lead->setName('name '.$id);
41
        $lead->setOrganization($this->organization);
42
        $lead->setCampaign($this->getReference('default_campaign'));
0 ignored issues
show
Bug introduced by
The method setCampaign() does not seem to exist on object<OroCRM\Bundle\SalesBundle\Entity\Lead>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
43
        $this->em->persist($lead);
44
        $lead->setCreatedAt($createdAt);
45
        $this->em->flush();
46
    }
47
48
    public function createCampaign()
49
    {
50
        $campaign = new Campaign();
51
        $campaign->setName('Campaign');
52
        $campaign->setCode('cmp');
53
        $campaign->setOrganization($this->organization);
54
        $campaign->setReportPeriod(Campaign::PERIOD_MONTHLY);
55
        $this->em->persist($campaign);
56
        $this->em->flush();
57
        $this->setReference('default_campaign', $campaign);
58
    }
59
60
    /**
61
     * @inheritDoc
62
     */
63 View Code Duplication
    public function load(ObjectManager $manager)
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...
64
    {
65
        $this->organization = $manager->getRepository('OroOrganizationBundle:Organization')->getFirst();
66
        $this->em = $manager;
67
        $this->createCampaign();
68
        $this->createLeads();
69
        $dashboard = new Dashboard();
70
        $dashboard->setName('dashboard');
71
        $campaignLeadsWidget = new Widget();
72
        $campaignLeadsWidget
73
            ->setDashboard($dashboard)
74
            ->setName('campaigns_leads')
75
            ->setLayoutPosition([1, 1]);
76
        $dashboard->addWidget($campaignLeadsWidget);
77
        if (!$this->hasReference('widget_campaigns_leads')) {
78
            $this->setReference('widget_campaigns_leads', $campaignLeadsWidget);
79
        }
80
        $manager->persist($dashboard);
81
        $manager->flush();
82
    }
83
}
84