@@ -38,7 +38,11 @@ public function processFile(array $config)
3838 $ expectedParams = (array ) $ expectedValues [$ parameterKey ];
3939
4040 // find the actual params
41- $ actualValues = array ($ parameterKey => array ());
41+ $ actualValues = array_merge (
42+ // Preserve other top-level keys than `$parameterKey` in the file
43+ $ expectedValues ,
44+ array ($ parameterKey => array ())
45+ );
4246 if ($ exists ) {
4347 $ existingValues = $ yamlParser ->parse (file_get_contents ($ realFile ));
4448 if ($ existingValues === null ) {
@@ -52,13 +56,6 @@ public function processFile(array $config)
5256
5357 $ actualValues [$ parameterKey ] = $ this ->processParams ($ config , $ expectedParams , (array ) $ actualValues [$ parameterKey ]);
5458
55- // Preserve other top-level keys than `$parameterKey` in the file
56- foreach ($ expectedValues as $ key => $ setting ) {
57- if (!array_key_exists ($ key , $ actualValues )) {
58- $ actualValues [$ key ] = $ setting ;
59- }
60- }
61-
6259 if (!is_dir ($ dir = dirname ($ realFile ))) {
6360 mkdir ($ dir , 0755 , true );
6461 }
@@ -87,7 +84,7 @@ private function processConfig(array $config)
8784 return $ config ;
8885 }
8986
90- private function processParams (array $ config , $ expectedParams , $ actualParams )
87+ private function processParams (array $ config , array $ expectedParams , array $ actualParams )
9188 {
9289 // Grab values for parameters that were renamed
9390 $ renameMap = empty ($ config ['rename-map ' ]) ? array () : (array ) $ config ['rename-map ' ];
@@ -99,12 +96,7 @@ private function processParams(array $config, $expectedParams, $actualParams)
9996 }
10097
10198 if (!$ keepOutdatedParams ) {
102- // Remove the outdated params
103- foreach ($ actualParams as $ key => $ value ) {
104- if (!array_key_exists ($ key , $ expectedParams )) {
105- unset($ actualParams [$ key ]);
106- }
107- }
99+ $ actualParams = array_intersect_key ($ actualParams , $ expectedParams );
108100 }
109101
110102 $ envMap = empty ($ config ['env-map ' ]) ? array () : (array ) $ config ['env-map ' ];
0 commit comments