Fix not reachable code

This commit is contained in:
Laurent Destailleur 2017-09-04 12:55:32 +02:00
parent ee32cce33a
commit c3daad7545
2 changed files with 48 additions and 23 deletions

View File

@ -48,6 +48,7 @@ class PrestaShopWebservice
const PSCOMPATIBLEVERSIONMIN = '1.4.0.0'; const PSCOMPATIBLEVERSIONMIN = '1.4.0.0';
const PSCOMPATIBLEVERSIONMAX = '1.6.99.99'; const PSCOMPATIBLEVERSIONMAX = '1.6.99.99';
/** /**
* PrestaShopWebservice constructor. Throw an exception when CURL is not installed/activated * PrestaShopWebservice constructor. Throw an exception when CURL is not installed/activated
* <code> * <code>
@ -79,6 +80,7 @@ class PrestaShopWebservice
/** /**
* Take the status code and throw an exception if the server didn't return 200 or 201 code * Take the status code and throw an exception if the server didn't return 200 or 201 code
*
* @param int $status_code Status code of an HTTP return * @param int $status_code Status code of an HTTP return
*/ */
protected function checkStatusCode($status_code) protected function checkStatusCode($status_code)
@ -86,21 +88,32 @@ class PrestaShopWebservice
$error_label = 'This call to PrestaShop Web Services failed and returned an HTTP status of %d. That means: %s.'; $error_label = 'This call to PrestaShop Web Services failed and returned an HTTP status of %d. That means: %s.';
switch($status_code) switch($status_code)
{ {
case 200: case 201: break; case 200:
case 204: throw new PrestaShopWebserviceException(sprintf($error_label, $status_code, 'No content'));break; case 201:
case 400: throw new PrestaShopWebserviceException(sprintf($error_label, $status_code, 'Bad Request'));break; break;
case 401: throw new PrestaShopWebserviceException(sprintf($error_label, $status_code, 'Unauthorized'));break; case 204:
case 404: throw new PrestaShopWebserviceException(sprintf($error_label, $status_code, 'Not Found'));break; throw new PrestaShopWebserviceException(sprintf($error_label, $status_code, 'No content'));
case 405: throw new PrestaShopWebserviceException(sprintf($error_label, $status_code, 'Method Not Allowed'));break; case 400:
case 500: throw new PrestaShopWebserviceException(sprintf($error_label, $status_code, 'Internal Server Error'));break; throw new PrestaShopWebserviceException(sprintf($error_label, $status_code, 'Bad Request'));
default: throw new PrestaShopWebserviceException('This call to PrestaShop Web Services returned an unexpected HTTP status of:' . $status_code); case 401:
throw new PrestaShopWebserviceException(sprintf($error_label, $status_code, 'Unauthorized'));
case 404:
throw new PrestaShopWebserviceException(sprintf($error_label, $status_code, 'Not Found'));
case 405:
throw new PrestaShopWebserviceException(sprintf($error_label, $status_code, 'Method Not Allowed'));
case 500:
throw new PrestaShopWebserviceException(sprintf($error_label, $status_code, 'Internal Server Error'));
default:
throw new PrestaShopWebserviceException('This call to PrestaShop Web Services returned an unexpected HTTP status of:' . $status_code);
} }
} }
/** /**
* Handles a CURL request to PrestaShop Webservice. Can throw exception. * Handles a CURL request to PrestaShop Webservice. Can throw exception.
* @param string $url Resource name *
* @param mixed $curl_params CURL parameters (sent to curl_set_opt) * @param string $url Resource name
* @return array status_code, response * @param mixed $curl_params CURL parameters (sent to curl_set_opt)
* @return array status_code, response
*/ */
public function executeRequest($url, $curl_params = array()) public function executeRequest($url, $curl_params = array())
{ {
@ -178,11 +191,23 @@ class PrestaShopWebservice
return array('status_code' => $status_code, 'response' => $body, 'header' => $header); return array('status_code' => $status_code, 'response' => $body, 'header' => $header);
} }
/**
* Output debug info
*
* @param string $title Title
* @param string $content Content
* @return void
*/
public function printDebug($title, $content) public function printDebug($title, $content)
{ {
echo '<div style="display:table;background:#CCC;font-size:8pt;padding:7px"><h6 style="font-size:9pt;margin:0">'.$title.'</h6><pre>'.htmlentities($content).'</pre></div>'; echo '<div style="display:table;background:#CCC;font-size:8pt;padding:7px"><h6 style="font-size:9pt;margin:0">'.$title.'</h6><pre>'.htmlentities($content).'</pre></div>';
} }
/**
* Return version
*
* @return string Version
*/
public function getVersion() public function getVersion()
{ {
return $this->version; return $this->version;
@ -190,8 +215,9 @@ class PrestaShopWebservice
/** /**
* Load XML from string. Can throw exception * Load XML from string. Can throw exception
* @param string $response String from a CURL response *
* @return SimpleXMLElement status_code, response * @param string $response String from a CURL response
* @return SimpleXMLElement status_code, response
*/ */
protected function parseXML($response) protected function parseXML($response)
{ {
@ -268,8 +294,8 @@ class PrestaShopWebservice
* } * }
* ?> * ?>
* </code> * </code>
* @param array $options Array representing resource to get. * @param array $options Array representing resource to get.
* @return SimpleXMLElement status_code, response * @return SimpleXMLElement status_code, response
*/ */
public function get($options) public function get($options)
{ {
@ -301,8 +327,8 @@ class PrestaShopWebservice
/** /**
* Head method (HEAD) a resource * Head method (HEAD) a resource
* *
* @param array $options Array representing resource for head request. * @param array $options Array representing resource for head request.
* @return SimpleXMLElement status_code, response * @return SimpleXMLElement status_code, response
*/ */
public function head($options) public function head($options)
{ {
@ -336,7 +362,9 @@ class PrestaShopWebservice
* 'id' => ID of a resource you want to edit,<br> * 'id' => ID of a resource you want to edit,<br>
* 'putXml' => Modified XML string of a resource<br><br> * 'putXml' => Modified XML string of a resource<br><br>
* Examples are given in the tutorial</p> * Examples are given in the tutorial</p>
* @param array $options Array representing resource to edit. *
* @param array $options Array representing resource to edit.
* @return SimpleXMLElement status_code, response
*/ */
public function edit($options) public function edit($options)
{ {
@ -381,7 +409,8 @@ class PrestaShopWebservice
* } * }
* ?> * ?>
* </code> * </code>
* @param array $options Array representing resource to delete. * @param array $options Array representing resource to delete.
* @return boolean true
*/ */
public function delete($options) public function delete($options)
{ {
@ -400,8 +429,6 @@ class PrestaShopWebservice
self::checkStatusCode($request['status_code']);// check the response validity self::checkStatusCode($request['status_code']);// check the response validity
return true; return true;
} }
} }
/** /**

View File

@ -1171,8 +1171,6 @@ class ExpenseReport extends CommonObject
$this->error=$this->db->lasterror(); $this->error=$this->db->lasterror();
return -1; return -1;
} }
return 0;
} }
/** /**