for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Wambo\Core\Immutable;
use Wambo\Core\Immutable\Exception\ImmutableException;
trait ImmutableTrait
{
/** @var bool $constructed */
private $constructed = false;
/**
* ImmutableTrait constructor.
*
* @throws ImmutableException
*/
public function setConstructed()
if ($this->constructed === true) {
throw new ImmutableException('Can not recall constructor again because this object is immutable.');
}
$this->constructed = true;
* Disable the magic function to prevent change the immutable object
* @param string $name
* @param string $value
final public function __set($name, $value)
$name
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.
$value
throw new ImmutableException('Can not set any value because this object is immutable.');
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.