@@ -78,7 +78,8 @@ public function configure(Recipe $recipe, $config, Lock $lock, array $options =
78
78
}
79
79
$ target = isset ($ patch ['target ' ]) ? $ patch ['target ' ] : null ;
80
80
81
- $ this ->patchFile ($ file , $ content , $ position , $ target , $ warnIfMissing );
81
+ $ newContents = $ this ->getPatchedContents ($ file , $ content , $ position , $ target , $ warnIfMissing );
82
+ file_put_contents ($ file , $ newContents );
82
83
}
83
84
}
84
85
@@ -106,7 +107,8 @@ public function unconfigure(Recipe $recipe, $config, Lock $lock): void
106
107
}
107
108
$ value = $ patch ['content ' ];
108
109
109
- $ this ->unPatchFile ($ file , $ value );
110
+ $ newContents = $ this ->getUnPatchedContents ($ file , $ value );
111
+ file_put_contents ($ file , $ newContents );
110
112
}
111
113
}
112
114
@@ -145,12 +147,12 @@ public function update(RecipeUpdate $recipeUpdate, array $originalConfig, array
145
147
$ this ->configure ($ recipeUpdate ->getNewRecipe (), $ filteredNewConfig , $ recipeUpdate ->getLock ());
146
148
}
147
149
148
- private function patchFile (string $ file , string $ value , string $ position , ?string $ target , bool $ warnIfMissing )
150
+ private function getPatchedContents (string $ file , string $ value , string $ position , ?string $ target , bool $ warnIfMissing ): string
149
151
{
150
152
$ fileContents = file_get_contents ($ file );
151
153
152
154
if (false !== strpos ($ fileContents , $ value )) {
153
- return ; // already includes value, skip
155
+ return $ fileContents ; // already includes value, skip
154
156
}
155
157
156
158
switch ($ position ) {
@@ -188,15 +190,15 @@ private function patchFile(string $file, string $value, string $position, ?strin
188
190
break ;
189
191
}
190
192
191
- file_put_contents ( $ file , $ fileContents) ;
193
+ return $ fileContents ;
192
194
}
193
195
194
- private function unPatchFile (string $ file , $ value )
196
+ private function getUnPatchedContents (string $ file , $ value ): string
195
197
{
196
198
$ fileContents = file_get_contents ($ file );
197
199
198
200
if (false === strpos ($ fileContents , $ value )) {
199
- return ; // value already gone!
201
+ return $ fileContents ; // value already gone!
200
202
}
201
203
202
204
if (false !== strpos ($ fileContents , "\n" .$ value )) {
@@ -208,7 +210,7 @@ private function unPatchFile(string $file, $value)
208
210
$ position = strpos ($ fileContents , $ value );
209
211
$ fileContents = substr_replace ($ fileContents , '' , $ position , \strlen ($ value ));
210
212
211
- file_put_contents ( $ file , $ fileContents) ;
213
+ return $ fileContents ;
212
214
}
213
215
214
216
private function isPackageInstalled ($ packages ): bool
0 commit comments