Skip to content

Commit

Permalink
perf(JsonFixer): Improve readability of conditional statements
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
[email protected] committed Sep 30, 2024
1 parent 43f2989 commit 012e870
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions app/Support/JsonFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public function fix(string $json): string
return $json;
}

if (null !== $tmpJson = $this->quickFix($json)) {
if (null !== ($tmpJson = $this->quickFix($json))) {
return $tmpJson;
}

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

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

Expand Down Expand Up @@ -289,7 +289,7 @@ private function padLiteral(string $tmpJson): string

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

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

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

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

Expand Down

0 comments on commit 012e870

Please sign in to comment.