for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare( strict_types = 1 );
namespace WMDE\FreezableValueObject;
/**
* @license GPL-2.0-or-later
* @author Jeroen De Dauw < [email protected] >
*/
trait FreezableValueObject {
private bool $isFrozen = false;
public function freeze(): self {
$this->isFrozen = true;
return $this;
}
protected function assertIsWritable(): self {
if ( $this->isFrozen ) {
throw new \RuntimeException( 'Cannot write to a frozen object!' );
public function assertNoNullFields(): self {
foreach ( get_object_vars( $this ) as $fieldName => $fieldValue ) {
if ( $fieldValue === null ) {
throw new \RuntimeException( "Field '$fieldName' cannot be null" );