Skip to content

Request::sendRequest mixed return type errors. #30

@devutixo

Description

@devutixo

The function returns a mix of stdClass and arrays for errors.

private function sendRequest($functionName,$ascioParams) {
if(isset($ascioParams["order"])) {
$orderType = " ".$ascioParams["order"]["Type"] ."";
} else $orderType ="";
$wsdl = $this->params["TestMode"]=="on" ? ASCIO_WSDL_TEST : ASCIO_WSDL_LIVE;
$client = new SoapClient($wsdl,array( "cache_wsdl " => WSDL_CACHE_MEMORY ));
$result = $client->__call($functionName, array('parameters' => $ascioParams));
$resultName = $functionName . "Result";
$status = $result->$resultName;
$result->status = $status;
$ot = $orderType ? " [".$orderType."] " : "";
$parameterCapture = new ParameterCapture($this->params,$functionName,$orderType);
$parameterCapture->capture();
Tools::logModule($functionName,$ascioParams,$result);
if ( $status->ResultCode == 200 ||$status->ResultCode == 201 || $status->ResultCode == 413 ) {
return $result;
} else if( $status->ResultCode==554) {
$messages = "Temporary error. Please try later or contact your support.";
} elseif ($status->ResultCode==401 && $functionName != "LogIn" ) {
SessionCache::clear($this->account);
$this->login();
return $this->request($functionName, $ascioParams);
} elseif ($status->ResultCode==401) {
logActivity("Ascio registrar plugin settings - Login failed, invalid account or password: ".$this->account);
die("Ascio registrar plugin settings - Login failed, invalid account or password: ".$this->account);
return array('error' => $status->Message );
} else if (is_array($status->Values->string) && count($status->Values->string) > 1 ){
$messages = join(", \r\n",$status->Values->string);
} else {
$messages = $status->Values->string;
}
$message = Tools::cleanString($messages);
return array('error' => $message );
}

When e.g. updating contact details, the Request::updateContacts function checks for errors in the return values and triggers the exception:
Cannot use object of type stdClass as array in [...]/modules/registrars/ascio/lib/Request.php:629

if(! ($contactResult["error"] || $registrantResult["error"])) {
return ["success" => true];
}

There may be more lines in the module that make similar checks for an "error" array key on what could potentially be an stdClass object.

The code would need refactoring for compatibility with newer PHP versions, ideally making use of type declarations available since PHP7.0.
The module is declared as supporting PHP5.3+, is it maybe time to drop support for PHP5 and raise the minimum version to at least 7.1? Maintaining such wide ranging support from 5.3 to 8.4 is realistically hardly achievable.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions