ok = $ok; $this->value = $value; $this->error = $error; } /** * @param mixed $value */ public static function ok( $value = null ): self { return new self( true, $value, null ); } public static function err( string $code, string $message = '' ): self { return new self( false, null, new Err( $code, $message ) ); } public function isOk(): bool { return $this->ok; } /** * @return mixed */ public function value() { if ( ! $this->ok ) { throw new \LogicException( 'value() on a failed result' ); } return $this->value; } public function error(): Err { if ( $this->ok || null === $this->error ) { throw new \LogicException( 'error() on a successful result' ); } return $this->error; } }