@@ -67,13 +67,26 @@ public function setData($data = [])
67
67
$ this ->data = json_encode ($ data , $ this ->encodingOptions );
68
68
}
69
69
70
- if ($ this ->hasJsonError (json_last_error ())) {
70
+ if (! $ this ->hasValidJson (json_last_error ())) {
71
71
throw new InvalidArgumentException (json_last_error_msg ());
72
72
}
73
73
74
74
return $ this ->update ();
75
75
}
76
76
77
+ /**
78
+ * Determine if an error occured during JSON encoding.
79
+ *
80
+ * @param int $jsonError
81
+ * @return bool
82
+ */
83
+ protected function hasValidJson ($ jsonError )
84
+ {
85
+ return $ jsonError === JSON_ERROR_NONE ||
86
+ ($ jsonError === JSON_ERROR_UNSUPPORTED_TYPE &&
87
+ $ this ->hasEncodingOption (JSON_PARTIAL_OUTPUT_ON_ERROR ));
88
+ }
89
+
77
90
/**
78
91
* {@inheritdoc}
79
92
*/
@@ -85,26 +98,13 @@ public function setEncodingOptions($options)
85
98
}
86
99
87
100
/**
88
- * Checks the JSON encoding option is set.
101
+ * Determine if a JSON encoding option is set.
89
102
*
90
103
* @param int $option
91
104
* @return bool
92
105
*/
93
- public function isEncodingOptionSet ($ option )
106
+ public function hasEncodingOption ($ option )
94
107
{
95
108
return (bool ) ($ this ->encodingOptions & $ option );
96
109
}
97
-
98
- /**
99
- * Checks if error happened during json_encode.
100
- *
101
- * @param int $jsonError
102
- * @return bool
103
- */
104
- protected function hasJsonError ($ jsonError )
105
- {
106
- return $ jsonError !== JSON_ERROR_NONE &&
107
- ($ jsonError !== JSON_ERROR_UNSUPPORTED_TYPE ||
108
- ! $ this ->isEncodingOptionSet (JSON_PARTIAL_OUTPUT_ON_ERROR ));
109
- }
110
110
}
0 commit comments