Skip to content

Commit

Permalink
Merge #391 Survive through a malformed installed.json file
Browse files Browse the repository at this point in the history
  • Loading branch information
jnvsor committed Jul 30, 2022
2 parents 055630e + 78ce27b commit 84a61c9
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 0 deletions.
Binary file modified build/kint.phar
Binary file not shown.
4 changes: 4 additions & 0 deletions src/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ public static function composerGetExtras($key = 'kint')
if (\file_exists($installed) && \is_readable($installed)) {
$packages = \json_decode(\file_get_contents($installed), true);

if (!\is_array($packages)) {
continue;
}

foreach ($packages as $package) {
if (isset($package['extra'][$key]) && \is_array($package['extra'][$key])) {
$extras = \array_replace($extras, $package['extra'][$key]);
Expand Down
3 changes: 3 additions & 0 deletions tests/UtilsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,9 @@ public function testComposerGetExtras()
]));

$this->assertSame(['more' => 'test', 'data', 'test' => 'ing'], Utils::composerGetExtras('kint'));

\file_put_contents($this->composer_test_dir.'/composer/installed.json', 'malformed JSON.');
$this->assertSame([], Utils::composerGetExtras('kint'));
}

public function traceProvider()
Expand Down

0 comments on commit 84a61c9

Please sign in to comment.