Skip to content

Commit

Permalink
Extract dumping of config into separate method
Browse files Browse the repository at this point in the history
  • Loading branch information
franzliedke committed Apr 6, 2016
1 parent ed749c6 commit 9b173ff
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/Config/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,38 +58,41 @@ public function getPaths()

public function addPath($path)
{
// ensure paths are loaded
// Ensure paths are loaded
$this->getPaths();

$this->paths[] = $path;
$this->writeToFile(
$this->serializer->serializePaths($this->paths)
);
$this->dump();
}

public function hasPackages()
{
// Ensure our packages are loaded
// Ensure paths are loaded
$this->getPaths();

return ! empty($this->paths);
}

public function removePackage(Package $package)
{
// Ensure our packages are loaded
// Ensure paths are loaded
$this->getPaths();

$path = $package->getPath();

if (($key = array_search($path, $this->paths)) !== false) {
unset($this->paths[$key]);
$this->writeToFile(
$this->serializer->serializePaths($this->paths)
);
$this->dump();
}
}

protected function dump()
{
$this->writeToFile(
$this->serializer->serializePaths($this->paths)
);
}

protected function writeToFile(array $data)
{
file_put_contents(
Expand Down

0 comments on commit 9b173ff

Please sign in to comment.