Skip to content

Commit

Permalink
refactor: Use the PHP native decode to decode the JSON artifacts
Browse files Browse the repository at this point in the history
  • Loading branch information
theofidry committed Dec 16, 2023
1 parent 23d6f5b commit 6f918b0
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/Configuration/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Fidry\FileSystem\FS;
use Humbug\PhpScoper\Configuration\Configuration as PhpScoperConfiguration;
use InvalidArgumentException;
use JsonException;
use KevinGH\Box\Compactor\Compactor;
use KevinGH\Box\Compactor\Compactors;
use KevinGH\Box\Compactor\Php as PhpCompactor;
Expand All @@ -37,7 +38,6 @@
use KevinGH\Box\PhpScoper\SerializableScoper;
use Phar;
use RuntimeException;
use Seld\JsonLint\ParsingException;
use SplFileInfo;
use stdClass;
use Symfony\Component\Filesystem\Path;
Expand Down Expand Up @@ -80,6 +80,7 @@
use function preg_replace;
use function property_exists;
use function realpath;
use function Safe\json_decode;
use function sprintf;
use function str_starts_with;
use function trigger_error;
Expand Down Expand Up @@ -1820,15 +1821,13 @@ private static function retrieveComposerArtifacts(string $basePath): ComposerArt

private static function retrieveComposerArtifact(string $path): ?ComposerArtifact
{
$json = new Json();

if (false === file_exists($path) || false === is_file($path) || false === is_readable($path)) {
return null;
}

try {
$contents = (array) $json->decodeFile($path, true);
} catch (ParsingException $exception) {
$contents = json_decode($path, true);
} catch (JsonException $exception) {
throw new InvalidArgumentException(
sprintf(
'Expected the file "%s" to be a valid composer.json file but an error has been found: %s',
Expand Down

0 comments on commit 6f918b0

Please sign in to comment.