Skip to content

Commit 94a3e56

Browse files
committed
Internal: changing private functions to return a string
1 parent 039bb47 commit 94a3e56

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/Configurator/AddLinesConfigurator.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ public function configure(Recipe $recipe, $config, Lock $lock, array $options =
7878
}
7979
$target = isset($patch['target']) ? $patch['target'] : null;
8080

81-
$this->patchFile($file, $content, $position, $target, $warnIfMissing);
81+
$newContents = $this->getPatchedContents($file, $content, $position, $target, $warnIfMissing);
82+
file_put_contents($file, $newContents);
8283
}
8384
}
8485

@@ -106,7 +107,8 @@ public function unconfigure(Recipe $recipe, $config, Lock $lock): void
106107
}
107108
$value = $patch['content'];
108109

109-
$this->unPatchFile($file, $value);
110+
$newContents = $this->getUnPatchedContents($file, $value);
111+
file_put_contents($file, $newContents);
110112
}
111113
}
112114

@@ -145,12 +147,12 @@ public function update(RecipeUpdate $recipeUpdate, array $originalConfig, array
145147
$this->configure($recipeUpdate->getNewRecipe(), $filteredNewConfig, $recipeUpdate->getLock());
146148
}
147149

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
149151
{
150152
$fileContents = file_get_contents($file);
151153

152154
if (false !== strpos($fileContents, $value)) {
153-
return; // already includes value, skip
155+
return $fileContents; // already includes value, skip
154156
}
155157

156158
switch ($position) {
@@ -188,15 +190,15 @@ private function patchFile(string $file, string $value, string $position, ?strin
188190
break;
189191
}
190192

191-
file_put_contents($file, $fileContents);
193+
return $fileContents;
192194
}
193195

194-
private function unPatchFile(string $file, $value)
196+
private function getUnPatchedContents(string $file, $value): string
195197
{
196198
$fileContents = file_get_contents($file);
197199

198200
if (false === strpos($fileContents, $value)) {
199-
return; // value already gone!
201+
return $fileContents; // value already gone!
200202
}
201203

202204
if (false !== strpos($fileContents, "\n".$value)) {
@@ -208,7 +210,7 @@ private function unPatchFile(string $file, $value)
208210
$position = strpos($fileContents, $value);
209211
$fileContents = substr_replace($fileContents, '', $position, \strlen($value));
210212

211-
file_put_contents($file, $fileContents);
213+
return $fileContents;
212214
}
213215

214216
private function isPackageInstalled($packages): bool

0 commit comments

Comments
 (0)