Skip to content

Commit

Permalink
Enhancement: Extract method
Browse files Browse the repository at this point in the history
  • Loading branch information
localheinz committed Dec 10, 2022
1 parent 7c0a1e3 commit b2eca7c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
2 changes: 1 addition & 1 deletion infection.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"text": ".build/infection/infection-log.txt"
},
"minCoveredMsi": 100,
"minMsi": 66,
"minMsi": 77,
"phpUnit": {
"configDir": "test\/Unit"
},
Expand Down
27 changes: 15 additions & 12 deletions src/Json.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,7 @@ private function __construct(
public static function fromString(string $encoded): self
{
try {
$decoded = \json_decode(
$encoded,
false,
512,
\JSON_THROW_ON_ERROR,
);
$decoded = self::decode($encoded);
} catch (\JsonException) {
throw Exception\NotJson::value($encoded);
}
Expand Down Expand Up @@ -67,12 +62,7 @@ public static function fromFile(string $file): self
}

try {
$decoded = \json_decode(
$encoded,
false,
512,
\JSON_THROW_ON_ERROR,
);
$decoded = self::decode($encoded);
} catch (\JsonException) {
throw Exception\FileDoesNotContainJson::file($file);
}
Expand Down Expand Up @@ -108,4 +98,17 @@ public function toString(): string
{
return $this->encoded;
}

/**
* @throws \JsonException
*/
private static function decode(string $encoded): mixed
{
return \json_decode(
$encoded,
false,
512,
\JSON_THROW_ON_ERROR,
);
}
}

0 comments on commit b2eca7c

Please sign in to comment.