Skip to content

Commit 9693354

Browse files
committed
feat: improve json reading error handling
1 parent 283ee39 commit 9693354

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/Install/Mcp/FileWriter.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Laravel\Boost\Install\Mcp;
66

77
use Illuminate\Support\Facades\File;
8+
use Illuminate\Support\Str;
89

910
class FileWriter
1011
{
@@ -63,7 +64,7 @@ public function save(): bool
6364
protected function updatePlainJsonFile(string $content): bool
6465
{
6566
$config = json_decode($content, true);
66-
if ($config === null) {
67+
if (json_last_error() !== JSON_ERROR_NONE) {
6768
return false;
6869
}
6970

@@ -223,16 +224,15 @@ protected function needsCommaBeforeClosingBrace(string $content, int $openBraceP
223224
$trimmed = preg_replace('/\s+|\/\/.*$/m', '', $innerContent);
224225

225226
// If empty or ends with opening brace, no comma needed
226-
if (empty($trimmed) || substr($trimmed, -1) === '{') {
227+
if (blank($trimmed) || Str::endsWith($trimmed, '{')) {
227228
return false;
228229
}
229230

230231
// If ends with comma, no additional comma needed
231-
if (substr($trimmed, -1) === ',') {
232+
if (Str::endsWith($trimmed, ',')) {
232233
return false;
233234
}
234235

235-
// Otherwise, we need a comma
236236
return true;
237237
}
238238

0 commit comments

Comments
 (0)