is_valid = $is_valid; $this->error_message = $error_message; $this->phone_number = $phone_number; $this->error_code = $error_code; } /** * Create a successful validation result. * * @param PhoneNumber $phone_number The parsed phone number. * @return self */ public static function success( PhoneNumber $phone_number ): self { return new self( true, null, $phone_number ); } /** * Create a failed validation result. * * @param string $error_code One of the ERROR_* constants. * @param string $error_message The (translated) error message. * @return self */ public static function failure( string $error_code, string $error_message ): self { return new self( false, $error_message, null, $error_code ); } /** * Check if the validation was successful. * * @return bool */ public function is_valid(): bool { return $this->is_valid; } /** * Get the machine-readable error code. * * @return string|null */ public function get_error_code(): ?string { return $this->error_code; } /** * Get the error message. * * @return string|null */ public function get_error_message(): ?string { return $this->error_message; } /** * Get the parsed phone number. * * @return PhoneNumber|null */ public function get_phone_number(): ?PhoneNumber { return $this->phone_number; } }