Code Duplication    Length = 26-28 lines in 2 locations

src/Oro/Bundle/DemoDataBundle/Migrations/Data/Demo/ORM/LoadLeadsData.php 1 location

@@ 131-156 (lines=26) @@
128
            ->locateResource('@OroDemoDataBundle/Migrations/Data/Demo/ORM/dictionaries');
129
130
        $handle = fopen($dictionaryDir . DIRECTORY_SEPARATOR. "leads.csv", "r");
131
        if ($handle) {
132
            $headers = array();
133
            if (($data = fgetcsv($handle, 1000, ",")) !== false) {
134
                //read headers
135
                $headers = $data;
136
            }
137
            $randomUser = count($this->users) - 1;
138
            $i = 0;
139
            while (($data = fgetcsv($handle, 1000, ",")) !== false) {
140
                $user = $this->users[mt_rand(0, $randomUser)];
141
                $this->setSecurityContext($user);
142
143
                $data = array_combine($headers, array_values($data));
144
145
                $lead = $this->createLead($manager, $data, $user);
146
                $this->persist($this->em, $lead);
147
148
                $i++;
149
                if ($i % self::FLUSH_MAX == 0) {
150
                    $this->flush($this->em);
151
                }
152
            }
153
154
            $this->flush($this->em);
155
            fclose($handle);
156
        }
157
    }
158
159
    /**

src/Oro/Bundle/ReportCRMBundle/Tests/Functional/DataFixtures/LoadLeadsData.php 1 location

@@ 114-141 (lines=28) @@
111
    public function loadLeads(ObjectManager $manager)
112
    {
113
        $handle = fopen(__DIR__ . DIRECTORY_SEPARATOR . 'dictionaries' . DIRECTORY_SEPARATOR . "leads.csv", "r");
114
        if ($handle) {
115
            $headers = [];
116
            if (($data = fgetcsv($handle, 1000, ",")) !== false) {
117
                //read headers
118
                $headers = $data;
119
            }
120
            $randomUser = count($this->users) - 1;
121
            $i          = 0;
122
            while (($data = fgetcsv($handle, 1000, ",")) !== false) {
123
                $user = $this->users[mt_rand(0, $randomUser)];
124
                $this->setSecurityContext($user);
125
126
                $data = array_combine($headers, array_values($data));
127
128
                $lead = $this->createLead($manager, $data, $user);
129
                $this->em->persist($lead);
130
131
                $this->loadSalesFlows($lead);
132
133
                $i++;
134
                if ($i % self::FLUSH_MAX == 0) {
135
                    $this->em->flush();
136
                }
137
            }
138
139
            $this->em->flush();
140
            fclose($handle);
141
        }
142
    }
143
144
    /**