Summary
ConvertsToJson::toJson() calls json_encode() with no flags, so it can return false on encoding failure despite its declared : string return type. Every other JSON boundary in the codebase throws instead.
Details
src/Support/ConvertsToJson.php:24-27:
public function toJson(): string
{
return json_encode($this);
}
json_encode() returns false on failure (e.g. malformed UTF-8 in a title/body/data field), which violates the declared : string return type. Without strict_types in this file, this doesn't fatal immediately at the call site, but it's a silent false-as-string bug waiting to surface — e.g. under strict_types=1, or in any caller that treats the result as a genuine JSON string (writing it to a file, sending it over HTTP, etc.).
By contrast:
ConvertsFromJson::jsonDecode() (src/Support/ConvertsFromJson.php:28) uses JSON_THROW_ON_ERROR.
SendNotificationsRequest::preventTooMuchMessageData() (src/Request/SendNotificationsRequest.php:164) uses JSON_THROW_ON_ERROR.
toJson() is the odd one out.
Suggested fix
Add the JSON_THROW_ON_ERROR flag to json_encode() in toJson(), matching the rest of the codebase's JSON-boundary handling.
Test gap
No test currently encodes a value that would fail JSON encoding (e.g. invalid UTF-8 in a message field) to confirm a JsonException is thrown rather than a silent false.
Summary
ConvertsToJson::toJson()callsjson_encode()with no flags, so it can returnfalseon encoding failure despite its declared: stringreturn type. Every other JSON boundary in the codebase throws instead.Details
src/Support/ConvertsToJson.php:24-27:json_encode()returnsfalseon failure (e.g. malformed UTF-8 in atitle/body/datafield), which violates the declared: stringreturn type. Withoutstrict_typesin this file, this doesn't fatal immediately at the call site, but it's a silentfalse-as-string bug waiting to surface — e.g. understrict_types=1, or in any caller that treats the result as a genuine JSON string (writing it to a file, sending it over HTTP, etc.).By contrast:
ConvertsFromJson::jsonDecode()(src/Support/ConvertsFromJson.php:28) usesJSON_THROW_ON_ERROR.SendNotificationsRequest::preventTooMuchMessageData()(src/Request/SendNotificationsRequest.php:164) usesJSON_THROW_ON_ERROR.toJson()is the odd one out.Suggested fix
Add the
JSON_THROW_ON_ERRORflag tojson_encode()intoJson(), matching the rest of the codebase's JSON-boundary handling.Test gap
No test currently encodes a value that would fail JSON encoding (e.g. invalid UTF-8 in a message field) to confirm a
JsonExceptionis thrown rather than a silentfalse.