Campaigns::load()   B
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 259
Code Lines 234

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 234
nc 3
nop 1
dl 0
loc 259
rs 8
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 * Copyright (c) 2017 Francois-Xavier Soubirou.
4
 *
5
 * This file is part of ci-report.
6
 *
7
 * ci-report is free software: you can redistribute it and/or modify
8
 * it under the terms of the GNU General Public License as published by
9
 * the Free Software Foundation, either version 3 of the License, or
10
 * (at your option) any later version.
11
 *
12
 * ci-report is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
 * GNU General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU General Public License
18
 * along with ci-report. If not, see <http://www.gnu.org/licenses/>.
19
 */
20
declare(strict_types=1);
21
22
namespace App\DataFixtures\ORM;
23
24
use App\Entity\Campaign;
25
use DateTime;
26
use Doctrine\Bundle\FixturesBundle\ORMFixtureInterface;
27
use Doctrine\Common\DataFixtures\AbstractFixture;
28
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
29
use Doctrine\Common\Persistence\ObjectManager;
30
31
/**
32
 * Campaign fixtures load class.
33
 *
34
 * @category  ci-report app
35
 *
36
 * @author    Francois-Xavier Soubirou <[email protected]>
37
 * @copyright 2017 Francois-Xavier Soubirou
38
 * @license   http://www.gnu.org/licenses/   GPLv3
39
 *
40
 * @see      https://www.ci-report.io
41
 */
