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) { if ($downloader instanceof ChangeReportInterface) {
$targetDir = $im->getInstallPath($package); $targetDir = $im->getInstallPath($package);
if ($changes = $downloader->getLocalChanges($targetDir, $package)) { if ($changes = $downloader->getLocalChanges($package, $targetDir)) {
$errors[$targetDir] = $changes; $errors[$targetDir] = $changes;
} }
} }

@ -24,9 +24,9 @@ interface ChangeReportInterface
/** /**
* Checks for changes to the local copy * Checks for changes to the local copy
* *
* @param string $path package directory
* @param PackageInterface $package package instance * @param PackageInterface $package package instance
* @param string $path package directory
* @return string|null changes or null * @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} * {@inheritDoc}
*/ */
public function getLocalChanges($path, PackageInterface $package) public function getLocalChanges(PackageInterface $package, $path)
{ {
$this->cleanEnv(); $this->cleanEnv();
$path = $this->normalizePath($path); $path = $this->normalizePath($path);
@ -97,11 +97,11 @@ class GitDownloader extends VcsDownloader
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
protected function cleanChanges($path, $update, $package) protected function cleanChanges(PackageInterface $package, $path, $update)
{ {
$this->cleanEnv(); $this->cleanEnv();
$path = $this->normalizePath($path); $path = $this->normalizePath($path);
if (!$changes = $this->getLocalChanges($path, $package)) { if (!$changes = $this->getLocalChanges($package, $path)) {
return; return;
} }
@ -112,13 +112,13 @@ class GitDownloader extends VcsDownloader
} }
if ('stash' === $discardChanges) { if ('stash' === $discardChanges) {
if (!$update) { if (!$update) {
return parent::cleanChanges($path, $update, $package); return parent::cleanChanges($package, $path, $update);
} }
return $this->stashChanges($path); return $this->stashChanges($path);
} }
return parent::cleanChanges($path, $update, $package); return parent::cleanChanges($package, $path, $update);
} }
$changes = array_map(function ($elem) { $changes = array_map(function ($elem) {

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

@ -52,7 +52,7 @@ class SvnDownloader extends VcsDownloader
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
public function getLocalChanges($path, PackageInterface $package) public function getLocalChanges(PackageInterface $package, $path)
{ {
if (!is_dir($path.'/.svn')) { if (!is_dir($path.'/.svn')) {
return; return;
@ -90,9 +90,9 @@ class SvnDownloader extends VcsDownloader
/** /**
* {@inheritDoc} * {@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; return;
} }
@ -101,7 +101,7 @@ class SvnDownloader extends VcsDownloader
return $this->discardChanges($path); return $this->discardChanges($path);
} }
return parent::cleanChanges($path, $update, $package); return parent::cleanChanges($package, $path, $update);
} }
$changes = array_map(function ($elem) { $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->io->write(" - Updating <info>" . $name . "</info> (<comment>" . $from . "</comment> => <comment>" . $to . "</comment>)");
$this->cleanChanges($path, true, $initial); $this->cleanChanges($initial, $path, true);
try { try {
$this->doUpdate($initial, $target, $path); $this->doUpdate($initial, $target, $path);
} catch (\Exception $e) { } catch (\Exception $e) {
@ -126,7 +126,7 @@ abstract class VcsDownloader implements DownloaderInterface, ChangeReportInterfa
public function remove(PackageInterface $package, $path) public function remove(PackageInterface $package, $path)
{ {
$this->io->write(" - Removing <info>" . $package->getName() . "</info> (<comment>" . $package->getPrettyVersion() . "</comment>)"); $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)) { if (!$this->filesystem->removeDirectory($path)) {
// retry after a bit on windows since it tends to be touchy with mass removals // 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))) { if (!defined('PHP_WINDOWS_VERSION_BUILD') || (usleep(250) && !$this->filesystem->removeDirectory($path))) {
@ -144,19 +144,19 @@ abstract class VcsDownloader implements DownloaderInterface, ChangeReportInterfa
return $this; return $this;
} }
/** /**
* Prompt the user to check if changes should be stashed/removed or the operation aborted * Prompt the user to check if changes should be stashed/removed or the operation aborted
* *
* @param string $path * @param PackageInterface $package
* @param bool $update if true (update) the changes can be stashed and reapplied after an update, * @param string $path
* if false (remove) the changes should be assumed to be lost if the operation is not aborted * @param bool $update if true (update) the changes can be stashed and reapplied after an update,
* @param PackageInterface $package * 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 * @throws \RuntimeException in case the operation must be aborted
*/ */
protected function cleanChanges($path, $update, $package) 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 // 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.'); throw new \RuntimeException('Source directory ' . $path . ' has uncommitted changes.');
} }
} }

Loading…
Cancel
Save