Completed
Pull Request — master (#108)
by Jeroen De
03:37
created

DoctrineMembershipApplication::setTracking()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
namespace WMDE\Fundraising\Entities;
4
5
use Doctrine\ORM\Mapping as ORM;
6
use Gedmo\Mapping\Annotation as Gedmo;
7
use WMDE\Fundraising\Store\MembershipApplicationData;
8
9
/**
10
 * @since 2.0
11
 *
12
 * @ORM\Table(name="request", indexes={@ORM\Index(name="idx_donation_id", columns={"donation_id"})})
13
 * @ORM\Entity
14
 */
15
class DoctrineMembershipApplication {
16
17
	const STATUS_CONFIRMED = 1;
18
	const STATUS_NEUTRAL = 0;
19
	const STATUS_DELETED = -1;
20
	const STATUS_MODERATION = -2;
21
	const STATUS_ABORTED = -4;
22
	const STATUS_CANCELED = -8;
23
24
	/**
25
	 * @var integer
26
	 *
27
	 * @ORM\Column(name="id", type="integer")
28
	 * @ORM\Id
29
	 * @ORM\GeneratedValue(strategy="IDENTITY")
30
	 */
31
	private $id;
32
33
	/**
34
	 * FIXME: this should not be nullable
35
	 *
36
	 * @var integer
37
	 *
38
	 * @ORM\Column(name="status", type="smallint", options={"default":0}, nullable=true)
39
	 */
40
	private $status = 0;
41
42
	/**
43
	 * @var integer|null
44
	 *
45
	 * @ORM\Column(name="donation_id", type="integer", nullable=true)
46
	 */
47
	private $donationId;
48
49
	/**
50
	 * @var \DateTime
51
	 *
52
	 * @Gedmo\Timestampable(on="create")
53
	 * @ORM\Column(name="timestamp", type="datetime")
54
	 */
55
	private $creationTime;
56
57
	/**
58
	 * @var string|null
59
	 *
60
	 * @ORM\Column(name="anrede", type="string", length=16, nullable=true)
61
	 */
62
	private $applicantSalutation;
63
64
	/**
65
	 * @var string|null
66
	 *
67
	 * @ORM\Column(name="firma", type="string", length=100, nullable=true)
68
	 */
69
	private $company;
70
71
	/**
72
	 * @var string|null
73
	 *
74
	 * @ORM\Column(name="titel", type="string", length=16, nullable=true)
75
	 */
76
	private $applicantTitle;
77
78
	/**
79
	 * @var string
80
	 *
81
	 * @ORM\Column(name="name", type="string", length=250, options={"default":""}, nullable=false)
82
	 */
83
	private $probablyUnusedNameField = '';
84
85
	/**
86
	 * @var string
87
	 *
88
	 * @ORM\Column(name="vorname", type="string", length=50, options={"default":""}, nullable=false)
89
	 */
90
	private $applicantFirstName = '';
91
92
	/**
93
	 * @var string
94
	 *
95
	 * @ORM\Column(name="nachname", type="string", length=50, options={"default":""}, nullable=false)
96
	 */
97
	private $applicantLastName = '';
98
99
	/**
100
	 * @var string|null
101
	 *
102
	 * @ORM\Column(name="strasse", type="string", length=100, nullable=true)
103
	 */
104
	private $address;
105
106
	/**
107
	 * @var string|null
108
	 *
109
	 * @ORM\Column(name="plz", type="string", length=8, nullable=true)
110
	 */
111
	private $postcode;
112
113
	/**
114
	 * @var string|null
115
	 *
116
	 * @ORM\Column(name="ort", type="string", length=100, nullable=true)
117
	 */
118
	private $city;
119
120
	/**
121
	 * @var string|null
122
	 *
123
	 * @ORM\Column(name="country", type="string", length=8, options={"default":""}, nullable=true)
124
	 */
125
	private $country = '';
126
127
	/**
128
	 * @var string
129
	 *
130
	 * @ORM\Column(name="email", type="string", length=250, options={"default":""}, nullable=false)
131
	 */
132
	private $applicantEmailAddress = '';
133
134
	/**
135
	 * @var string
136
	 *
137
	 * @ORM\Column(name="phone", type="string", length=30, options={"default":""}, nullable=false)
138
	 */
139
	private $applicantPhoneNumber = '';
140
141
	/**
142
	 * Date of birth
143
	 *
144
	 * @var \DateTime|null
145
	 *
146
	 * @ORM\Column(name="dob", type="date", nullable=true)
147
	 */
148
	private $applicantDateOfBirth;
149
150
	/**
151
	 * @var string
152
	 *
153
	 * @ORM\Column(name="wikimedium_shipping", type="string", options={"default":""}, nullable=false)
154
	 */
155
	private $wikimediumShipping = 'none';
156
157
	/**
158
	 * @var string
159
	 *
160
	 * @ORM\Column(name="membership_type", type="string", options={"default":"sustaining"}, nullable=false)
161
	 */
162
	private $membershipType = 'sustaining';
163
164
	/**
165
	 * @var string
166
	 *
167
	 * @ORM\Column(name="payment_type", type="string", options={"default":"BEZ"}, nullable=false)
168
	 */
169
	private $paymentType = 'BEZ';
170
171
	/**
172
	 * @var integer
173
	 *
174
	 * @ORM\Column(name="membership_fee", type="integer", options={"default":0}, nullable=false)
175
	 */
176
	private $paymentAmountInEuro = 0;
177
178
	/**
179
	 * FIXME: this should not be nullable
180
	 *
181
	 * @var integer
182
	 *
183
	 * @ORM\Column(name="membership_fee_interval", type="smallint", options={"default":12}, nullable=true)
184
	 */
185
	private $paymentIntervalInMonths = 12;
186
187
	/**
188
	 * @var string
189
	 *
190
	 * @ORM\Column(name="account_number", type="string", length=16, options={"default":""}, nullable=false)
191
	 */
192
	private $paymentBankAccount = '';
193
194
	/**
195
	 * @var string
196
	 *
197
	 * @ORM\Column(name="bank_name", type="string", length=50, options={"default":""}, nullable=false)
198
	 */
199
	private $paymentBankName = '';
200
201
	/**
202
	 * @var string
203
	 *
204
	 * @ORM\Column(name="bank_code", type="string", length=16, options={"default":""}, nullable=false)
205
	 */
206
	private $paymentBankCode = '';
207
208
	/**
209
	 * @var string|null
210
	 *
211
	 * @ORM\Column(name="iban", type="string", length=32, options={"default":""}, nullable=true)
212
	 */
213
	private $paymentIban = '';
214
215
	/**
216
	 * @var string|null
217
	 *
218
	 * @ORM\Column(name="bic", type="string", length=32, options={"default":""}, nullable=true)
219
	 */
220
	private $paymentBic = '';
221
222
	/**
223
	 * @var string
224
	 *
225
	 * @ORM\Column(name="account_holder", type="string", length=50, options={"default":""}, nullable=false)
226
	 */
227
	private $paymentBankAccountHolder = '';
228
229
	/**
230
	 * @var string
231
	 *
232
	 * @ORM\Column(name="comment", type="text", options={"default":""}, nullable=false)
233
	 */
234
	private $comment = '';
235
236
	/**
237
	 * @var \DateTime|null
238
	 *
239
	 * @ORM\Column(name="export", type="datetime", nullable=true)
240
	 */
241
	private $export;
242
243
	/**
244
	 * @var \DateTime|null
245
	 *
246
	 * @ORM\Column(name="backup", type="datetime", nullable=true)
247
	 */
248
	private $backup;
249
250
	/**
251
	 * @var boolean
252
	 *
253
	 * @ORM\Column(name="wikilogin", type="boolean", options={"default":0}, nullable=false)
254
	 */
255
	private $wikilogin = 0;
256
257
	/**
258
	 * @var string|null
259
	 *
260
	 * @ORM\Column(name="tracking", type="string", length=50, nullable=true)
261
	 */
262
	private $tracking;
263
264
	/**
265
	 * @var string|null
266
	 *
267
	 * @ORM\Column(name="data", type="text", nullable=true)
268
	 */
269
	private $data;
270
271
	/**
272
	 * @return integer
273
	 */
274
	public function getId() {
275
		return $this->id;
276
	}
277
278
	/**
279
	 * @since 2.0
280
	 *
281
	 * @param integer|null $id
282
	 */
283
	public function setId( $id ) {
284
		$this->id = $id;
285
	}
286
287
	/**
288
	 * @param integer|null $donationId
289
	 *
290
	 * @return DoctrineMembershipApplication
291
	 */
292
	public function setDonationId( $donationId ) {
293
		$this->donationId = $donationId;
294
295
		return $this;
296
	}
297
298
	/**
299
	 * Returns the id of the donation that led to the membership application,
300
	 * or null when the application is not linked to any donation.
301
	 *
302
	 * @return integer|null
303
	 */
304
	public function getDonationId() {
305
		return $this->donationId;
306
	}
307
308
	/**
309
	 * @param \DateTime|null $creationTime
310
	 *
311
	 * @return DoctrineMembershipApplication
312
	 */
313
	public function setCreationTime( $creationTime ) {
314
		$this->creationTime = $creationTime;
315
316
		return $this;
317
	}
318
319
	/**
320
	 * @return \DateTime|null
321
	 */
322
	public function getCreationTime() {
323
		return $this->creationTime;
324
	}
325
326
	/**
327
	 * @param string|null $applicantSalutation
328
	 *
329
	 * @return DoctrineMembershipApplication
330
	 */
331
	public function setApplicantSalutation( $applicantSalutation ) {
332
		$this->applicantSalutation = $applicantSalutation;
333
334
		return $this;
335
	}
336
337
	/**
338
	 * @return string|null
339
	 */
340
	public function getApplicantSalutation() {
341
		return $this->applicantSalutation;
342
	}
343
344
	/**
345
	 * @param string|null $company
346
	 *
347
	 * @return DoctrineMembershipApplication
348
	 */
349
	public function setCompany( $company ) {
350
		$this->company = $company;
351
352
		return $this;
353
	}
354
355
	/**
356
	 * @return string|null
357
	 */
358
	public function getCompany() {
359
		return $this->company;
360
	}
361
362
	/**
363
	 * @param string $applicantTitle
364
	 *
365
	 * @return DoctrineMembershipApplication
366
	 */
367
	public function setApplicantTitle( $applicantTitle ) {
368
		$this->applicantTitle = $applicantTitle;
369
370
		return $this;
371
	}
372
373
	/**
374
	 * @return string
375
	 */
376
	public function getApplicantTitle() {
377
		return $this->applicantTitle;
378
	}
379
380
	/**
381
	 * @param string $probablyUnusedNameField
382
	 *
383
	 * @return DoctrineMembershipApplication
384
	 */
385
	public function setProbablyUnusedNameField( $probablyUnusedNameField ) {
386
		$this->probablyUnusedNameField = $probablyUnusedNameField;
387
388
		return $this;
389
	}
390
391
	/**
392
	 * @return string
393
	 */
394
	public function getProbablyUnusedNameField() {
395
		return $this->probablyUnusedNameField;
396
	}
397
398
	/**
399
	 * @param string $applicantFirstName
400
	 *
401
	 * @return DoctrineMembershipApplication
402
	 */
403
	public function setApplicantFirstName( $applicantFirstName ) {
404
		$this->applicantFirstName = $applicantFirstName;
405
		$this->setNameFromParts( $applicantFirstName, $this->getApplicantLastName() );
406
407
		return $this;
408
	}
409
410
	/**
411
	 * @return string
412
	 */
413
	public function getApplicantFirstName() {
414
		return $this->applicantFirstName;
415
	}
416
417
	/**
418
	 * @param string $applicantLastName
419
	 *
420
	 * @return DoctrineMembershipApplication
421
	 */
422
	public function setApplicantLastName( $applicantLastName ) {
423
		$this->applicantLastName = $applicantLastName;
424
		$this->setNameFromParts( $this->getApplicantFirstName(), $applicantLastName );
425
426
		return $this;
427
	}
428
429
	/**
430
	 * @return string
431
	 */
432
	public function getApplicantLastName() {
433
		return $this->applicantLastName;
434
	}
435
436
	/**
437
	 * Sets the full name
438
	 *
439
	 * @param string|null $firstName
440
	 * @param string|null $lastName
441
	 *
442
	 * @return DoctrineMembershipApplication
443
	 */
444
	private function setNameFromParts( $firstName, $lastName ) {
445
		$this->setProbablyUnusedNameField( implode(
446
			' ',
447
			array_filter( [ $firstName, $lastName ] )
448
		) );
449
450
		return $this;
451
	}
452
453
	/**
454
	 * Set address (street, etc)
455
	 *
456
	 * @param string|null $address
457
	 *
458
	 * @return DoctrineMembershipApplication
459
	 */
460
	public function setAddress( $address ) {
461
		$this->address = $address;
462
463
		return $this;
464
	}
465
466
	/**
467
	 * Get address (street, etc)
468
	 *
469
	 * @return string|null
470
	 */
471
	public function getAddress() {
472
		return $this->address;
473
	}
474
475
	/**
476
	 * @param string|null $postcode
477
	 *
478
	 * @return DoctrineMembershipApplication
479
	 */
480
	public function setPostcode( $postcode ) {
481
		$this->postcode = $postcode;
482
483
		return $this;
484
	}
485
486
	/**
487
	 * @return string|null
488
	 */
489
	public function getPostcode() {
490
		return $this->postcode;
491
	}
492
493
	/**
494
	 * @param string|null $city
495
	 *
496
	 * @return DoctrineMembershipApplication
497
	 */
498
	public function setCity( $city ) {
499
		$this->city = $city;
500
501
		return $this;
502
	}
503
504
	/**
505
	 * @return string|null
506
	 */
507
	public function getCity() {
508
		return $this->city;
509
	}
510
511
	/**
512
	 * Set email
513
	 *
514
	 * @param string $applicantEmailAddress
515
	 *
516
	 * @return DoctrineMembershipApplication
517
	 */
518
	public function setApplicantEmailAddress( $applicantEmailAddress ) {
519
		$this->applicantEmailAddress = $applicantEmailAddress;
520
521
		return $this;
522
	}
523
524
	/**
525
	 * Get email
526
	 *
527
	 * @return string
528
	 */
529
	public function getApplicantEmailAddress() {
530
		return $this->applicantEmailAddress;
531
	}
532
533
	/**
534
	 * Set phone
535
	 *
536
	 * @param string $applicantPhoneNumber
537
	 *
538
	 * @return DoctrineMembershipApplication
539
	 */
540
	public function setApplicantPhoneNumber( $applicantPhoneNumber ) {
541
		$this->applicantPhoneNumber = $applicantPhoneNumber;
542
543
		return $this;
544
	}
545
546
	/**
547
	 * Get phone
548
	 *
549
	 * @return string
550
	 */
551
	public function getApplicantPhoneNumber() {
552
		return $this->applicantPhoneNumber;
553
	}
554
555
	/**
556
	 * @param \DateTime|null $dateOfBirth
557
	 *
558
	 * @return DoctrineMembershipApplication
559
	 */
560
	public function setApplicantDateOfBirth( $dateOfBirth ) {
561
		$this->applicantDateOfBirth = $dateOfBirth;
562
563
		return $this;
564
	}
565
566
	/**
567
	 * @return \DateTime|null
568
	 */
569
	public function getApplicantDateOfBirth() {
570
		return $this->applicantDateOfBirth;
571
	}
572
573
	/**
574
	 * @param string $wikimediumShipping
575
	 *
576
	 * @return DoctrineMembershipApplication
577
	 */
578
	public function setWikimediumShipping( $wikimediumShipping ) {
579
		$this->wikimediumShipping = $wikimediumShipping;
580
581
		return $this;
582
	}
583
584
	/**
585
	 * @return string
586
	 */
587
	public function getWikimediumShipping() {
588
		return $this->wikimediumShipping;
589
	}
590
591
	/**
592
	 * @param string $membershipType
593
	 *
594
	 * @return DoctrineMembershipApplication
595
	 */
596
	public function setMembershipType( $membershipType ) {
597
		$this->membershipType = $membershipType;
598
599
		return $this;
600
	}
601
602
	/**
603
	 * @return string
604
	 */
605
	public function getMembershipType() {
606
		return $this->membershipType;
607
	}
608
609
	/**
610
	 * @since 2.1
611
	 *
612
	 * @param string $paymentType
613
	 *
614
	 * @return DoctrineMembershipApplication
615
	 */
616
	public function setPaymentType( $paymentType ) {
617
		$this->paymentType = $paymentType;
618
619
		return $this;
620
	}
621
622
	/**
623
	 * @since 2.1
624
	 *
625
	 * @return string
626
	 */
627
	public function getPaymentType() {
628
		return $this->paymentType;
629
	}
630
631
	/**
632
	 * @param integer $paymentAmountInEuro
633
	 *
634
	 * @return DoctrineMembershipApplication
635
	 */
636
	public function setPaymentAmount( $paymentAmountInEuro ) {
637
		$this->paymentAmountInEuro = $paymentAmountInEuro;
638
639
		return $this;
640
	}
641
642
	/**
643
	 * @return integer
644
	 */
645
	public function getPaymentAmount() {
646
		return $this->paymentAmountInEuro;
647
	}
648
649
	/**
650
	 * @param integer $paymentIntervalInMonths
651
	 *
652
	 * @return DoctrineMembershipApplication
653
	 */
654
	public function setPaymentIntervalInMonths($paymentIntervalInMonths) {
655
		$this->paymentIntervalInMonths = $paymentIntervalInMonths;
656
657
		return $this;
658
	}
659
660
	/**
661
	 * @return integer
662
	 */
663
	public function getPaymentIntervalInMonths() {
664
		return $this->paymentIntervalInMonths;
665
	}
666
667
668
	/**
669
	 * @param string $paymentBankAccount
670
	 *
671
	 * @return DoctrineMembershipApplication
672
	 */
673
	public function setPaymentBankAccount( $paymentBankAccount ) {
674
		$this->paymentBankAccount = $paymentBankAccount;
675
676
		return $this;
677
	}
678
679
	/**
680
	 * @return string
681
	 */
682
	public function getPaymentBankAccount() {
683
		return $this->paymentBankAccount;
684
	}
685
686
	/**
687
	 * @param string $paymentBankName
688
	 *
689
	 * @return DoctrineMembershipApplication
690
	 */
691
	public function setPaymentBankName( $paymentBankName ) {
692
		$this->paymentBankName = $paymentBankName;
693
694
		return $this;
695
	}
696
697
	/**
698
	 * @return string
699
	 */
700
	public function getPaymentBankName() {
701
		return $this->paymentBankName;
702
	}
703
704
	/**
705
	 * @param string $paymentBankCode
706
	 *
707
	 * @return DoctrineMembershipApplication
708
	 */
709
	public function setPaymentBankCode( $paymentBankCode ) {
710
		$this->paymentBankCode = $paymentBankCode;
711
712
		return $this;
713
	}
714
715
	/**
716
	 * @return string
717
	 */
718
	public function getPaymentBankCode() {
719
		return $this->paymentBankCode;
720
	}
721
722
	/**
723
	 * @param string|null $paymentIban
724
	 *
725
	 * @return DoctrineMembershipApplication
726
	 */
727
	public function setPaymentIban( $paymentIban ) {
728
		$this->paymentIban = $paymentIban;
729
730
		return $this;
731
	}
732
733
	/**
734
	 * @return string|null
735
	 */
736
	public function getPaymentIban() {
737
		return $this->paymentIban;
738
	}
739
740
	/**
741
	 * @param string|null $paymentBic
742
	 *
743
	 * @return DoctrineMembershipApplication
744
	 */
745
	public function setPaymentBic( $paymentBic ) {
746
		$this->paymentBic = $paymentBic;
747
748
		return $this;
749
	}
750
751
	/**
752
	 * @return string|null
753
	 */
754
	public function getPaymentBic() {
755
		return $this->paymentBic;
756
	}
757
758
	/**
759
	 * @param string $paymentBankAccountHolder
760
	 *
761
	 * @return DoctrineMembershipApplication
762
	 */
763
	public function setPaymentBankAccountHolder( $paymentBankAccountHolder ) {
764
		$this->paymentBankAccountHolder = $paymentBankAccountHolder;
765
766
		return $this;
767
	}
768
769
	/**
770
	 * @return string
771
	 */
772
	public function getPaymentBankAccountHolder() {
773
		return $this->paymentBankAccountHolder;
774
	}
775
776
	/**
777
	 * @param string $comment
778
	 *
779
	 * @return DoctrineMembershipApplication
780
	 */
781
	public function setComment( $comment ) {
782
		$this->comment = $comment;
783
784
		return $this;
785
	}
786
787
	/**
788
	 * @return string
789
	 */
790
	public function getComment() {
791
		return $this->comment;
792
	}
793
794
	/**
795
	 * Sets the time of export.
796
	 *
797
	 * @param \DateTime|null $export
798
	 *
799
	 * @return DoctrineMembershipApplication
800
	 */
801
	public function setExport( $export ) {
802
		$this->export = $export;
803
804
		return $this;
805
	}
806
807
	/**
808
	 * Returns the time of export.
809
	 *
810
	 * @return \DateTime|null
811
	 */
812
	public function getExport() {
813
		return $this->export;
814
	}
815
816
	/**
817
	 * Sets the time of backup.
818
	 *
819
	 * @param \DateTime|null $backup
820
	 *
821
	 * @return DoctrineMembershipApplication
822
	 */
823
	public function setBackup( $backup ) {
824
		$this->backup = $backup;
825
826
		return $this;
827
	}
828
829
	/**
830
	 * Returns the time of backup.
831
	 *
832
	 * @return \DateTime|null
833
	 */
834
	public function getBackup() {
835
		return $this->backup;
836
	}
837
838
	/**
839
	 * @param boolean $wikilogin
840
	 *
841
	 * @return DoctrineMembershipApplication
842
	 */
843
	public function setWikilogin( $wikilogin ) {
844
		$this->wikilogin = $wikilogin;
845
846
		return $this;
847
	}
848
849
	/**
850
	 * @return boolean
851
	 */
852
	public function getWikilogin() {
853
		return $this->wikilogin;
854
	}
855
856
	/**
857
	 * @param string|null $tracking
858
	 *
859
	 * @return DoctrineMembershipApplication
860
	 */
861
	public function setTracking( $tracking ) {
862
		$this->tracking = $tracking;
863
864
		return $this;
865
	}
866
867
	/**
868
	 * @return string|null
869
	 */
870
	public function getTracking() {
871
		return $this->tracking;
872
	}
873
874
	/**
875
	 * Sets the status of the membership request.
876
	 * The allowed values are the STATUS_ constants in this class.
877
	 *
878
	 * @param integer $status
879
	 *
880
	 * @return DoctrineMembershipApplication
881
	 */
882
	public function setStatus( $status ) {
883
		$this->status = $status;
884
885
		return $this;
886
	}
887
888
	/**
889
	 * Returns the status of the membership request.
890
	 * The possible values are the STATUS_ constants in this class.
891
	 *
892
	 * @return integer
893
	 */
894
	public function getStatus() {
895
		return $this->status;
896
	}
897
898
	/**
899
	 * @param string|null $country
900
	 *
901
	 * @return DoctrineMembershipApplication
902
	 */
903
	public function setCountry( $country ) {
904
		$this->country = $country;
905
906
		return $this;
907
	}
908
909
	/**
910
	 * @return string|null
911
	 */
912
	public function getCountry() {
913
		return $this->country;
914
	}
915
916
	/**
917
	 * @param string|null $data
918
	 *
919
*@return DoctrineMembershipApplication
920
	 */
921
	public function setData( $data ) {
922
		$this->data = $data;
923
924
		return $this;
925
	}
926
927
	/**
928
	 * @return string|null
929
	 */
930
	public function getData() {
931
		return $this->data;
932
	}
933
934
	/**
935
	 * @return bool
936
	 */
937
	public function isUnconfirmed() {
938
		return $this->status === self::STATUS_NEUTRAL;
939
	}
940
941
	/**
942
	 * @return bool
943
	 */
944
	public function needsModeration() {
945
		return $this->status < 0 && abs( $this->status ) & abs( self::STATUS_MODERATION );
946
	}
947
948
	/**
949
	 * @return bool
950
	 */
951
	public function isCancelled() {
952
		return $this->status < 0 && abs( $this->status ) & abs( self::STATUS_CANCELED );
953
	}
954
955
	public function log( $message ) {
956
		$dataArray = $this->getDecodedData();
957
		$dataArray[ "log" ][ date( "Y-m-d H:i:s" ) ] = $message;
958
		$this->encodeAndSetData( $dataArray );
959
960
		return $this;
961
	}
962
963
	/**
964
	 * NOTE: if possible, use @see getDataObject instead, as it provides a nicer API.
965
	 *
966
	 * @since 2.0
967
	 * @return array
968
	 */
969
	public function getDecodedData() {
970
		$data = unserialize( base64_decode( $this->data ) );
971
972
		return is_array( $data ) ? $data : [];
973
	}
974
975
	/**
976
	 * NOTE: if possible, use @see modifyDataObject instead, as it provides a nicer API.
977
	 *
978
	 * @since 2.0
979
	 * @param array $data
0 ignored issues
show
Bug introduced by
There is no parameter named $data. 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...
980
	 */
981
	public function encodeAndSetData( array $dataArray ) {
982
		$this->data = base64_encode( serialize( $dataArray ) );
983
	}
984
985
	/**
986
	 * WARNING: updates made to the return value will not be reflected in the Donation state.
987
	 * Similarly, updates to the Donation state will not propagate to the returned object.
988
	 * To update the Donation state, explicitly call @see setDataObject.
989
	 *
990
	 * @since 2.0
991
	 * @return MembershipApplicationData
992
	 */
993
	public function getDataObject() {
994
		$dataArray = $this->getDecodedData();
995
996
		$data = new MembershipApplicationData();
997
998
		$data->setAccessToken( array_key_exists( 'token', $dataArray ) ? $dataArray['token'] : null );
999
		$data->setUpdateToken( array_key_exists( 'utoken', $dataArray ) ? $dataArray['utoken'] : null );
1000
		$data->setPreservedStatus( array_key_exists( 'old_status', $dataArray ) ? $dataArray['old_status'] : null );
1001
1002
		return $data;
1003
	}
1004
1005
	/**
1006
	 * @since 2.0
1007
	 * @param MembershipApplicationData $data
1008
	 */
1009
	public function setDataObject( MembershipApplicationData $data ) {
1010
		$dataArray = array_merge(
1011
			$this->getDecodedData(),
1012
			[
1013
				'token' => $data->getAccessToken(),
1014
				'utoken' => $data->getUpdateToken(),
1015
				'old_status' => $data->getPreservedStatus(),
1016
			]
1017
		);
1018
1019
		foreach ( [ 'token', 'utoken', 'old_status' ] as $keyName ) {
1020
			if ( is_null( $dataArray[$keyName] ) ) {
1021
				unset( $dataArray[$keyName] );
1022
			}
1023
		}
1024
1025
		$this->encodeAndSetData( $dataArray );
1026
	}
1027
1028
	/**
1029
	 * @since 2.0
1030
	 * @param callable $modificationFunction Takes a modifiable MembershipApplicationData parameter
1031
	 */
1032
	public function modifyDataObject( callable $modificationFunction ) {
1033
		$dataObject = $this->getDataObject();
1034
		$modificationFunction( $dataObject );
1035
		$this->setDataObject( $dataObject );
1036
	}
1037
1038
}
1039