Skip to content

Commit 780bbf8

Browse files
committed
Fix (and test) ComposerScripts::updateComposerJson
1 parent 226b093 commit 780bbf8

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

dev/ComposerScripts.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -162,15 +162,16 @@ private static function updateComposerJson($path, $value)
162162
$json = \file_get_contents($composerJsonPath);
163163
$data = \json_decode($json, true);
164164
$path = \explode('.', $path);
165+
$pointer = &$data;
165166
foreach ($path as $key) {
166-
if (!isset($data[$key]) || !\is_array($data[$key])) {
167-
$data[$key] = array();
167+
if (!isset($pointer[$key]) || !\is_array($pointer[$key])) {
168+
$pointer[$key] = array();
168169
}
169-
$data = &$data[$key];
170+
$pointer = &$pointer[$key];
170171
}
171-
$data = $value;
172-
$newJson = \json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) . "\n";
173-
\file_put_contents($composerJsonPath, $newJson);
172+
$pointer = $value;
173+
$json = \json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) . "\n";
174+
\file_put_contents($composerJsonPath, $json);
174175
}
175176

176177
/**

0 commit comments

Comments
 (0)