Passed
Push — main ( b7b8b7...5de84d )
by Gabriel
51s queued 15s
created

AddressChangeId   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 9
c 1
b 0
f 0
dl 0
loc 23
rs 10
ccs 10
cts 10
cp 1

4 Methods

Rating   Name   Duplication   Size   Complexity  
A fromString() 0 2 1
A __toString() 0 2 1
A __construct() 0 5 2
A equals() 0 2 2
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 8
	private function __construct( string $id ) {
14 8
		if ( !preg_match( '/' . self::VALID_PATTERN . '/D', $id ) ) {
15 5
			throw new \InvalidArgumentException( 'Identifier must be a valid UUID ' );
16
		}
17 3
		$this->identifier = $id;
18
	}
19
20 8
	public static function fromString( string $id ): self {
21 8
		return new self( $id );
22
	}
23
24 1
	public function __toString(): string {
25 1
		return $this->identifier;
26
	}
27
28 2
	public function equals( string|AddressChangeId $id ): bool {
29 2
		return is_string( $id ) ? $this->identifier === $id : $this->identifier === $id->identifier;
30
	}
31
32
}
33