Skip to content

Commit 012e870

Browse files
author
ityaozm@gmail.com
committed
perf(JsonFixer): Improve readability of conditional statements
- Refactor conditional assignments for better clarity. - Change variable assignment style in quickFix and other methods. - Enhance code maintainability by ensuring consistent structure in if statements.
1 parent 43f2989 commit 012e870

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

app/Support/JsonFixer.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public function fix(string $json): string
8989
return $json;
9090
}
9191

92-
if (null !== $tmpJson = $this->quickFix($json)) {
92+
if (null !== ($tmpJson = $this->quickFix($json))) {
9393
return $tmpJson;
9494
}
9595

@@ -139,7 +139,7 @@ private function isValid(string $json): bool
139139

140140
private function quickFix(string $json): ?string
141141
{
142-
if (1 === \strlen($json) && isset($this->pairs[$json])) {
142+
if (isset($this->pairs[$json]) && 1 === \strlen($json)) {
143143
return $json.$this->pairs[$json];
144144
}
145145

@@ -289,7 +289,7 @@ private function padLiteral(string $tmpJson): string
289289

290290
$match = preg_match('/(tr?u?e?|fa?l?s?e?|nu?l?l?)$/', $tmpJson, $matches);
291291

292-
if (! $match || null === $literal = $this->maybeLiteral($matches[1])) {
292+
if (! $match || null === ($literal = $this->maybeLiteral($matches[1]))) {
293293
return $tmpJson;
294294
}
295295

@@ -314,7 +314,7 @@ private function padObject(string $tmpJson): string
314314
}
315315

316316
$part = substr($tmpJson, $this->objectPos + 1);
317-
if (preg_match('/(\s*\"[^"]+\"\s*:\s*[^,]+,?)+$/', $part, $matches)) {
317+
if (preg_match('/(\s*\"[^"]+\"\s*:\s*[^,]+,?)+$/', $part)) {
318318
return $tmpJson;
319319
}
320320

0 commit comments

Comments
 (0)