diff --git a/src/Composer/Command/StatusCommand.php b/src/Composer/Command/StatusCommand.php index 7721a6501..2a1388039 100644 --- a/src/Composer/Command/StatusCommand.php +++ b/src/Composer/Command/StatusCommand.php @@ -109,7 +109,7 @@ EOT $errors[$targetDir] = $targetDir . ' is a symbolic link.'; } - if ($changes = $downloader->getLocalChanges($package, $targetDir)) { + if (null !== ($changes = $downloader->getLocalChanges($package, $targetDir))) { $errors[$targetDir] = $changes; } } diff --git a/src/Composer/Downloader/FileDownloader.php b/src/Composer/Downloader/FileDownloader.php index 39eaf6528..9b5783a16 100644 --- a/src/Composer/Downloader/FileDownloader.php +++ b/src/Composer/Downloader/FileDownloader.php @@ -500,7 +500,7 @@ class FileDownloader implements DownloaderInterface, ChangeReportInterface $comparer->setSource($targetDir.'_compare'); $comparer->setUpdate($targetDir); $comparer->doCompare(); - $output = $comparer->getChanged(true, true); + $output = $comparer->getChangedAsString(true); $this->filesystem->removeDirectory($targetDir.'_compare'); } catch (\Exception $e) { } @@ -511,6 +511,8 @@ class FileDownloader implements DownloaderInterface, ChangeReportInterface throw $e; } - return trim($output); + $output = trim($output); + + return strlen($output) > 0 ? $output : null; } } diff --git a/src/Composer/Downloader/FossilDownloader.php b/src/Composer/Downloader/FossilDownloader.php index d1ae129c3..6c8b73909 100644 --- a/src/Composer/Downloader/FossilDownloader.php +++ b/src/Composer/Downloader/FossilDownloader.php @@ -92,7 +92,9 @@ class FossilDownloader extends VcsDownloader $this->process->execute('fossil changes', $output, realpath($path)); - return trim($output) ?: null; + $output = trim($output); + + return strlen($output) > 0 ? $output : null; } /** diff --git a/src/Composer/Downloader/GitDownloader.php b/src/Composer/Downloader/GitDownloader.php index 89a4debab..bae9a8586 100644 --- a/src/Composer/Downloader/GitDownloader.php +++ b/src/Composer/Downloader/GitDownloader.php @@ -225,7 +225,9 @@ class GitDownloader extends VcsDownloader implements DvcsDownloaderInterface throw new \RuntimeException('Failed to execute ' . $command . "\n\n" . $this->process->getErrorOutput()); } - return trim($output) ?: null; + $output = trim($output); + + return strlen($output) > 0 ? $output : null; } /** @@ -338,7 +340,7 @@ class GitDownloader extends VcsDownloader implements DvcsDownloaderInterface throw new \RuntimeException('Source directory ' . $path . ' has unpushed changes on the current branch: '."\n".$unpushed); } - if (!$changes = $this->getLocalChanges($package, $path)) { + if (null === ($changes = $this->getLocalChanges($package, $path))) { return \React\Promise\resolve(); } diff --git a/src/Composer/Downloader/HgDownloader.php b/src/Composer/Downloader/HgDownloader.php index c32375c97..c1d3cd764 100644 --- a/src/Composer/Downloader/HgDownloader.php +++ b/src/Composer/Downloader/HgDownloader.php @@ -90,7 +90,9 @@ class HgDownloader extends VcsDownloader $this->process->execute('hg st', $output, realpath($path)); - return trim($output) ?: null; + $output = trim($output); + + return strlen($output) > 0 ? $output : null; } /** diff --git a/src/Composer/Downloader/SvnDownloader.php b/src/Composer/Downloader/SvnDownloader.php index 7e532f444..ee93f51b2 100644 --- a/src/Composer/Downloader/SvnDownloader.php +++ b/src/Composer/Downloader/SvnDownloader.php @@ -132,7 +132,7 @@ class SvnDownloader extends VcsDownloader */ protected function cleanChanges(PackageInterface $package, string $path, bool $update): PromiseInterface { - if (!$changes = $this->getLocalChanges($package, $path)) { + if (null === ($changes = $this->getLocalChanges($package, $path))) { return \React\Promise\resolve(); } diff --git a/src/Composer/Package/Comparer/Comparer.php b/src/Composer/Package/Comparer/Comparer.php index a2dd890bb..a52e1c1af 100644 --- a/src/Composer/Package/Comparer/Comparer.php +++ b/src/Composer/Package/Comparer/Comparer.php @@ -49,12 +49,11 @@ class Comparer } /** - * @param bool $toString * @param bool $explicated * - * @return array{changed?: string[], removed?: string[], added?: string[]}|string|false false if no change, string only if $toString is true + * @return array{changed?: string[], removed?: string[], added?: string[]}|false false if no change */ - public function getChanged(bool $toString = false, bool $explicated = false) + public function getChanged(bool $explicated = false) { $changed = $this->changed; if (!count($changed)) { @@ -68,17 +67,29 @@ class Comparer } } - if ($toString) { - $strings = array(); - foreach ($changed as $sectionKey => $itemSection) { - foreach ($itemSection as $itemKey => $item) { - $strings[] = $item."\r\n"; - } - } - $changed = implode("\r\n", $strings); + return $changed; + } + + /** + * @param bool $explicated + * + * @return string empty string if no changes + */ + public function getChangedAsString(bool $toString = false, bool $explicated = false): string + { + $changed = $this->getChanged($explicated); + if (false === $changed) { + return ''; } - return $changed; + $strings = array(); + foreach ($changed as $sectionKey => $itemSection) { + foreach ($itemSection as $itemKey => $item) { + $strings[] = $item."\r\n"; + } + } + + return trim(implode("\r\n", $strings)); } /**