Passed
Push — master ( 249034...333e31 )
by Tim
01:20
created

AddressChange::setThirdPartyIdentifier()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 0
cts 3
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
declare( strict_types = 1 );
4
5
namespace WMDE\Fundraising\Entities;
6
7
use Doctrine\ORM\Mapping as ORM;
8
use Ramsey\Uuid\Uuid;
9
10
/**
11
 * @since 8.0
12
 *
13
 * @ORM\Table( name="address_change" )
14
 * @ORM\Entity
15
 */
16
class AddressChange {
17
18
	public const ADDRESS_TYPE_PERSON = 'person';
19
20
	public const ADDRESS_TYPE_COMPANY = 'company';
21
22
	/**
23
	 * @var integer
24
	 *
25
	 * @ORM\Column(name="id", type="integer")
26
	 * @ORM\Id
27
	 * @ORM\GeneratedValue(strategy="IDENTITY")
28
	 */
29
	private $id;
30
31
	/**
32
	 * @ORM\ManyToOne(targetEntity="Address")
33
	 * @ORM\JoinColumn(name="address_id", referencedColumnName="id")
34
	 */
35
	private $address;
36
37
	/**
38
	 * @var string
39
	 *
40
	 * @ORM\Column(name="current_identifier", type="string", length=36, nullable=true, unique=true)
41
	 */
42
	private $identifier;
43
44
	/**
45
	 * @var string
46
	 *
47
	 * @ORM\Column(name="previous_identifier", type="string", length=36, nullable=true, unique=true)
48
	 */
49
	private $previousIdentifier;
50
51
	/**
52
	 * @var string
53
	 *
54
	 * @ORM\Column(name="address_type", type="string", length = 10)
55
	 */
56
	private $addressType;
57
58 6
	public function __construct( string $addressType ) {
59 6
		$this->addressType = $addressType;
60 6
		if ($this->identifier === null) {
61 6
			$this->generateUuid();
62
		}
63 6
	}
64
65 6
	private function generateUuid(): void {
66 6
		$this->identifier = Uuid::uuid4()->toString();
67 6
	}
68
69 3
	public function updateAddressIdentifier(): void {
70 3
		$this->previousIdentifier = $this->getCurrentIdentifier();
71 3
		$this->generateUuid();
72 3
	}
73
74 6
	public function getCurrentIdentifier(): string {
75 6
		if ($this->identifier === null) {
76
			$this->generateUuid();
77
		}
78 6
		return $this->identifier;
79
	}
80
81 3
	public function getPreviousIdentifier(): ?string {
82 3
		return $this->previousIdentifier;
83
	}
84
85
	public function getAddress(): Address {
86
		return $this->address;
87
	}
88
89
	public function setAddress( Address $address ) {
90
		$this->address = $address;
91
	}
92
93
	public function getAddressType(): string {
94
		return $this->addressType;
95
	}
96
}
97