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

LoadMagentoData::persistDemoIntegration()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 25
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 25
rs 8.8571
c 1
b 0
f 0
cc 1
eloc 19
nc 1
nop 2
1
<?php
2
3
namespace OroCRM\Bundle\DemoDataBundle\Migrations\Data\Demo\ORM;
4
5
use Doctrine\Common\DataFixtures\AbstractFixture;
6
use Doctrine\Common\DataFixtures\DependentFixtureInterface;
7
use Doctrine\Common\Persistence\ObjectManager;
8
9
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
10
use Symfony\Component\DependencyInjection\ContainerInterface;
11
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
12
13
use Oro\Bundle\AddressBundle\Entity\Country;
14
use Oro\Bundle\AddressBundle\Entity\Region;
15
use Oro\Bundle\IntegrationBundle\Entity\Channel as Integration;
16
use Oro\Bundle\OrganizationBundle\Entity\Organization;
17
use Oro\Bundle\UserBundle\Entity\User;
18
19
use OroCRM\Bundle\AnalyticsBundle\Entity\RFMMetricCategory;
20
use OroCRM\Bundle\ChannelBundle\Builder\BuilderFactory;
21
use OroCRM\Bundle\ChannelBundle\Entity\Channel;
22
use OroCRM\Bundle\ContactBundle\Entity\Contact;
23
use OroCRM\Bundle\MagentoBundle\Entity\Cart;
24
use OroCRM\Bundle\MagentoBundle\Entity\CartItem;
25
use OroCRM\Bundle\MagentoBundle\Entity\CartStatus;
26
use OroCRM\Bundle\MagentoBundle\Entity\Customer;
27
use OroCRM\Bundle\MagentoBundle\Entity\CustomerGroup;
28
use OroCRM\Bundle\MagentoBundle\Entity\MagentoSoapTransport;
29
use OroCRM\Bundle\MagentoBundle\Entity\Order;
30
use OroCRM\Bundle\MagentoBundle\Entity\OrderAddress;
31
use OroCRM\Bundle\MagentoBundle\Entity\OrderItem;
32
use OroCRM\Bundle\MagentoBundle\Entity\Store;
33
use OroCRM\Bundle\MagentoBundle\Entity\Website;
34
use OroCRM\Bundle\MagentoBundle\Provider\Transport\SoapTransport;
35
36
class LoadMagentoData extends AbstractFixture implements ContainerAwareInterface, DependentFixtureInterface
37
{
38
    use ContainerAwareTrait;
39
40
    const TAX              = 0.0838;
41
42
    /** @var array */
43
    protected $users;
44
45
    /** @var array */
46
    protected static $websiteCodes = ['admin', 'admin2'];
47
48
    /** @var array */
49
    protected static $integrationNames = ['Demo Web store', 'Demo Web store 2'];
50
51
    /** @var array */
52
    protected static $groupNames = ['General', 'Secondary'];
53
54
    /** @var array */
55
    protected static $channelNames = ['Magento channel', 'Magento channel 2'];
56
57
    /**
58
     * {@inheritdoc}
59
     */
60
    public function getDependencies()
61
    {
62
        return [
63
            'OroCRM\Bundle\DemoDataBundle\Migrations\Data\Demo\ORM\LoadContactData'
64
        ];
65
    }
66
67
    /**
68
     * {@inheritDoc}
69
     */
70
    public function load(ObjectManager $om)
71
    {
72
        $organization = $this->getReference('default_organization');
73
        $this->users = $om->getRepository('OroUserBundle:User')->findAll();
74
75
        $stores = $this->persistDemoStores($om, $organization);
76
        foreach ($stores as $store) {
77
            $channel = $this->persistDemoChannel($om, $store->getChannel());
78
            $group = $this->persistDemoUserGroup($om, $store->getChannel());
79
            $customers = $this->persistDemoCustomers($om, $store, $group, $channel, $organization);
80
            $carts = $this->persistDemoCarts($om, $customers);
81
            $this->persistDemoOrders($om, $carts);
82
            $this->persistDemoRFM($om, $channel, $organization);
83
84
            $om->flush();
85
        }
86
    }
87
88
    /**
89
     * @param ObjectManager $om
90
     * @param Organization $organization
91
     *
92
     * @return Store[]
93
     */
94
    protected function persistDemoStores(ObjectManager $om, Organization $organization)
95
    {
96
        $countOfWebsites = count(static::$websiteCodes);
97
        $stores = [];
98
99
        for ($i = 0; $i < $countOfWebsites; $i++) {
100
            $code = static::$websiteCodes[$i];
101
            $integration = $this->persistDemoIntegration($om, $organization);
102
103
            $website = new Website();
104
            $website
105
                ->setCode($code)
106
                ->setName(ucfirst($code));
107
            $om->persist($website);
108
109
            $store = new Store();
110
            $store
111
                ->setCode($website->getCode())
112
                ->setName($website->getName())
113
                ->setChannel($integration)
114
                ->setWebsite($website);
115
            $om->persist($store);
116
            $stores[] = $store;
117
        }
118
119
        return $stores;
120
    }
121
122
    /**
123
     * @param ObjectManager $om
124
     * @param Organization $organization
125
     *
126
     * @return Integration
127
     */
128
    protected function persistDemoIntegration(ObjectManager $om, Organization $organization)
129
    {
130
        static $i = 0;
131
132
        $transport = new MagentoSoapTransport();
133
        $transport->setApiUser('api_user');
134
        $transport->setApiKey('api_key');
135
        $transport->setExtensionVersion(SoapTransport::REQUIRED_EXTENSION_VERSION);
136
        $transport->setIsExtensionInstalled(true);
137
        $transport->setMagentoVersion('1.9.1.0');
138
        $transport->setWsdlUrl('http://magento.domain');
139
        $om->persist($transport);
140
141
        $integrationName = static::$integrationNames[$i++];
142
143
        $integration = new Integration();
144
        $integration->setType('magento');
145
        $integration->setConnectors(['customer', 'cart', 'order', 'newsletter_subscriber']);
146
        $integration->setName($integrationName);
147
        $integration->setTransport($transport);
148
        $integration->setOrganization($organization);
149
        $om->persist($integration);
150
151
        return $integration;
152
    }
153
154
    /**
155
     * @param ObjectManager $om
156
     * @param Integration $integration
157
     *
158
     * @return Channel
159
     */
160
    protected function persistDemoChannel(ObjectManager $om, Integration $integration)
161
    {
162
        static $i = 0;
163
164
        $name = static::$channelNames[$i++];
165
166
        /** @var $factory BuilderFactory */
167
        $factory = $this->container->get('orocrm_channel.builder.factory');
168
        $builder = $factory->createBuilderForIntegration($integration);
169
        $builder->setOwner($integration->getOrganization());
170
        $builder->setDataSource($integration);
171
        $builder->setStatus($integration->isEnabled() ? Channel::STATUS_ACTIVE : Channel::STATUS_INACTIVE);
172
        $builder->setName($name);
173
        $dataChannel = $builder->getChannel();
174
        $om->persist($dataChannel);
175
176
        return $dataChannel;
177
    }
178
179
    /**
180
     * @param ObjectManager $om
181
     * @param Integration $integration
182
     *
183
     * @return CustomerGroup
184
     */
185
    protected function persistDemoUserGroup(ObjectManager $om, Integration $integration)
186
    {
187
        static $i = 0;
188
189
        $groupName = static::$groupNames[$i++];
190
191
        $group = new CustomerGroup();
192
        $group->setName($groupName);
193
        $group->setOriginId(14999 + $i);
194
        $group->setChannel($integration);
195
        $om->persist($group);
196
197
        return $group;
198
    }
199
200
    /**
201
     * @param ObjectManager $om
202
     * @param Channel $dataChannel
203
     * @param Organization $organization
204
     */
205
    protected function persistDemoRFM(ObjectManager $om, Channel $dataChannel, Organization $organization)
206
    {
207
        $rfmData = [
208
            'recency' => [
209
                ['min' => null, 'max' => 7],
210
                ['min' => 7, 'max' => 30],
211
                ['min' => 30, 'max' => 90],
212
                ['min' => 90, 'max' => 365],
213
                ['min' => 365, 'max' => null],
214
            ],
215
            'frequency' => [
216
                ['min' => 52, 'max' => null],
217
                ['min' => 12, 'max' => 52],
218
                ['min' => 4, 'max' => 12],
219
                ['min' => 2, 'max' => 4],
220
                ['min' => null, 'max' => 2],
221
            ],
222
            'monetary' => [
223
                ['min' => 10000, 'max' => null],
224
                ['min' => 1000, 'max' => 10000],
225
                ['min' => 100, 'max' => 1000],
226
                ['min' => 10, 'max' => 100],
227
                ['min' => null, 'max' => 10],
228
            ]
229
        ];
230
231
        foreach ($rfmData as $type => $values) {
232
            foreach ($values as $idx => $limits) {
233
                $category = new RFMMetricCategory();
234
                $category->setCategoryIndex($idx + 1)
235
                    ->setChannel($dataChannel)
236
                    ->setCategoryType($type)
237
                    ->setMinValue($limits['min'])
238
                    ->setMaxValue($limits['max'])
239
                    ->setOwner($organization);
240
241
                $om->persist($category);
242
            }
243
        }
244
245
        $data = $dataChannel->getData();
246
        $data['rfm_enabled'] = true;
247
        $dataChannel->setData($data);
248
        $om->persist($dataChannel);
249
    }
250
251
    /**
252
     * @param ObjectManager $om
253
     * @param Customer[] $customers
254
     *
255
     * @return Cart[]
256
     */
257
    protected function persistDemoCarts(ObjectManager $om, array $customers)
258
    {
259
        /** @var CartStatus $status */
260
        $status = $om->getRepository('OroCRMMagentoBundle:CartStatus')->findOneBy(['name' => 'open']);
261
262
        $carts = [];
263
        for ($i = 0; $i < 10; ++$i) {
264
            $customer = $customers[array_rand($customers)];
265
            $cart = $this->generateShoppingCart(
266
                $om,
267
                $customer->getStore(),
268
                $customer->getDataChannel(),
269
                $customer,
270
                $status,
271
                $i
272
            );
273
            $this->generateShoppingCartItem($om, $cart);
274
            $carts[] = $cart;
275
        }
276
277
        return $carts;
278
    }
279
280
    /**
281
     * @param ObjectManager $om
282
     * @param Cart[] $carts
283
     */
284
    protected function persistDemoOrders(ObjectManager $om, array $carts)
285
    {
286
        $paymentMethod = ['Ccsave', 'Checkmo'];
287
        $paymentMethodDetails = ['Card[MC]', 'Card[AE]', 'N/A'];
288
        $status = ['Pending', 'Processing', 'Completed', 'Canceled'];
289
        $i = 0;
290
        foreach ($carts as $cart) {
291
            /** @var Cart $cart */
292
            $order = $this->generateOrder(
293
                $om,
294
                $cart->getStore(),
295
                $cart->getDataChannel(),
296
                $cart->getCustomer(),
0 ignored issues
show
Bug introduced by
It seems like $cart->getCustomer() can be null; however, generateOrder() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
297
                $status[array_rand($status)],
298
                $cart,
299
                $paymentMethod[array_rand($paymentMethod)],
300
                $paymentMethodDetails[array_rand($paymentMethodDetails)],
301
                $i++
302
            );
303
            $this->generateOrderItem($om, $order, $cart);
304
        }
305
    }
306
307
    /**
308
     * @param ObjectManager $om
309
     * @param Store         $store
310
     * @param Integration   $integration
0 ignored issues
show
Bug introduced by
There is no parameter named $integration. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
311
     * @param Customer      $customer
312
     * @param string        $status
313
     * @param Cart          $cart
314
     * @param string        $paymentMethod
315
     * @param string        $paymentMethodDetails
316
     * @param mixed         $origin
317
     *
318
     * @return Order
319
     */
320
    protected function generateOrder(
321
        ObjectManager $om,
322
        Store $store,
323
        Channel $channel,
324
        Customer $customer,
325
        $status,
326
        Cart $cart,
327
        $paymentMethod,
328
        $paymentMethodDetails,
329
        $origin
330
    ) {
331
        $order = new Order();
332
        $order->setOrganization($customer->getOrganization());
333
        $order->setChannel($channel->getDataSource());
334
        $order->setCustomer($customer);
335
        $order->setOwner($customer->getOwner());
336
        $order->setStatus($status);
337
        $order->setStore($store);
338
        $order->setStoreName($store->getName());
339
        $order->setIsGuest(0);
0 ignored issues
show
Documentation introduced by
0 is of type integer, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
340
        $order->setIncrementId((string)$origin);
341
        $order->setCreatedAt(new \DateTime('now'));
342
        $order->setUpdatedAt(new \DateTime('now'));
343
        $order->setCart($cart);
344
        $order->setCurrency($cart->getBaseCurrencyCode());
345
        $order->setTotalAmount($cart->getGrandTotal());
346
        $order->setTotalInvoicedAmount($cart->getGrandTotal());
347
        $order->setDataChannel($channel);
348
        if ($status == 'Completed') {
349
            $order->setTotalPaidAmount($cart->getGrandTotal());
350
        }
351
        $order->setSubtotalAmount($cart->getSubTotal());
352
        $order->setShippingAmount(rand(5, 10));
353
        $order->setPaymentMethod($paymentMethod);
354
        $order->setPaymentDetails($paymentMethodDetails);
355
        $order->setShippingMethod('flatrate_flatrate');
356
        $address = $this->getOrderAddress($om);
357
        $order->addAddress($address);
358
        $address->setOwner($order);
359
        $om->persist($order);
360
        return $order;
361
    }
362
363
364
    /**
365
     * @param ObjectManager $om
366
     * @param Order         $order
367
     * @param Cart          $cart
368
     *
369
     * @return OrderItem[]
370
     */
371
    protected function generateOrderItem(ObjectManager $om, Order $order, Cart $cart)
372
    {
373
        $cartItems = $cart->getCartItems();
374
        $orderItems = [];
375
        foreach ($cartItems as $cartItem) {
376
            $orderItem = new OrderItem();
377
            $orderItem->setOriginId($cartItem->getOriginId());
378
            $orderItem->setOrder($order);
379
            $orderItem->setTaxAmount($cartItem->getTaxAmount());
380
            $orderItem->setTaxPercent($cartItem->getTaxPercent());
381
            $orderItem->setRowTotal($cartItem->getRowTotal());
382
            $orderItem->setProductType($cartItem->getProductType());
383
            $orderItem->setIsVirtual((bool)$cartItem->getIsVirtual());
384
            $orderItem->setQty($cartItem->getQty());
385
            $orderItem->setSku($cartItem->getSku());
386
            $orderItem->setPrice($cartItem->getPrice());
387
            $orderItem->setOriginalPrice($cartItem->getPrice());
388
            $orderItem->setName($cartItem->getName());
389
            $orderItem->setOwner($order->getOrganization());
390
            $orderItems[] = $orderItem;
391
392
            $om->persist($orderItem);
393
        }
394
395
        $order->setItems($orderItems);
396
        $om->persist($order);
397
398
        return $orderItems;
399
    }
400
401
    /**
402
     * @param ObjectManager $om
403
     * @param Store         $store
404
     * @param Channel       $channel
405
     * @param Customer      $customer
406
     * @param CartStatus    $status
407
     * @param int           $origin
408
     * @param string        $currency
409
     * @param int           $rate
410
     *
411
     * @return Cart
412
     */
413
    protected function generateShoppingCart(
414
        ObjectManager $om,
415
        Store $store,
416
        Channel $channel,
417
        Customer $customer,
418
        CartStatus $status,
419
        $origin,
420
        $currency = 'USD',
421
        $rate = 1
422
    ) {
423
        $cart = new Cart();
424
        $cart->setOrganization($customer->getOrganization());
425
        $cart->setChannel($channel->getDataSource());
426
        $cart->setCustomer($customer);
427
        $cart->setOwner($customer->getOwner());
428
        $cart->setStatus($status);
429
        $cart->setStore($store);
430
        $cart->setBaseCurrencyCode($currency);
431
        $cart->setStoreCurrencyCode($currency);
432
        $cart->setQuoteCurrencyCode($currency);
433
        $cart->setStoreToBaseRate($rate);
434
        $cart->setStoreToQuoteRate($rate);
435
        $cart->setIsGuest(0);
436
        $cart->setEmail($customer->getEmail());
437
438
        $datetime = new \DateTime('now');
439
        $datetime->modify(sprintf('-%s day', rand(1, 5)));
440
441
        $cart->setCreatedAt($datetime);
442
        $cart->setUpdatedAt($datetime);
443
        $cart->setOriginId($origin);
444
        $cart->setDataChannel($channel);
445
        $om->persist($cart);
446
447
        return $cart;
448
    }
449
450
    /**
451
     * @param ObjectManager $om
452
     * @param Cart          $cart
453
     *
454
     * @return CartItem[]
455
     */
456
    protected function generateShoppingCartItem(ObjectManager $om, Cart $cart)
457
    {
458
459
        $products = ['Computer', 'Gaming Computer', 'Universal Camera Case', 'SLR Camera Tripod',
460
            'Two Year Extended Warranty - Parts and Labor', 'Couch', 'Chair', 'Magento Red Furniture Set'];
461
462
        $cartItems = [];
463
        $cartItemsCount = rand(0, 2);
464
        $total = 0.0;
465
        $totalTaxAmount = 0.0;
466
        $shipping = rand(0, 1);
467
        for ($i = 0; $i <= $cartItemsCount; $i++) {
468
            $product = $products[rand(0, count($products)-1)];
469
            $origin = $i+1;
470
            $price = rand(10, 200);
471
            $price = $price + rand(0, 99)/100.0;
472
            $taxAmount = $price * self::TAX;
473
            $totalTaxAmount = $totalTaxAmount + $taxAmount;
474
            $total = $total + $price + $taxAmount;
475
            $cartItem = new CartItem();
476
            $cartItem->setProductId(rand(1, 100));
477
            $cartItem->setFreeShipping((string)$shipping);
478
            $cartItem->setIsVirtual(0);
479
            $cartItem->setRowTotal($price + $taxAmount);
480
            $cartItem->setPriceInclTax($price + $taxAmount);
481
            $cartItem->setTaxAmount($taxAmount);
482
            $cartItem->setSku('sku-' . strtolower(str_replace(" ", "_", $product)));
483
            $cartItem->setProductType('simple');
484
            $cartItem->setName($product);
485
            $cartItem->setQty(1);
486
            $cartItem->setPrice($price);
487
            $cartItem->setDiscountAmount(0);
488
            $cartItem->setTaxPercent(self::TAX);
489
            $cartItem->setCreatedAt(new \DateTime('now'));
490
            $cartItem->setUpdatedAt(new \DateTime('now'));
491
            $cartItem->setOriginId($origin);
492
            $cartItem->setCart($cart);
493
            $cartItem->setOwner($cart->getOrganization());
494
            $cart->getCartItems()->add($cartItem);
495
            $cart->setItemsQty($i+1);
496
            $cart->setItemsCount($i+1);
497
            $om->persist($cartItem);
498
            $cartItems[] = $cartItem;
499
        }
500
        $cart->setSubTotal($total);
501
        $shippingAmount = 0.0;
502
        if ((bool)$shipping) {
503
            $shippingAmount = rand(3, 10);
504
        }
505
        $cart->setGrandTotal($total + $shippingAmount);
506
        $cart->setTaxAmount($totalTaxAmount);
507
        $om->persist($cart);
508
        return $cartItems;
509
    }
510
511
    protected function getOrderAddress(ObjectManager $om)
512
    {
513
        $address = new OrderAddress;
514
        $address->setCity('City');
515
        $address->setStreet('First street');
516
        $address->setPostalCode(123456);
517
        $address->setFirstName('John');
518
        $address->setLastName('Doe');
519
        /** @var Country $country */
520
        $country = $om->getRepository('OroAddressBundle:Country')->findOneBy(['iso2Code' => 'US']);
521
        $address->setCountry($country);
522
        /** @var Region $region */
523
        $region = $om->getRepository('OroAddressBundle:Region')->findOneBy(['combinedCode' => 'US-AK']);
524
        $address->setRegion($region);
525
        $om->persist($address);
526
527
        return $address;
528
    }
529
530
    /**
531
     * @param ObjectManager $om
532
     * @param Website       $website
0 ignored issues
show
Bug introduced by
There is no parameter named $website. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
533
     * @param Store         $store
534
     * @param CustomerGroup $group
535
     * @param Channel       $channel
536
     * @param Organization  $organization
537
     *
538
     * @return Customer[]
539
     */
540
    protected function persistDemoCustomers(
541
        ObjectManager $om,
542
        Store $store,
543
        CustomerGroup $group,
544
        Channel $channel,
545
        Organization $organization
546
    ) {
547
        $accounts = $om->getRepository('OroCRMAccountBundle:Account')->findAll();
548
        $contacts = $om->getRepository('OroCRMContactBundle:Contact')->findAll();
549
        $customers = [];
550
551
        $buffer = range(0, count($accounts) - 1);
552
        for ($i = 0; $i < 25; ++$i) {
553
            $birthday  = $this->generateBirthday();
554
555
            /** @var Contact $contact */
556
            $contact = $contacts[$buffer[$i]];
557
            $customer = new Customer();
558
            $customer->setWebsite($store->getWebsite())
559
                ->setChannel($channel->getDataSource())
560
                ->setStore($store)
561
                ->setFirstName($contact->getFirstName())
562
                ->setLastName($contact->getLastName())
563
                ->setEmail($contact->getPrimaryEmail())
0 ignored issues
show
Documentation introduced by
$contact->getPrimaryEmail() is of type object<OroCRM\Bundle\Con...tity\ContactEmail>|null, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
564
                ->setBirthday($birthday)
565
                ->setVat(mt_rand(10000000, 99999999))
566
                ->setGroup($group)
567
                ->setCreatedAt(new \DateTime('now'))
568
                ->setUpdatedAt(new \DateTime('now'))
569
                ->setOriginId($i + 1)
570
                ->setAccount($accounts[$buffer[$i]])
571
                ->setContact($contact)
572
                ->setOrganization($organization)
573
                ->setOwner($this->getRandomOwner())
574
                ->setDataChannel($channel);
575
576
            $om->persist($customer);
577
            $customers[] = $customer;
578
        }
579
580
        return $customers;
581
    }
582
583
    /**
584
     * Generates a date of birth
585
     *
586
     * @return \DateTime
587
     */
588 View Code Duplication
    private function generateBirthday()
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...
589
    {
590
        // Convert to timestamps
591
        $min = strtotime('1950-01-01');
592
        $max = strtotime('2000-01-01');
593
594
        // Generate random number using above bounds
595
        $val = rand($min, $max);
596
597
        // Convert back to desired date format
598
        return new \DateTime(date('Y-m-d', $val), new \DateTimeZone('UTC'));
599
    }
600
601
    /**
602
     * @return User
603
     */
604
    protected function getRandomOwner()
605
    {
606
        $randomUser = count($this->users)-1;
607
        $user = $this->users[rand(0, $randomUser)];
608
609
        return $user;
610
    }
611
}
612