[Translation] fixed CS
This commit is contained in:
parent
9988475881
commit
c5a65780db
@ -37,12 +37,11 @@ class JsonFileLoader extends ArrayLoader implements LoaderInterface
|
|||||||
|
|
||||||
$messages = json_decode(file_get_contents($resource), true);
|
$messages = json_decode(file_get_contents($resource), true);
|
||||||
|
|
||||||
if (($errorCode = json_last_error()) > 0) {
|
if (0 < $errorCode = json_last_error()) {
|
||||||
$message = $this->getJSONErrorMessage($errorCode);
|
throw new InvalidResourceException(sprintf('Error parsing JSON - %s', $this->getJSONErrorMessage($errorCode)));
|
||||||
throw new InvalidResourceException(sprintf('Error parsing JSON - %s', $message));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($messages === null) {
|
if (null === $messages) {
|
||||||
$messages = array();
|
$messages = array();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,35 +52,27 @@ class JsonFileLoader extends ArrayLoader implements LoaderInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Translates JSON_ERROR_* constant into meaningful message
|
* Translates JSON_ERROR_* constant into meaningful message.
|
||||||
*
|
*
|
||||||
* @param integer $errorCode Error code returned by json_last_error() call
|
* @param integer $errorCode Error code returned by json_last_error() call
|
||||||
|
*
|
||||||
* @return string Message string
|
* @return string Message string
|
||||||
*/
|
*/
|
||||||
private function getJSONErrorMessage($errorCode)
|
private function getJSONErrorMessage($errorCode)
|
||||||
{
|
{
|
||||||
$errorMsg = null;
|
|
||||||
switch ($errorCode) {
|
switch ($errorCode) {
|
||||||
case JSON_ERROR_DEPTH:
|
case JSON_ERROR_DEPTH:
|
||||||
$errorMsg = 'Maximum stack depth exceeded';
|
return 'Maximum stack depth exceeded';
|
||||||
break;
|
|
||||||
case JSON_ERROR_STATE_MISMATCH:
|
case JSON_ERROR_STATE_MISMATCH:
|
||||||
$errorMsg = 'Underflow or the modes mismatch';
|
return 'Underflow or the modes mismatch';
|
||||||
break;
|
|
||||||
case JSON_ERROR_CTRL_CHAR:
|
case JSON_ERROR_CTRL_CHAR:
|
||||||
$errorMsg = 'Unexpected control character found';
|
return 'Unexpected control character found';
|
||||||
break;
|
|
||||||
case JSON_ERROR_SYNTAX:
|
case JSON_ERROR_SYNTAX:
|
||||||
$errorMsg = 'Syntax error, malformed JSON';
|
return 'Syntax error, malformed JSON';
|
||||||
break;
|
|
||||||
case JSON_ERROR_UTF8:
|
case JSON_ERROR_UTF8:
|
||||||
$errorMsg = 'Malformed UTF-8 characters, possibly incorrectly encoded';
|
return 'Malformed UTF-8 characters, possibly incorrectly encoded';
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
$errorMsg = 'Unknown error';
|
return 'Unknown error';
|
||||||
break;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return $errorMsg;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user