Adjust function signatures and add type hints, refs #2136

main
Jordi Boggiano 11 years ago
parent d96d9b3926
commit 1217a632fe

@ -59,7 +59,7 @@ EOT
if ($downloader instanceof ChangeReportInterface) {
$targetDir = $im->getInstallPath($package);
if ($changes = $downloader->getLocalChanges($targetDir, $package)) {
if ($changes = $downloader->getLocalChanges($package, $targetDir)) {
$errors[$targetDir] = $changes;
}
}

@ -24,9 +24,9 @@ interface ChangeReportInterface
/**
* Checks for changes to the local copy
*
* @param string $path package directory
* @param PackageInterface $package package instance
* @param string $path package directory
* @return string|null changes or null
*/
public function getLocalChanges($path, PackageInterface $package);
public function getLocalChanges(PackageInterface $package, $path);
}

@ -78,7 +78,7 @@ class GitDownloader extends VcsDownloader
/**
* {@inheritDoc}
*/
public function getLocalChanges($path, PackageInterface $package)
public function getLocalChanges(PackageInterface $package, $path)
{
$this->cleanEnv();
$path = $this->normalizePath($path);
@ -97,11 +97,11 @@ class GitDownloader extends VcsDownloader
/**
* {@inheritDoc}
*/
protected function cleanChanges($path, $update, $package)
protected function cleanChanges(PackageInterface $package, $path, $update)
{
$this->cleanEnv();
$path = $this->normalizePath($path);
if (!$changes = $this->getLocalChanges($path, $package)) {
if (!$changes = $this->getLocalChanges($package, $path)) {
return;
}
@ -112,13 +112,13 @@ class GitDownloader extends VcsDownloader
}
if ('stash' === $discardChanges) {
if (!$update) {
return parent::cleanChanges($path, $update, $package);
return parent::cleanChanges($package, $path, $update);
}
return $this->stashChanges($path);
}
return parent::cleanChanges($path, $update, $package);
return parent::cleanChanges($package, $path, $update);
}
$changes = array_map(function ($elem) {

@ -59,7 +59,7 @@ class HgDownloader extends VcsDownloader
/**
* {@inheritDoc}
*/
public function getLocalChanges($path, PackageInterface $package)
public function getLocalChanges(PackageInterface $package, $path)
{
if (!is_dir($path.'/.hg')) {
return;

@ -52,7 +52,7 @@ class SvnDownloader extends VcsDownloader
/**
* {@inheritDoc}
*/
public function getLocalChanges($path, PackageInterface $package)
public function getLocalChanges(PackageInterface $package, $path)
{
if (!is_dir($path.'/.svn')) {
return;
@ -90,9 +90,9 @@ class SvnDownloader extends VcsDownloader
/**
* {@inheritDoc}
*/
protected function cleanChanges($path, $update, $package)
protected function cleanChanges(PackageInterface $package, $path, $update)
{
if (!$changes = $this->getLocalChanges($path, $package)) {
if (!$changes = $this->getLocalChanges($package, $path)) {
return;
}
@ -101,7 +101,7 @@ class SvnDownloader extends VcsDownloader
return $this->discardChanges($path);
}
return parent::cleanChanges($path, $update, $package);
return parent::cleanChanges($package, $path, $update);
}
$changes = array_map(function ($elem) {

@ -86,7 +86,7 @@ abstract class VcsDownloader implements DownloaderInterface, ChangeReportInterfa
$this->io->write(" - Updating <info>" . $name . "</info> (<comment>" . $from . "</comment> => <comment>" . $to . "</comment>)");
$this->cleanChanges($path, true, $initial);
$this->cleanChanges($initial, $path, true);
try {
$this->doUpdate($initial, $target, $path);
} catch (\Exception $e) {
@ -126,7 +126,7 @@ abstract class VcsDownloader implements DownloaderInterface, ChangeReportInterfa
public function remove(PackageInterface $package, $path)
{
$this->io->write(" - Removing <info>" . $package->getName() . "</info> (<comment>" . $package->getPrettyVersion() . "</comment>)");
$this->cleanChanges($path, false, $package);
$this->cleanChanges($package, $path, false);
if (!$this->filesystem->removeDirectory($path)) {
// retry after a bit on windows since it tends to be touchy with mass removals
if (!defined('PHP_WINDOWS_VERSION_BUILD') || (usleep(250) && !$this->filesystem->removeDirectory($path))) {
@ -144,19 +144,19 @@ abstract class VcsDownloader implements DownloaderInterface, ChangeReportInterfa
return $this;
}
/**
* Prompt the user to check if changes should be stashed/removed or the operation aborted
*
* @param string $path
* @param bool $update if true (update) the changes can be stashed and reapplied after an update,
* if false (remove) the changes should be assumed to be lost if the operation is not aborted
* @param PackageInterface $package
* @throws \RuntimeException in case the operation must be aborted
*/
protected function cleanChanges($path, $update, $package)
/**
* Prompt the user to check if changes should be stashed/removed or the operation aborted
*
* @param PackageInterface $package
* @param string $path
* @param bool $update if true (update) the changes can be stashed and reapplied after an update,
* if false (remove) the changes should be assumed to be lost if the operation is not aborted
* @throws \RuntimeException in case the operation must be aborted
*/
protected function cleanChanges(PackageInterface $package, $path, $update)
{
// the default implementation just fails if there are any changes, override in child classes to provide stash-ability
if (null !== $this->getLocalChanges($path, $package)) {
if (null !== $this->getLocalChanges($package, $path)) {
throw new \RuntimeException('Source directory ' . $path . ' has uncommitted changes.');
}
}

Loading…
Cancel
Save