code style

This commit is contained in:
El RIDO 2022-10-23 08:16:05 +02:00
parent 0dc9ab7576
commit 0a2094f069
No known key found for this signature in database
GPG Key ID: 0F5C940A6BD81F92
1 changed files with 35 additions and 33 deletions

View File

@ -48,7 +48,11 @@ class YourlsProxy
*/ */
public function __construct(Configuration $conf, $link) public function __construct(Configuration $conf, $link)
{ {
if (strpos($link, $conf->getKey('basepath') . '/?') !== false) { if (strpos($link, $conf->getKey('basepath') . '/?') === false) {
$this->_error = 'Trying to shorten a URL not pointing to our PrivateBin instance.';
return;
}
// Init the CURL session // Init the CURL session
$ch = curl_init(); $ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $conf->getKey("apiurl", "yourls")); curl_setopt($ch, CURLOPT_URL, $conf->getKey("apiurl", "yourls"));
@ -65,24 +69,22 @@ class YourlsProxy
$data = curl_exec($ch); $data = curl_exec($ch);
curl_close($ch); curl_close($ch);
if (!($data === FALSE) && is_string($data)) if ($data === false || !is_string($data)) {
{ $this->_error = 'Error calling YOURLS. Probably a configuration issue, like wrong or missing "apiurl" or "signature".';
$data = json_decode( $data, true); return;
}
if (!is_null($data) && array_key_exists('statusCode', $data) $data = json_decode($data, true);
&& array_key_exists('shorturl', $data) && ($data['statusCode'] == 200)) if (
{ !is_null($data) &&
array_key_exists('statusCode', $data) &&
array_key_exists('shorturl', $data) &&
$data['statusCode'] == 200
) {
$this->_url = $data['shorturl']; $this->_url = $data['shorturl'];
$opSuccess = TRUE;
} else { } else {
$this->_error = 'Error parsing YOURLS response.'; $this->_error = 'Error parsing YOURLS response.';
} }
} else {
$this->_error = 'Error calling YOURLS. Probably a configuration issue, like wrong or missing "apiurl" or "signature".';
}
} else {
$this->_error = 'Trying to shorten a URL not pointing to our PrivateBin instance.';
}
} }
/** /**