Passed
Push — master ( 4776d4...1205d2 )
by Gabriel
41s queued 11s
created

FreezableValueObject::freeze()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
crap 1
1
<?php
2
3
declare( strict_types = 1 );
4
5
namespace WMDE\FreezableValueObject;
6
7
/**
8
 * @license GPL-2.0-or-later
9
 * @author Jeroen De Dauw < [email protected] >
10
 */
11
trait FreezableValueObject {
12
13
	private bool $isFrozen = false;
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected T_STRING, expecting T_FUNCTION or T_CONST
Loading history...
14
15 4
	public function freeze(): self {
16 4
		$this->isFrozen = true;
17 4
		return $this;
18
	}
19
20 5
	protected function assertIsWritable(): self {
21 5
		if ( $this->isFrozen ) {
22 2
			throw new \RuntimeException( 'Cannot write to a frozen object!' );
23
		}
24 4
		return $this;
25
	}
26
27 2
	public function assertNoNullFields(): self {
28 2
		foreach ( get_object_vars( $this ) as $fieldName => $fieldValue ) {
29 2
			if ( $fieldValue === null ) {
30 1
				throw new \RuntimeException( "Field '$fieldName' cannot be null" );
31
			}
32
		}
33 1
		return $this;
34
	}
35
36
}
37