Customer   D
last analyzed

Complexity

Total Complexity 56

Size/Duplication

Total Lines 895
Duplicated Lines 1.12 %

Coupling/Cohesion

Components 5
Dependencies 10

Importance

Changes 0
Metric Value
wmc 56
lcom 5
cbo 10
dl 10
loc 895
rs 4.4444
c 0
b 0
f 0

50 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A setWebsite() 0 6 1
A getWebsite() 0 4 1
A getWebsiteName() 0 4 2
A setStore() 0 6 1
A getStore() 0 4 1
A getStoreName() 0 4 2
A isConfirmed() 0 4 1
A setConfirmed() 0 6 1
A isGuest() 0 4 1
A setGuest() 0 6 1
A getCreatedIn() 0 4 1
A setCreatedIn() 0 6 1
A setGroup() 0 6 1
A getGroup() 0 4 1
A setContact() 0 6 1
A getContact() 0 4 1
A setAccount() 0 6 1
A getAccount() 0 4 1
A setVat() 0 6 1
A getVat() 0 4 1
A setIsActive() 0 6 1
A getIsActive() 0 4 1
A setCarts() 0 4 1
A getCarts() 0 4 1
A getOrders() 0 4 1
A getAddressByOriginId() 0 8 1
A setLifetime() 0 6 1
A getLifetime() 0 4 1
A setCurrency() 0 6 1
A getCurrency() 0 4 1
A addAddress() 10 10 2
A getOwner() 0 4 1
A setOwner() 0 6 1
A setOrganization() 0 6 1
A getOrganization() 0 4 1
A getSyncState() 0 4 1
A setSyncState() 0 6 1
A getPassword() 0 4 1
A setPassword() 0 6 1
A setGeneratedPassword() 0 8 2
A getGeneratedPassword() 0 4 1
A getNewsletterSubscribers() 0 4 1
A setNewsletterSubscribers() 0 6 1
A isSubscribed() 0 10 3
A getSyncedAt() 0 4 1
A setSyncedAt() 0 6 1
A getImportedAt() 0 4 1
A setImportedAt() 0 6 1
A __toString() 0 4 1

How to fix   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like Customer often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use Customer, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
namespace Oro\Bundle\MagentoBundle\Entity;
4
5
use Doctrine\Common\Collections\ArrayCollection;
6
use Doctrine\Common\Collections\Collection;
7
use Doctrine\ORM\Mapping as ORM;
8
9
use Oro\Bundle\AddressBundle\Entity\AbstractAddress;
10
use Oro\Bundle\EntityConfigBundle\Metadata\Annotation\Config;
11
use Oro\Bundle\EntityConfigBundle\Metadata\Annotation\ConfigField;
12
use Oro\Bundle\OrganizationBundle\Entity\Organization;
13
use Oro\Bundle\UserBundle\Entity\User;
14
use Oro\Bundle\AccountBundle\Entity\Account;
15
use Oro\Bundle\AnalyticsBundle\Model\RFMAwareInterface;
16
use Oro\Bundle\AnalyticsBundle\Model\RFMAwareTrait;
17
use Oro\Bundle\ContactBundle\Entity\Contact;
18
use Oro\Bundle\MagentoBundle\Model\ExtendCustomer;
19
use Oro\Bundle\ChannelBundle\Model\ChannelAwareInterface;
20
use Oro\Bundle\ChannelBundle\Model\CustomerIdentityInterface;
21
22
/**
23
 * Class Customer
24
 *
25
 * @SuppressWarnings(PHPMD.TooManyFields)
26
 * @SuppressWarnings(PHPMD.ExcessivePublicCount)
27
 * @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
28
 *
29
 * @package Oro\Bundle\OroMagentoBundle\Entity
30
 * @ORM\Entity(repositoryClass="Oro\Bundle\MagentoBundle\Entity\Repository\CustomerRepository")
31
 * @ORM\Table(
32
 *      name="orocrm_magento_customer",
33
 *      uniqueConstraints={@ORM\UniqueConstraint(name="magecustomer_oid_cid_unq", columns={"origin_id", "channel_id"})},
34
 *      indexes={
35
 *          @ORM\Index(name="magecustomer_name_idx",columns={"first_name", "last_name"}),
36
 *          @ORM\Index(name="magecustomer_rev_name_idx",columns={"last_name", "first_name"}),
37
 *          @ORM\Index(name="magecustomer_email_guest_idx",columns={"email"})
38
 *      }
39
 * )
40
 * @Config(
41
 *      routeName="oro_magento_customer_index",
42
 *      routeView="oro_magento_customer_view",
43
 *      defaultValues={
44
 *          "entity"={
45
 *              "icon"="icon-user"
46
 *          },
47
 *          "ownership"={
48
 *              "owner_type"="USER",
49
 *              "owner_field_name"="owner",
50
 *              "owner_column_name"="user_owner_id",
51
 *              "organization_field_name"="organization",
52
 *              "organization_column_name"="organization_id"
53
 *          },
54
 *          "security"={
55
 *              "type"="ACL",
56
 *              "group_name"="",
57
 *              "category"="sales_data"
58
 *          },
59
 *          "form"={
60
 *              "grid_name"="magento-customers-grid",
61
 *          },
62
 *          "grid"={
63
 *              "default"="magento-customers-grid",
64
 *              "context"="magento-customers-for-context-grid"
65
 *          },
66
 *          "tag"={
67
 *              "enabled"=true
68
 *          }
69
 *      }
70
 * )
71
 */
