-
Add input validation at the top of the method. Check each constrained param against its $this->valid* list using in_array(). Return early on failure:
if (!in_array($product, $this->validProducts)) {
return ['error' => 'Invalid Product'];
}
Verify: every constrained param has a guard before any $this->params[...] assignment.
-
Set params and call $this->req($action). Return its result directly — do not wrap it:
$this->params['order_product'] = $product;
return $this->req('Order');
Verify: resetParams() is called in __construct(), not at the start of each method.
-
Inside req(): handle cURL failure. curl_exec() returns false on network error. Append to $this->error[] and return false:
$this->rawResponse = curl_exec($ch);
if (!$this->rawResponse) {
$error = 'There was some error in connecting to LiteSpeed. ...';
$this->error[] = $error;
return false;
}
Verify: $this->error[] uses [] append syntax, not = assignment.
-
Inside req(): handle API-level errors from XML response. After xml2array(), check $this->response['error']. On error, merge into $this->error[] and return false; on success, return $this->response:
$this->response = xml2array($this->rawResponse);
if (empty($this->response['error'])) {
unset($this->response['error']);
return $this->response;
} else {
$this->error = array_merge($this->error, $this->response['error']);
return false;
}
Verify: success path calls unset($this->response['error']) before returning.
-
Log before and after the request using myadmin_log():
myadmin_log('licenses', 'info', "LiteSpeed URL: $url\npstring: $pstring\n", __LINE__, __FILE__);
myadmin_log('licenses', 'info', 'LiteSpeed Response '.var_export($this->response, true), __LINE__, __FILE__);
-
Callers must check the return value before using it:
$result = $ls->order('LSWS', '1', 'monthly', 'credit');
if ($result === false) {
} elseif (isset($result['error'])) {
} else {
}