From 1f41da8d3f42052c7019c7a918b3bc4a2f3895f0 Mon Sep 17 00:00:00 2001 From: till Date: Mon, 25 Jun 2012 18:59:04 +0200 Subject: [PATCH] * various cs fixes (idention, tabs/spaces, doc blocks, etc.) * fixed a typo'd exception name --- src/Composer/Package/Dumper/BaseDumper.php | 10 ++---- .../Package/Dumper/DumperInterface.php | 10 +++++- src/Composer/Package/Dumper/TarDumper.php | 31 ++++++++++--------- src/Composer/Package/Dumper/ZipDumper.php | 30 +++++++++--------- .../Test/Package/Dumper/DumperTest.php | 8 ++--- 5 files changed, 47 insertions(+), 42 deletions(-) diff --git a/src/Composer/Package/Dumper/BaseDumper.php b/src/Composer/Package/Dumper/BaseDumper.php index 3adc7ffd4c87..1a0e49484735 100644 --- a/src/Composer/Package/Dumper/BaseDumper.php +++ b/src/Composer/Package/Dumper/BaseDumper.php @@ -32,7 +32,7 @@ abstract class BaseDumper implements DumperInterface /** * @var array */ - static $keys = array( + protected static $keys = array( 'binaries' => 'bin', 'scripts', 'type', @@ -70,7 +70,6 @@ abstract class BaseDumper implements DumperInterface * @param mixed $path * @param \Composer\Util\ProcessExecutor|null $process * - * @return \Composer\Package\Dumper\BaseDumper * @throws \InvalidArgumentException */ public function __construct($path = null, ProcessExecutor $process = null) @@ -79,7 +78,7 @@ public function __construct($path = null, ProcessExecutor $process = null) if (!is_writable($path)) { throw new \InvalidArgumentException("Not authorized to write to '{$path}'"); } - $this->path = $path; + $this->path = $path; } $this->process = ($process !== null)?$process:new ProcessExecutor; $this->temp = sys_get_temp_dir(); @@ -95,10 +94,7 @@ public function __construct($path = null, ProcessExecutor $process = null) public function getFilename(PackageInterface $package, $extension) { $name = $package->getPrettyVersion(); - $fileName = sprintf('%s.%s', - $name, - $extension - ); + $fileName = sprintf('%s.%s', $name, $extension); return $fileName; } diff --git a/src/Composer/Package/Dumper/DumperInterface.php b/src/Composer/Package/Dumper/DumperInterface.php index 1f92000c26f5..cefa5e170bcc 100644 --- a/src/Composer/Package/Dumper/DumperInterface.php +++ b/src/Composer/Package/Dumper/DumperInterface.php @@ -17,5 +17,13 @@ */ interface DumperInterface { + /** + * Return value depends on implementation - e.g. generating a tar or zip the + * method currently returns void, the ArrayDumper returns an array. + * + * @param PackageInterface $package + * + * @return mixed + */ public function dump(PackageInterface $package); -} \ No newline at end of file +} diff --git a/src/Composer/Package/Dumper/TarDumper.php b/src/Composer/Package/Dumper/TarDumper.php index 99815b17c997..ca6dcb50451a 100644 --- a/src/Composer/Package/Dumper/TarDumper.php +++ b/src/Composer/Package/Dumper/TarDumper.php @@ -32,21 +32,22 @@ public function dump(PackageInterface $package) $sourceRef = $package->getSourceReference(); switch ($sourceType) { - case 'git': - $this->downloadGit($package, $workDir); - $this->packageGit($fileName, $sourceRef, $workDir); - break; - case 'hg': - $this->downloadHg($package, $workDir); - $this->packageHg($fileName, $sourceRef, $workDir); - break; - case 'svn': - $dir = $workDir . (substr($sourceRef, 0, 1) !== '/')?'/':'' . $sourceRef; - $this->downloadSvn($package, $workDir); - $this->package($fileName, $dir, \Phar::TAR); - break; - default: - throw new \InvalidArgumentException("Unable to handle repositories of type '{$sourceType}'."); + case 'git': + $this->downloadGit($package, $workDir); + $this->packageGit($fileName, $sourceRef, $workDir); + break; + case 'hg': + $this->downloadHg($package, $workDir); + $this->packageHg($fileName, $sourceRef, $workDir); + break; + case 'svn': + $dir = $workDir . (substr($sourceRef, 0, 1) !== '/')?'/':'' . $sourceRef; + $this->downloadSvn($package, $workDir); + $this->package($fileName, $dir, \Phar::TAR); + break; + default: + throw new \InvalidArgumentException( + "Unable to handle repositories of type '{$sourceType}'."); } } } diff --git a/src/Composer/Package/Dumper/ZipDumper.php b/src/Composer/Package/Dumper/ZipDumper.php index de3915d0c7ab..b0649b346774 100644 --- a/src/Composer/Package/Dumper/ZipDumper.php +++ b/src/Composer/Package/Dumper/ZipDumper.php @@ -32,21 +32,21 @@ public function dump(PackageInterface $package) $sourceRef = $package->getSourceReference(); switch ($sourceType) { - case 'git': - $this->downloadGit($package, $workDir); - $this->packageGit($fileName, $sourceRef, $workDir); - break; - case 'hg': - $this->downloadHg($package, $workDir); - $this->packageHg($fileName, $sourceRef, $workDir); - break; - case 'svn': - $dir = $workDir . (substr($sourceRef, 0, 1) !== '/')?'/':'' . $sourceRef; - $this->downloadSvn($package, $workDir); - $this->package($fileName, $dir, \Phar::ZIP); - break; - default: - throw new \InvalidArgumentException("Unable to handle repositories of type '{$sourceType}'."); + case 'git': + $this->downloadGit($package, $workDir); + $this->packageGit($fileName, $sourceRef, $workDir); + break; + case 'hg': + $this->downloadHg($package, $workDir); + $this->packageHg($fileName, $sourceRef, $workDir); + break; + case 'svn': + $dir = $workDir . (substr($sourceRef, 0, 1) !== '/')?'/':'' . $sourceRef; + $this->downloadSvn($package, $workDir); + $this->package($fileName, $dir, \Phar::ZIP); + break; + default: + throw new \InvalidArgumentException("Unable to handle repositories of type '{$sourceType}'."); } } } \ No newline at end of file diff --git a/tests/Composer/Test/Package/Dumper/DumperTest.php b/tests/Composer/Test/Package/Dumper/DumperTest.php index 6cc524b3ef99..6db54ea69054 100644 --- a/tests/Composer/Test/Package/Dumper/DumperTest.php +++ b/tests/Composer/Test/Package/Dumper/DumperTest.php @@ -35,7 +35,7 @@ abstract class DumperTest extends \PHPUnit_Framework_TestCase public function setUp() { $this->fs = new Filesystem; - $this->process = new ProcessExecutor; + $this->process = new ProcessExecutor; $this->testdir = sys_get_temp_dir() . '/composer_dumpertest_git_repository' . mt_rand(); } @@ -58,20 +58,20 @@ protected function setupGitRepo() chdir($td); $result = $this->process->execute("git init -q"); - if ($result > 0) { + if ($result > 0) { throw new \RuntimeException( "Could not init: " . $this->process->getErrorOutput()); } $result = file_put_contents('b', 'a'); if (false === $result) { - throw new \RuntimeExcepton("Could not save file."); + throw new \RuntimeException("Could not save file."); } $result = $this->process->execute("git add b && git commit -m 'commit b' -q"); if ($result > 0) { throw new \RuntimeException( "Could not init: " . $this->process->getErrorOutput()); } - chdir($currentWorkDir); + chdir($currentWorkDir); } protected function removeGitRepo()