72
class Customer extends ExtendCustomer implements
73
    ChannelAwareInterface,
74
    CustomerIdentityInterface,
75
    RFMAwareInterface,
76
    OriginAwareInterface,
77
    IntegrationAwareInterface
78
{
79
    const SYNC_TO_MAGENTO = 1;
80
    const MAGENTO_REMOVED = 2;
81
82
    use IntegrationEntityTrait, OriginTrait, ChannelEntityTrait, RFMAwareTrait;
83
84
    /**
85
     * @var int
86
     *
87
     * @ORM\Id
88
     * @ORM\Column(type="integer", name="id")
89
     * @ORM\GeneratedValue(strategy="AUTO")
90
     * @ConfigField(
91
     *      defaultValues={
92
     *          "importexport"={
93
     *              "excluded"=true
94
     *          }
95
     *      }
96
     * )
97
     */
98
    protected $id;
99
100
    /*
101
     * FIELDS are duplicated to enable dataaudit only for customer fields
102
     */
103
    /**
104
     * @var string
105
     *
106
     * @ORM\Column(name="name_prefix", type="string", length=255, nullable=true)
107
     */
108
    protected $namePrefix;
109
110
    /**
111
     * @var string
112
     *
113
     * @ORM\Column(name="first_name", type="string", length=255, nullable=true)
114
     */
115
    protected $firstName;
116
117
    /**
118
     * @var string
119
     *
120
     * @ORM\Column(name="middle_name", type="string", length=255, nullable=true)
121
     */
122
    protected $middleName;
123
124
    /**
125
     * @var string
126
     *
127
     * @ORM\Column(name="last_name", type="string", length=255, nullable=true)
128
     */
129
    protected $lastName;
130
131
    /**
132
     * @var string
133
     *
134
     * @ORM\Column(name="name_suffix", type="string", length=255, nullable=true)
135
     */
136
    protected $nameSuffix;
137
138
    /**
139
     * @var string
140
     *
141
     * @ORM\Column(name="gender", type="string", length=8, nullable=true)
142
     */
143
    protected $gender;
144
145
    /**
146
     * @var \DateTime
147
     *
148
     * @ORM\Column(name="birthday", type="date", nullable=true)
149
     */
150
    protected $birthday;
151
152
    /**
153
     * @var string
154
     *
155
     * @ORM\Column(name="email", type="string", length=255, nullable=true)
156
     * @ConfigField(
157
     *      defaultValues={
158
     *          "entity"={
159
     *              "contact_information"="email"
160
     *          }
161
     *      }
162
     * )
163
     */
164
    protected $email;
165
166
    /**
167
     * @var \DateTime $createdAt
168
     *
169
     * @ORM\Column(type="datetime", name="created_at")
170
     * @ConfigField(
171
     *      defaultValues={
172
     *          "entity"={
173
     *              "label"="oro.ui.created_at"
174
     *          }
175
     *      }
176
     * )
177
     */
178
    protected $createdAt;
179
180
    /**
181
     * @var \DateTime $updatedAt
182
     *
183
     * @ORM\Column(type="datetime", name="updated_at")
184
     * @ConfigField(
185
     *      defaultValues={
186
     *          "entity"={
187
     *              "label"="oro.ui.updated_at"
188
     *          }
189
     *      }
190
     * )
191
     */
192
    protected $updatedAt;
193
194
    /**
195
     * @var \DateTime
196
     *
197
     * @ORM\Column(type="datetime", name="imported_at", nullable=true)
198
     */
199
    protected $importedAt;
200
201
    /**
202
     * @var \DateTime
203
     *
204
     * @ORM\Column(type="datetime", name="synced_at", nullable=true)
205
     */
206
    protected $syncedAt;
207
208
    /**
209
     * @var Website
210
     *
211
     * @ORM\ManyToOne(targetEntity="Oro\Bundle\MagentoBundle\Entity\Website")
212
     * @ORM\JoinColumn(name="website_id", referencedColumnName="id", onDelete="SET NULL")
213
     * @ConfigField(
214
     *      defaultValues={
215
     *          "importexport"={
216
     *              "full"=false
217
     *          }
218
     *      }
219
     * )
220
     */
221
    protected $website;
222
223
    /**
224
     * @var Store
225
     *
226
     * @ORM\ManyToOne(targetEntity="Oro\Bundle\MagentoBundle\Entity\Store")
227
     * @ORM\JoinColumn(name="store_id", referencedColumnName="id", onDelete="SET NULL")
228
     * @ConfigField(
229
     *      defaultValues={
230
     *          "importexport"={
231
     *              "full"=false
232
     *          }
233
     *      }
234
     * )
235
     */
236
    protected $store;
237
238
    /**
239
     * @var string
240
     *
241
     * @ORM\Column(name="created_in", type="string", length=255, nullable=true)
242
     */
243
    protected $createdIn;
244
245
    /**
246
     * @var bool
247
     * @ORM\Column(name="is_confirmed", type="boolean", nullable=true)
248
     */
249
    protected $confirmed = true;
250
251
    /**
252
     * @var bool
253
     * @ORM\Column(name="is_guest", type="boolean", nullable=false, options={"default"=false})
254
     */
255
    protected $guest = false;
256
257
    /**
258
     * @var CustomerGroup
259
     *
260
     * @ORM\ManyToOne(targetEntity="Oro\Bundle\MagentoBundle\Entity\CustomerGroup")
261
     * @ORM\JoinColumn(name="customer_group_id", referencedColumnName="id", onDelete="SET NULL")
262
     * @ConfigField(
263
     *      defaultValues={
264
     *          "importexport"={
265
     *              "full"=false
266
     *          }
267
     *      }
268
     * )
269
     */
270
    protected $group;
271
272
    /**
273
     * @var Contact
274
     *
275
     * @ORM\ManyToOne(targetEntity="Oro\Bundle\ContactBundle\Entity\Contact")
276
     * @ORM\JoinColumn(name="contact_id", referencedColumnName="id", onDelete="SET NULL")
277
     * @ConfigField(
278
     *      defaultValues={
279
     *          "importexport"={
280
     *              "excluded"=true
281
     *          }
282
     *      }
283
     * )
284
     */
285
    protected $contact;
286
287
    /**
288
     * @var Account
289
     *
290
     * @ORM\ManyToOne(targetEntity="Oro\Bundle\AccountBundle\Entity\Account")
291
     * @ORM\JoinColumn(name="account_id", referencedColumnName="id", onDelete="SET NULL")
292
     * @ConfigField(
293
     *      defaultValues={
294
     *          "importexport"={
295
     *              "excluded"=true
296
     *          }
297
     *      }
298
     * )
299
     */
300
    protected $account;
301
302
    /**
303
     * @var Collection
304
     *
305
     * @ORM\OneToMany(targetEntity="Oro\Bundle\MagentoBundle\Entity\Address",
306
     *     mappedBy="owner", cascade={"all"}, orphanRemoval=true
307
     * )
308
     * @ORM\OrderBy({"primary" = "DESC"})
309
     * @ConfigField(
310
     *      defaultValues={
311
     *          "importexport"={
312
     *              "full"=true
313
     *          }
314
     *      }
315
     * )
316
     */
317
    protected $addresses;
318
319
    /**
320
     * @var Collection
321
     *
322
     * @ORM\OneToMany(targetEntity="Oro\Bundle\MagentoBundle\Entity\Cart",
323
     *     mappedBy="customer", cascade={"remove"}, orphanRemoval=true
324
     * )
325
     * @ConfigField(
326
     *      defaultValues={
327
     *          "importexport"={
328
     *              "excluded"=true
329
     *          }
330
     *      }
331
     * )
332
     */
333
    protected $carts;
334
335
    /**
336
     * @var Collection
337
     *
338
     * @ORM\OneToMany(targetEntity="Oro\Bundle\MagentoBundle\Entity\Order",
339
     *     mappedBy="customer", cascade={"remove"}, orphanRemoval=true
340
     * )
341
     * @ConfigField(
342
     *      defaultValues={
343
     *          "importexport"={
344
     *              "excluded"=true
345
     *          }
346
     *      }
347
     * )
348
     */
349
    protected $orders;
350
351
    /**
352
     * @var boolean
353
     *
354
     * @ORM\Column(type="boolean", name="is_active")
355
     * @ConfigField(
356
     *      defaultValues={
357
     *          "importexport"={
358
     *              "excluded"=true
359
     *          }
360
     *      }
361
     * )
362
     */
363
    protected $isActive = false;
364
365
    /**
366
     * @var float
367
     *
368
     * @ORM\Column(name="vat", type="string", length=255, nullable=true)
369
     */
370
    protected $vat;
371
372
    /**
373
     * @var float
374
     *
375
     * @ORM\Column(name="lifetime", type="money", nullable=true)
376
     * @ConfigField(
377
     *      defaultValues={
378
     *          "importexport"={
379
     *              "excluded"=true
380
     *          }
381
     *      }
382
     * )
383
     */
384
    protected $lifetime = 0;
385
386
    /**
387
     * @var string
388
     *
389
     * @ORM\Column(name="currency", type="string", length=10, nullable=true)
390
     * @ConfigField(
391
     *      defaultValues={
392
     *          "importexport"={
393
     *              "excluded"=true
394
     *          }
395
     *      }
396
     * )
397
     */
398
    protected $currency;
399
400
    /**
401
     * @var int
402
     *
403
     * @ORM\Column(name="sync_state", type="integer", nullable=true)
404
     * @ConfigField(
405
     *      defaultValues={
406
     *          "importexport"={
407
     *              "excluded"=true
408
     *          }
409
     *      }
410
     * )
411
     */
412
    protected $syncState;
413
414
    /**
415
     * @var User
416
     * @ORM\ManyToOne(targetEntity="Oro\Bundle\UserBundle\Entity\User")
417
     * @ORM\JoinColumn(name="user_owner_id", referencedColumnName="id", onDelete="SET NULL")
418
     * @ConfigField(
419
     *      defaultValues={
420
     *          "importexport"={
421
     *              "excluded"=true
422
     *          }
423
     *      }
424
     * )
425
     */
426
    protected $owner;
427
428
    /**
429
     * @var Organization
430
     *
431
     * @ORM\ManyToOne(targetEntity="Oro\Bundle\OrganizationBundle\Entity\Organization")
432
     * @ORM\JoinColumn(name="organization_id", referencedColumnName="id", onDelete="SET NULL")
433
     * @ConfigField(
434
     *      defaultValues={
435
     *          "importexport"={
436
     *              "excluded"=true
437
     *          }
438
     *      }
439
     * )
440
     */
441
    protected $organization;
442
443
    /**
444
     * @var string
445
     *
446
     * @ORM\Column(name="password", type="string", length=32, nullable=true)
447
     */
448
    protected $password;
449
450
    /**
451
     * @var NewsletterSubscriber[]|Collection
452
     *
453
     * @ORM\OneToMany(targetEntity="Oro\Bundle\MagentoBundle\Entity\NewsletterSubscriber",
454
     *      mappedBy="customer", cascade={"remove"}, orphanRemoval=true)
455
     * @ConfigField(
456
     *      defaultValues={
457
     *          "importexport"={
458
     *              "excluded"=true
459
     *          }
460
     *      }
461
     * )
462
     */
463
    protected $newsletterSubscribers;
464
465
    /**
466
     * {@inheritdoc}
467
     */
468
    public function __construct()
469
    {
470
        parent::__construct();
471
472
        $this->carts  = new ArrayCollection();
473
        $this->orders = new ArrayCollection();
474
        $this->newsletterSubscribers = new ArrayCollection();
475
    }
476
477
    /**
478
     * @param Website $website
479
     *
480
     * @return Customer
481
     */
482
    public function setWebsite(Website $website)
483
    {
484
        $this->website = $website;
485
486
        return $this;
487
    }
488
489
    /**
490
     * @return Website
491
     */
492
    public function getWebsite()
493
    {
494
        return $this->website;
495
    }
496
497
    /**
498
     * @return string
499
     */
500
    public function getWebsiteName()
501
    {
502
        return $this->website ? $this->website->getName() : null;
503
    }
504
505
    /**
506
     * @param Store $store
507
     *
508
     * @return Customer
509
     */
510
    public function setStore(Store $store)
511
    {
512
        $this->store = $store;
513
514
        return $this;
515
    }
516
517
    /**
518
     * @return Store
519
     */
520
    public function getStore()
521
    {
522
        return $this->store;
523
    }
524
525
    /**
526
     * @return string|null
527
     */
528
    public function getStoreName()
529
    {
530
        return $this->store ? $this->store->getName() : null;
531
    }
532
533
    /**
534
     * @return bool
535
     */
536
    public function isConfirmed()
537
    {
538
        return $this->confirmed;
539
    }
540
541
    /**
542
     * @param bool $confirmed
543
     * @return Customer
544
     */
545
    public function setConfirmed($confirmed)
546
    {
547
        $this->confirmed = $confirmed;
548
549
        return $this;
550
    }
551
552
    /**
553
     * @return bool
554
     */
555
    public function isGuest()
556
    {
557
        return $this->guest;
558
    }
559
560
    /**
561
     * @param bool $guest
562
     * @return Customer
563
     */
564
    public function setGuest($guest)
565
    {
566
        $this->guest = $guest;
567
568
        return $this;
569
    }
570
571
    /**
572
     * @return string
573
     */
574
    public function getCreatedIn()
575
    {
576
        return $this->createdIn;
577
    }
578
579
    /**
580
     * @param string $createdIn
581
     * @return Customer
582
     */
583
    public function setCreatedIn($createdIn)
584
    {
585
        $this->createdIn = $createdIn;
586
587
        return $this;
588
    }
589
590
    /**
591
     * @param CustomerGroup $group
592
     *
593
     * @return Customer
594
     */
595
    public function setGroup(CustomerGroup $group)
596
    {
597
        $this->group = $group;
598
599
        return $this;
600
    }
601
602
    /**
603
     * @return CustomerGroup
604
     */
605
    public function getGroup()
606
    {
607
        return $this->group;
608
    }
609
610
    /**
611
     * @param Contact $contact
612
     *
613
     * @return Customer
614
     */
615
    public function setContact($contact)
616
    {
617
        $this->contact = $contact;
618
619
        return $this;
620
    }
621
622
    /**
623
     * @return Contact
624
     */
625
    public function getContact()
626
    {
627
        return $this->contact;
628
    }
629
630
    /**
631
     * @param Account $account
632
     *
633
     * @return Customer
634
     */
635
    public function setAccount($account)
636
    {
637
        $this->account = $account;
638
639
        return $this;
640
    }
641
642
    /**
643
     * @return Account
644
     */
645
    public function getAccount()
646
    {
647
        return $this->account;
648
    }
649
650
    /**
651
     * @param string $vat
652
     *
653
     * @return Customer
654
     */
655
    public function setVat($vat)
656
    {
657
        $this->vat = $vat;
0 ignored issues
show
Documentation Bug introduced by
The property $vat was declared of type double, but $vat is of type string. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
658
659
        return $this;
660
    }
661
662
    /**
663
     * @return string
664
     */
665
    public function getVat()
666
    {
667
        return $this->vat;
668
    }
669
670
    /**
671
     * @param bool $isActive
672
     *
673
     * @return Customer
674
     */
675
    public function setIsActive($isActive)
676
    {
677
        $this->isActive = $isActive;
678
679
        return $this;
680
    }
681
682
    /**
683
     * @return bool
684
     */
685
    public function getIsActive()
686
    {
687
        return $this->isActive;
688
    }
689
690
    /**
691
     * @param Collection $carts
692
     */
693
    public function setCarts($carts)
694
    {
695
        $this->carts = $carts;
696
    }
697
698
    /**
699
     * @return Collection
700
     */
701
    public function getCarts()
702
    {
703
        return $this->carts;
704
    }
705
706
    /**
707
     * @return Collection
708
     */
709
    public function getOrders()
710
    {
711
        return $this->orders;
712
    }
713
714
    /**
715
     * @param int $originId
716
     *
717
     * @return Address|false
718
     */
719
    public function getAddressByOriginId($originId)
720
    {
721
        return $this->addresses->filter(
722
            function (Address $item) use ($originId) {
723
                return $item->getOriginId() === $originId;
724
            }
725
        )->first();
726
    }
727
728
    /**
729
     * @param double $lifetime
730
     *
731
     * @return Customer
732
     */
733
    public function setLifetime($lifetime)
734
    {
735
        $this->lifetime = $lifetime;
736
737
        return $this;
738
    }
739
740
    /**
741
     * @return double
742
     */
743
    public function getLifetime()
744
    {
745
        return $this->lifetime;
746
    }
747
748
    /**
749
     * @param string $currency
750
     *
751
     * @return Customer
752
     */
753
    public function setCurrency($currency)
754
    {
755
        $this->currency = $currency;
756
757
        return $this;
758
    }
759
760
    /**
761
     * @return string
762
     */
763
    public function getCurrency()
764
    {
765
        return $this->currency;
766
    }
767
768
    /**
769
     * Add address
770
     *
771
     * @param AbstractAddress $address
772
     * @return Customer
773
     */
774 View Code Duplication
    public function addAddress(AbstractAddress $address)
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...
775
    {
776
        /** @var Address $address */
777
        if (!$this->addresses->contains($address)) {
778
            $this->addresses->add($address);
779
            $address->setOwner($this);
780
        }
781
782
        return $this;
783
    }
784
785
    /**
786
     * @return User
787
     */
788
    public function getOwner()
789
    {
790
        return $this->owner;
791
    }
792
793
    /**
794
     * @param User $user
795
     *
796
     * @return Customer
797
     */
798
    public function setOwner(User $user)
799
    {
800
        $this->owner = $user;
801
802
        return $this;
803
    }
804
805
    /**
806
     * Set organization
807
     *
808
     * @param Organization $organization
809
     * @return Customer
810
     */
811
    public function setOrganization(Organization $organization = null)
812
    {
813
        $this->organization = $organization;
814
815
        return $this;
816
    }
817
818
    /**
819
     * Get organization
820
     *
821
     * @return Organization
822
     */
823
    public function getOrganization()
824
    {
825
        return $this->organization;
826
    }
827
828
    /**
829
     * {@inheritdoc}
830
     */
831
    public function getSyncState()
832
    {
833
        return $this->syncState;
834
    }
835
836
    /**
837
     * {@inheritdoc}
838
     *
839
     * @return Customer
840
     */
841
    public function setSyncState($syncState)
842
    {
843
        $this->syncState = $syncState;
844
845
        return $this;
846
    }
847
848
    /**
849
     * @return string
850
     */
851
    public function getPassword()
852
    {
853
        return $this->password;
854
    }
855
856
    /**
857
     * @param string $password
858
     * @return Customer
859
     */
860
    public function setPassword($password)
861
    {
862
        $this->password = $password;
863
864
        return $this;
865
    }
866
867
    /**
868
     * @param string $password
869
     * @return Customer
870
     */
871
    public function setGeneratedPassword($password)
872
    {
873
        if ($password) {
874
            $this->setPassword($password);
875
        }
876
877
        return $this;
878
    }
879
880
    /**
881
     * @return string
882
     */
883
    public function getGeneratedPassword()
884
    {
885
        return '';
886
    }
887
888
    /**
889
     * @return NewsletterSubscriber[]|Collection
890
     */
891
    public function getNewsletterSubscribers()
892
    {
893
        return $this->newsletterSubscribers;
894
    }
895
896
    /**
897
     * @param Collection|NewsletterSubscriber[] $newsletterSubscribers
898
     * @return Customer
899
     */
900
    public function setNewsletterSubscribers($newsletterSubscribers)
901
    {
902
        $this->newsletterSubscribers = $newsletterSubscribers;
903
904
        return $this;
905
    }
906
907
    /**
908
     * @return bool
909
     */
910
    public function isSubscribed()
911
    {
912
        foreach ($this->getNewsletterSubscribers() as $newsletterSubscriber) {
913
            if ($newsletterSubscriber->isSubscribed()) {
914
                return true;
915
            }
916
        }
917
918
        return false;
919
    }
920
921
    /**
922
     * @return \DateTime
923
     */
924
    public function getSyncedAt()
925
    {
926
        return $this->syncedAt;
927
    }
928
929
    /**
930
     * @param \DateTime|null $syncedAt
931
     * @return Customer
932
     */
933
    public function setSyncedAt(\DateTime $syncedAt = null)
934
    {
935
        $this->syncedAt = $syncedAt;
936
937
        return $this;
938
    }
939
940
    /**
941
     * @return \DateTime
942
     */
943
    public function getImportedAt()
944
    {
945
        return $this->importedAt;
946
    }
947
948
    /**
949
     * @param \DateTime|null $importedAt
950
     * @return Customer
951
     */
952
    public function setImportedAt(\DateTime $importedAt = null)
953
    {
954
        $this->importedAt = $importedAt;
955
956
        return $this;
957
    }
958
959
    /**
960
     * @return string
961
     */
962
    public function __toString()
963
    {
964
        return (string)$this->getLastName() . (string)$this->getFirstName();
965
    }
966
}
967