@@ -37,12 +37,11 @@ public function load($resource, $locale, $domain = 'messages')
37
37
38
38
$ messages = json_decode (file_get_contents ($ resource ), true );
39
39
40
- if (($ errorCode = json_last_error ()) > 0 ) {
41
- $ message = $ this ->getJSONErrorMessage ($ errorCode );
42
- throw new InvalidResourceException (sprintf ('Error parsing JSON - %s ' , $ message ));
40
+ if (0 < $ errorCode = json_last_error ()) {
41
+ throw new InvalidResourceException (sprintf ('Error parsing JSON - %s ' , $ this ->getJSONErrorMessage ($ errorCode )));
43
42
}
44
43
45
- if ($ messages === null ) {
44
+ if (null === $ messages ) {
46
45
$ messages = array ();
47
46
}
48
47
@@ -53,35 +52,27 @@ public function load($resource, $locale, $domain = 'messages')
53
52
}
54
53
55
54
/**
56
- * Translates JSON_ERROR_* constant into meaningful message
55
+ * Translates JSON_ERROR_* constant into meaningful message.
57
56
*
58
57
* @param integer $errorCode Error code returned by json_last_error() call
58
+ *
59
59
* @return string Message string
60
60
*/
61
61
private function getJSONErrorMessage ($ errorCode )
62
62
{
63
- $ errorMsg = null ;
64
63
switch ($ errorCode ) {
65
64
case JSON_ERROR_DEPTH :
66
- $ errorMsg = 'Maximum stack depth exceeded ' ;
67
- break ;
65
+ return 'Maximum stack depth exceeded ' ;
68
66
case JSON_ERROR_STATE_MISMATCH :
69
- $ errorMsg = 'Underflow or the modes mismatch ' ;
70
- break ;
67
+ return 'Underflow or the modes mismatch ' ;
71
68
case JSON_ERROR_CTRL_CHAR :
72
- $ errorMsg = 'Unexpected control character found ' ;
73
- break ;
69
+ return 'Unexpected control character found ' ;
74
70
case JSON_ERROR_SYNTAX :
75
- $ errorMsg = 'Syntax error, malformed JSON ' ;
76
- break ;
71
+ return 'Syntax error, malformed JSON ' ;
77
72
case JSON_ERROR_UTF8 :
78
- $ errorMsg = 'Malformed UTF-8 characters, possibly incorrectly encoded ' ;
79
- break ;
73
+ return 'Malformed UTF-8 characters, possibly incorrectly encoded ' ;
80
74
default :
81
- $ errorMsg = 'Unknown error ' ;
82
- break ;
75
+ return 'Unknown error ' ;
83
76
}
84
-
85
- return $ errorMsg ;
86
77
}
87
78
}
0 commit comments