42
class Campaigns extends AbstractFixture implements OrderedFixtureInterface, ORMFixtureInterface
43
{
44
    /**
45
     * Load data fixtures with the passed EntityManager.
46
     *
47
     * @param ObjectManager $manager The entity manager
48
     */
49
    public function load(ObjectManager $manager)
50
    {
51
        $ref1Date = new DateTime();
52
        $ref1Date->setDate(2017, 7, 1)->setTime(12, 30, 1);
53
        $ref2Date = new DateTime();
54
        $ref2Date->setDate(2017, 7, 2)->setTime(12, 30, 1);
55
        $ref3Date = new DateTime();
56
        $ref3Date->setDate(2017, 7, 3)->setTime(12, 30, 1);
57
        $ref4Date = new DateTime();
58
        $ref4Date->setDate(2017, 7, 4)->setTime(12, 30, 1);
59
60
        $dataArray = array(
61
            array(
62
                'passed' => 25,
63
                'failed' => 0,
64
                'errored' => 0,
65
                'skipped' => 0,
66
                'disabled' => 0,
67
                'status' => 2,
68
                'start' => $ref1Date,
69
                'end' => $ref4Date,
70
                'project' => 'projectone-project',
71
                'campaignRef' => 'p1c1',
72
            ),
73
            array(
74
                'passed' => 25,
75
                'failed' => 0,
76
                'errored' => 1,
77
                'skipped' => 0,
78
                'disabled' => 0,
79
                'status' => 4,
80
                'start' => $ref2Date,
81
                'end' => null,
82
                'project' => 'projectone-project',
83
                'campaignRef' => 'p1c2',
84
            ),
85
            array(
86
                'passed' => 25,
87
                'failed' => 1,
88
                'errored' => 0,
89
                'skipped' => 0,
90
                'disabled' => 0,
91
                'status' => 4,
92
                'start' => $ref3Date,
93
                'end' => null,
94
                'project' => 'projectone-project',
95
                'campaignRef' => 'p1c3',
96
            ),
97
            array(
98
                'passed' => 26,
99
                'failed' => 0,
100
                'errored' => 0,
101
                'skipped' => 0,
102
                'disabled' => 0,
103
                'status' => 2,
104
                'start' => $ref4Date,
105
                'end' => null,
106
                'project' => 'projectone-project',
107
                'campaignRef' => 'p1c4',
108
            ),
109
            array(
110
                'passed' => 79,
111
                'failed' => 21,
112
                'errored' => 0,
113
                'skipped' => 0,
114
                'disabled' => 0,
115
                'status' => 8,
116
                'start' => $ref1Date,
117
                'end' => null,
118
                'project' => 'projecttwo-project',
119
                'campaignRef' => 'p2c1',
120
            ),
121
            array(
122
                'passed' => 80,
123
                'failed' => 20,
124
                'errored' => 0,
125
                'skipped' => 0,
126
                'disabled' => 0,
127
                'status' => 4,
128
                'start' => $ref2Date,
129
                'end' => null,
130
                'project' => 'projecttwo-project',
131
                'campaignRef' => 'p2c2',
132
            ),
133
            array(
134
                'passed' => 95,
135
                'failed' => 4,
136
                'errored' => 0,
137
                'skipped' => 1,
138
                'disabled' => 0,
139
                'status' => 2,
140
                'start' => $ref3Date,
141
                'end' => $ref4Date,
142
                'project' => 'projecttwo-project',
143
                'campaignRef' => 'p2c3',
144
            ),
145
            array(
146
                'passed' => 95,
147
                'failed' => 5,
148
                'errored' => 0,
149
                'skipped' => 0,
150
                'disabled' => 0,
151
                'status' => 2,
152
                'start' => $ref1Date,
153
                'end' => null,
154
                'project' => 'projectthree-project',
155
                'campaignRef' => 'p3c1',
156
            ),
157
            array(
158
                'passed' => 79,
159
                'failed' => 21,
160
                'errored' => 0,
161
                'skipped' => 0,
162
                'disabled' => 0,
163
                'status' => 8,
164
                'start' => $ref2Date,
165
                'end' => null,
166
                'project' => 'projectthree-project',
167
                'campaignRef' => 'p3c2',
168
            ),
169
            array(
170
                'passed' => 80,
171
                'failed' => 20,
172
                'errored' => 0,
173
                'skipped' => 0,
174
                'disabled' => 0,
175
                'status' => 4,
176
                'start' => $ref3Date,
177
                'end' => null,
178
                'project' => 'projectthree-project',
179
                'campaignRef' => 'p3c3',
180
            ),
181
            array(
182
                'passed' => 95,
183
                'failed' => 0,
184
                'errored' => 5,
185
                'skipped' => 0,
186
                'disabled' => 0,
187
                'status' => 2,
188
                'start' => $ref1Date,
189
                'end' => null,
190
                'project' => 'projectfour-project',
191
                'campaignRef' => 'p4c1',
192
            ),
193
            array(
194
                'passed' => 80,
195
                'failed' => 0,
196
                'errored' => 20,
197
                'skipped' => 0,
198
                'disabled' => 0,
199
                'status' => 4,
200
                'start' => $ref2Date,
201
                'end' => null,
202
                'project' => 'projectfour-project',
203
                'campaignRef' => 'p4c2',
204
            ),
205
            array(
206
                'passed' => 79,
207
                'failed' => 0,
208
                'errored' => 21,
209
                'skipped' => 0,
210
                'disabled' => 0,
211
                'status' => 8,
212
                'start' => $ref3Date,
213
                'end' => null,
214
                'project' => 'projectfour-project',
215
                'campaignRef' => 'p4c3',
216
            ),
217
            array(
218
                'passed' => 79,
219
                'failed' => 0,
220
                'errored' => 0,
221
                'skipped' => 21,
222
                'disabled' => 0,
223
                'status' => 8,
224
                'start' => $ref1Date,
225
                'end' => null,
226
                'project' => 'projectfive-project',
227
                'campaignRef' => 'p5c1',
228
            ),
229
            array(
230
                'passed' => 80,
231
                'failed' => 0,
232
                'errored' => 0,
233
                'skipped' => 20,
234
                'disabled' => 0,
235
                'status' => 4,
236
                'start' => $ref2Date,
237
                'end' => null,
238
                'project' => 'projectfive-project',
239
                'campaignRef' => 'p5c2',
240
            ),
241
            array(
242
                'passed' => 95,
243
                'failed' => 0,
244
                'errored' => 0,
245
                'skipped' => 5,
246
                'disabled' => 0,
247
                'status' => 2,
248
                'start' => $ref3Date,
249
                'end' => null,
250
                'project' => 'projectfive-project',
251
                'campaignRef' => 'p5c3',
252
            ),
253
            array(
254
                'passed' => 50,
255
                'failed' => 0,
256
                'errored' => 0,
257
                'skipped' => 0,
258
                'disabled' => 50,
259
                'status' => 2,
260
                'start' => $ref4Date,
261
                'end' => null,
262
                'project' => 'projectfive-project',
263
                'campaignRef' => 'p5c4',
264
            ),
265
            array(
266
                'passed' => 0,
267
                'failed' => 0,
268
                'errored' => 0,
269
                'skipped' => 0,
270
                'disabled' => 0,
271
                'status' => 1,
272
                'start' => $ref4Date,
273
                'end' => null,
274
                'project' => 'projectseven-project',
275
                'campaignRef' => 'p7c1',
276
            ),
277
            array(
278
                'passed' => 0,
279
                'failed' => 0,
280
                'errored' => 0,
281
                'skipped' => 0,
282
                'disabled' => 0,
283
                'status' => 1,
284
                'start' => $ref4Date,
285
                'end' => null,
286
                'project' => 'projecteight-project',
287
                'campaignRef' => 'p8c1',
288
            ),
289
        );
290
        $objectList = array();
291
        foreach ($dataArray as $i => $data) {
292
            $objectList[$i] = new Campaign($this->getReference($data['project']));
293
            $objectList[$i]->setPassed($data['passed']);
294
            $objectList[$i]->setFailed($data['failed']);
295
            $objectList[$i]->setErrored($data['errored']);
296
            $objectList[$i]->setSkipped($data['skipped']);
297
            $objectList[$i]->setDisabled($data['disabled']);
298
            $objectList[$i]->setStatus($data['status']);
299
            $objectList[$i]->setStart($data['start']);
300
            if (null !== $data['end']) {
301
                $objectList[$i]->setEnd($data['end']);
302
            }
303
            $manager->persist($objectList[$i]);
304
            $ref = $data['campaignRef'].'-campaign';
305
            $this->addReference($ref, $objectList[$i]);
306
        }
307
        $manager->flush();
308
    }
309
310
    /**
311
     * Get the order of this fixture.
312
     *
313
     * @return int
314
     */
315
    public function getOrder(): int
316
    {
317
        return 20;
318
    }
319
}
320