From c438120c695fab843cef5ed390a66a31849f9929 Mon Sep 17 00:00:00 2001 From: Paul Seiffert Date: Tue, 8 May 2012 22:41:37 +0200 Subject: [PATCH 1/7] Added comments to Composer class in order to make it IDE friendlier. Also added missing property 'config'. --- src/Composer/Composer.php | 60 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/src/Composer/Composer.php b/src/Composer/Composer.php index 0ad14c450..61e0b0f7a 100644 --- a/src/Composer/Composer.php +++ b/src/Composer/Composer.php @@ -26,68 +26,128 @@ class Composer { const VERSION = '@package_version@'; + /** + * @var Package\PackageInterface + */ private $package; + + /** + * @var Locker + */ private $locker; + /** + * @var Repository\RepositoryManager + */ private $repositoryManager; + + /** + * @var Downloader\DownloadManager + */ private $downloadManager; + + /** + * @var Installer\InstallationManager + */ private $installationManager; + /** + * @var Config + */ + private $config; + + /** + * @param Package\PackageInterface $package + * @return void + */ public function setPackage(PackageInterface $package) { $this->package = $package; } + /** + * @return Package\PackageInterface + */ public function getPackage() { return $this->package; } + /** + * @param Config $config + */ public function setConfig(Config $config) { $this->config = $config; } + /** + * @return Config + */ public function getConfig() { return $this->config; } + /** + * @param Package\Locker $locker + */ public function setLocker(Locker $locker) { $this->locker = $locker; } + /** + * @return Package\Locker + */ public function getLocker() { return $this->locker; } + /** + * @param Repository\RepositoryManager $manager + */ public function setRepositoryManager(RepositoryManager $manager) { $this->repositoryManager = $manager; } + /** + * @return Repository\RepositoryManager + */ public function getRepositoryManager() { return $this->repositoryManager; } + /** + * @param Downloader\DownloadManager $manager + */ public function setDownloadManager(DownloadManager $manager) { $this->downloadManager = $manager; } + /** + * @return Doenloader\DownloadManager + */ public function getDownloadManager() { return $this->downloadManager; } + /** + * @param Installer\InstallationManager $manager + */ public function setInstallationManager(InstallationManager $manager) { $this->installationManager = $manager; } + /** + * @return Installer\InstallationManager + */ public function getInstallationManager() { return $this->installationManager; From 16941adb49cc21f3347a3474769fd816e0f72795 Mon Sep 17 00:00:00 2001 From: Paul Seiffert Date: Tue, 8 May 2012 23:04:58 +0200 Subject: [PATCH 2/7] Added comments to Composer/Factory class in order to make it IDE friendlier. --- src/Composer/Factory.php | 49 +++++++++++++++++++++++++++++++++++----- 1 file changed, 43 insertions(+), 6 deletions(-) diff --git a/src/Composer/Factory.php b/src/Composer/Factory.php index 4cad60d97..7872b8d0c 100644 --- a/src/Composer/Factory.php +++ b/src/Composer/Factory.php @@ -27,6 +27,10 @@ use Composer\Util\RemoteFilesystem; */ class Factory { + /** + * @static + * @return Config + */ public static function createConfig() { // load main Composer configuration @@ -62,9 +66,11 @@ class Factory /** * Creates a Composer instance * - * @param IOInterface $io IO instance - * @param mixed $localConfig either a configuration array or a filename to read from, if null it will read from the default filename - * @return Composer + * @param IOInterface $io IO instance + * @param array|null $localConfig either a configuration array or a filename to read from, if null it will + * read from the default filename + * @throws \InvalidArgumentException + * @return Composer */ public function createComposer(IOInterface $io, $localConfig = null) { @@ -143,6 +149,11 @@ class Factory return $composer; } + /** + * @param IO\IOInterface $io + * @param Config $config + * @return Repository\RepositoryManager + */ protected function createRepositoryManager(IOInterface $io, Config $config) { $rm = new RepositoryManager($io, $config); @@ -157,6 +168,10 @@ class Factory return $rm; } + /** + * @param Repository\RepositoryManager $rm + * @param $vendorDir + */ protected function addLocalRepository(RepositoryManager $rm, $vendorDir) { // TODO BC feature, remove after May 30th @@ -180,6 +195,10 @@ class Factory $rm->setLocalDevRepository(new Repository\InstalledFilesystemRepository(new JsonFile($vendorDir.'/composer/installed_dev.json'))); } + /** + * @param array $localConfig + * @return array + */ protected function addPackagistRepository(array $localConfig) { $loadPackagist = true; @@ -210,6 +229,10 @@ class Factory return $localConfig; } + /** + * @param IO\IOInterface $io + * @return Downloader\DownloadManager + */ public function createDownloadManager(IOInterface $io) { $dm = new Downloader\DownloadManager(); @@ -225,6 +248,14 @@ class Factory return $dm; } + /** + * @param Repository\RepositoryManager $rm + * @param Downloader\DownloadManager $dm + * @param string $vendorDir + * @param string $binDir + * @param IO\IOInterface $io + * @return Installer\InstallationManager + */ protected function createInstallationManager(Repository\RepositoryManager $rm, Downloader\DownloadManager $dm, $vendorDir, $binDir, IOInterface $io) { $im = new Installer\InstallationManager($vendorDir); @@ -235,9 +266,14 @@ class Factory return $im; } + /** + * @param Repository\RepositoryManager $rm + * @param Installer\InstallationManager $im + */ protected function purgePackages(Repository\RepositoryManager $rm, Installer\InstallationManager $im) { foreach ($rm->getLocalRepositories() as $repo) { + /* @var $repo Repository\RepositoryInterface */ foreach ($repo->getPackages() as $package) { if (!$im->isPackageInstalled($repo, $package)) { $repo->removePackage($package); @@ -247,9 +283,10 @@ class Factory } /** - * @param IOInterface $io IO instance - * @param mixed $config either a configuration array or a filename to read from, if null it will read from the default filename - * @return Composer + * @param IOInterface $io IO instance + * @param mixed $config either a configuration array or a filename to read from, if null it will read from + * the default filename + * @return Composer */ static public function create(IOInterface $io, $config = null) { From 73080490564b75882b2457cda4cc38de4ab6c18f Mon Sep 17 00:00:00 2001 From: Paul Seiffert Date: Tue, 8 May 2012 23:06:10 +0200 Subject: [PATCH 3/7] Added removePackage() to Repository\RepositoryInterface in order to provide to be able to rely on the existance of this method in all repositories. Had to add this method to the Repository\CompositeRepository. --- src/Composer/Repository/CompositeRepository.php | 11 +++++++++++ src/Composer/Repository/RepositoryInterface.php | 7 +++++++ 2 files changed, 18 insertions(+) diff --git a/src/Composer/Repository/CompositeRepository.php b/src/Composer/Repository/CompositeRepository.php index e000d97e8..b01f2e7ca 100644 --- a/src/Composer/Repository/CompositeRepository.php +++ b/src/Composer/Repository/CompositeRepository.php @@ -91,6 +91,17 @@ class CompositeRepository implements RepositoryInterface return call_user_func_array('array_merge', $packages); } + /** + * {@inheritdoc} + */ + public function removePackage(PackageInterface $package) + { + foreach($this->repositories as $repository) { + /* @var $repository RepositoryInterface */ + $repository->removePackage($package); + } + } + /** * {@inheritdoc} */ diff --git a/src/Composer/Repository/RepositoryInterface.php b/src/Composer/Repository/RepositoryInterface.php index e4a79695d..de735c039 100644 --- a/src/Composer/Repository/RepositoryInterface.php +++ b/src/Composer/Repository/RepositoryInterface.php @@ -57,4 +57,11 @@ interface RepositoryInterface extends \Countable * @return array */ function getPackages(); + + /** + * @abstract + * @param \Composer\Package\PackageInterface $package + * @return void + */ + function removePackage(PackageInterface $package); } From 51e165c6c5e38370256db70cdfa5ee27bbe76e22 Mon Sep 17 00:00:00 2001 From: Paul Seiffert Date: Tue, 8 May 2012 23:25:32 +0200 Subject: [PATCH 4/7] Composer\Command dependencies (application and io) should can now be injected. This way, Composer\Command objects can be used in a regular symfony2 Console\Application. --- src/Composer/Command/Command.php | 52 +++++++++++++++++++++++++++++--- 1 file changed, 47 insertions(+), 5 deletions(-) diff --git a/src/Composer/Command/Command.php b/src/Composer/Command/Command.php index 98298d139..043b5d645 100644 --- a/src/Composer/Command/Command.php +++ b/src/Composer/Command/Command.php @@ -13,6 +13,7 @@ namespace Composer\Command; use Symfony\Component\Console\Command\Command as BaseCommand; +use Composer\Console\Application as ComposerApplication; /** * Base class for Composer commands @@ -23,18 +24,59 @@ use Symfony\Component\Console\Command\Command as BaseCommand; abstract class Command extends BaseCommand { /** - * @return \Composer\Composer + * @var \Composer\Composer */ - protected function getComposer($required = true) + private $composer; + + /** + * @var \Composer\IO\IOInterface + */ + private $io; + + /** + * @param bool $required + * @return \Composer\Composer + */ + public function getComposer($required = true) { - return $this->getApplication()->getComposer($required); + if (null === $this->composer) { + $application = $this->getApplication(); + if ($application instanceof ComposerApplication) { + /* @var $application ComposerApplication */ + $this->composer = $application->getComposer(); + } + } + return $this->composer; + } + + /** + * @param \Composer\Composer $composer + */ + public function setComposer(\Composer\Composer $composer) + { + $this->composer = $composer; } /** * @return \Composer\IO\ConsoleIO */ - protected function getIO() + public function getIO() { - return $this->getApplication()->getIO(); + if (null === $this->io) { + $application = $this->getApplication(); + if ($application instanceof ComposerApplication) { + /* @var $application ComposerApplication */ + $this->io = $application->getIO(); + } + } + return $this->io; + } + + /** + * @param \Composer\IO\IOInterface $io + */ + public function setIO(\Composer\IO\IOInterface $io) + { + $this->io = $io; } } From b3a5ca93c768f5fd6e39666929d8da0f014b01bb Mon Sep 17 00:00:00 2001 From: Paul Seiffert Date: Tue, 8 May 2012 23:26:01 +0200 Subject: [PATCH 5/7] Added comments -> IDE friendliness --- src/Composer/Console/Application.php | 12 +++++++++--- src/Composer/Repository/RepositoryInterface.php | 2 ++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/Composer/Console/Application.php b/src/Composer/Console/Application.php index ae7518618..555e6cf57 100644 --- a/src/Composer/Console/Application.php +++ b/src/Composer/Console/Application.php @@ -35,7 +35,14 @@ use Composer\Util\ErrorHandler; */ class Application extends BaseApplication { + /** + * @var Composer + */ protected $composer; + + /** + * @var ConsoleIO + */ protected $io; public function __construct() @@ -75,7 +82,8 @@ class Application extends BaseApplication } /** - * @return Composer + * @param bool $required + * @return \Composer\Composer */ public function getComposer($required = true) { @@ -87,8 +95,6 @@ class Application extends BaseApplication $this->io->write($e->getMessage()); exit(1); } - - return; } } diff --git a/src/Composer/Repository/RepositoryInterface.php b/src/Composer/Repository/RepositoryInterface.php index de735c039..b32872ef1 100644 --- a/src/Composer/Repository/RepositoryInterface.php +++ b/src/Composer/Repository/RepositoryInterface.php @@ -59,6 +59,8 @@ interface RepositoryInterface extends \Countable function getPackages(); /** + * Removes a package from the repository. + * * @abstract * @param \Composer\Package\PackageInterface $package * @return void From e4a0de5df47a496f883210589a03c484674df9a9 Mon Sep 17 00:00:00 2001 From: Paul Seiffert Date: Wed, 9 May 2012 00:30:33 +0200 Subject: [PATCH 6/7] When using composer commands outside a Composer\Console\Application, one does not have an IOInterface object --- src/Composer/Command/Command.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Composer/Command/Command.php b/src/Composer/Command/Command.php index 043b5d645..dc3183ee3 100644 --- a/src/Composer/Command/Command.php +++ b/src/Composer/Command/Command.php @@ -67,6 +67,8 @@ abstract class Command extends BaseCommand if ($application instanceof ComposerApplication) { /* @var $application ComposerApplication */ $this->io = $application->getIO(); + } else { + $this->io = new \Composer\IO\NullIO(); } } return $this->io; From 1713acf0112aa5df0bfeac550c50811c44691294 Mon Sep 17 00:00:00 2001 From: Paul Seiffert Date: Wed, 9 May 2012 09:50:08 +0200 Subject: [PATCH 7/7] Coding standards and Cosmetics Processing feedback given by @stof and @Seldaek. --- src/Composer/Command/Command.php | 23 +++++++++++-------- src/Composer/Factory.php | 13 +++++------ .../Repository/RepositoryInterface.php | 9 -------- src/Composer/Repository/RepositoryManager.php | 2 +- 4 files changed, 21 insertions(+), 26 deletions(-) diff --git a/src/Composer/Command/Command.php b/src/Composer/Command/Command.php index dc3183ee3..227ee0479 100644 --- a/src/Composer/Command/Command.php +++ b/src/Composer/Command/Command.php @@ -12,8 +12,11 @@ namespace Composer\Command; +use Composer\Composer; +use Composer\Console\Application; +use Composer\IO\IOInterface; +use Composer\IO\NullIO; use Symfony\Component\Console\Command\Command as BaseCommand; -use Composer\Console\Application as ComposerApplication; /** * Base class for Composer commands @@ -41,43 +44,45 @@ abstract class Command extends BaseCommand { if (null === $this->composer) { $application = $this->getApplication(); - if ($application instanceof ComposerApplication) { - /* @var $application ComposerApplication */ + if ($application instanceof Application) { + /* @var $application Application */ $this->composer = $application->getComposer(); } } + return $this->composer; } /** * @param \Composer\Composer $composer */ - public function setComposer(\Composer\Composer $composer) + public function setComposer(Composer $composer) { $this->composer = $composer; } /** - * @return \Composer\IO\ConsoleIO + * @return \Composer\IO\IOInterface */ public function getIO() { if (null === $this->io) { $application = $this->getApplication(); - if ($application instanceof ComposerApplication) { - /* @var $application ComposerApplication */ + if ($application instanceof Application) { + /* @var $application Application */ $this->io = $application->getIO(); } else { - $this->io = new \Composer\IO\NullIO(); + $this->io = new NullIO(); } } + return $this->io; } /** * @param \Composer\IO\IOInterface $io */ - public function setIO(\Composer\IO\IOInterface $io) + public function setIO(IOInterface $io) { $this->io = $io; } diff --git a/src/Composer/Factory.php b/src/Composer/Factory.php index 7872b8d0c..76f68203c 100644 --- a/src/Composer/Factory.php +++ b/src/Composer/Factory.php @@ -28,7 +28,6 @@ use Composer\Util\RemoteFilesystem; class Factory { /** - * @static * @return Config */ public static function createConfig() @@ -66,9 +65,9 @@ class Factory /** * Creates a Composer instance * - * @param IOInterface $io IO instance - * @param array|null $localConfig either a configuration array or a filename to read from, if null it will - * read from the default filename + * @param IOInterface $io IO instance + * @param array|string|null $localConfig either a configuration array or a filename to read from, if null it will + * read from the default filename * @throws \InvalidArgumentException * @return Composer */ @@ -169,8 +168,8 @@ class Factory } /** - * @param Repository\RepositoryManager $rm - * @param $vendorDir + * @param Repository\RepositoryManager $rm + * @param string $vendorDir */ protected function addLocalRepository(RepositoryManager $rm, $vendorDir) { @@ -273,7 +272,7 @@ class Factory protected function purgePackages(Repository\RepositoryManager $rm, Installer\InstallationManager $im) { foreach ($rm->getLocalRepositories() as $repo) { - /* @var $repo Repository\RepositoryInterface */ + /* @var $repo Repository\WritableRepositoryInterface */ foreach ($repo->getPackages() as $package) { if (!$im->isPackageInstalled($repo, $package)) { $repo->removePackage($package); diff --git a/src/Composer/Repository/RepositoryInterface.php b/src/Composer/Repository/RepositoryInterface.php index b32872ef1..e4a79695d 100644 --- a/src/Composer/Repository/RepositoryInterface.php +++ b/src/Composer/Repository/RepositoryInterface.php @@ -57,13 +57,4 @@ interface RepositoryInterface extends \Countable * @return array */ function getPackages(); - - /** - * Removes a package from the repository. - * - * @abstract - * @param \Composer\Package\PackageInterface $package - * @return void - */ - function removePackage(PackageInterface $package); } diff --git a/src/Composer/Repository/RepositoryManager.php b/src/Composer/Repository/RepositoryManager.php index febce81a3..8c36859dc 100644 --- a/src/Composer/Repository/RepositoryManager.php +++ b/src/Composer/Repository/RepositoryManager.php @@ -165,7 +165,7 @@ class RepositoryManager /** * Returns all local repositories for the project. * - * @return array[RepositoryInterface] + * @return array[WritableRepositoryInterface] */ public function getLocalRepositories() {