Completed
Pull Request — master (#10)
by Gabriel
60:20
created

AddressChangeId::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 5
rs 10
1
<?php
2
3
declare( strict_types = 1 );
4
5
namespace WMDE\Fundraising\AddressChangeContext\Domain\Model;
6
7
class AddressChangeId {
8
9
	private const VALID_PATTERN = '^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$';
10
11
	private string $identifier;
12
13
	private function __construct( string $id ) {
14
		if ( !preg_match( '/' . self::VALID_PATTERN . '/D', $id ) ) {
15
			throw new \InvalidArgumentException( 'Identifier must be a valid UUID ' );
16
		}
17
		$this->identifier = $id;
18
	}
19
20
	public static function fromString( string $id ): self {
21
		return new self( $id );
22
	}
23
24
	public function __toString(): string {
25
		return $this->identifier;
26
	}
27
28
}