From 949728f81274cf2d828b52c1342f90b959c70ed2 Mon Sep 17 00:00:00 2001 From: Jerome Tamarelle Date: Tue, 24 Apr 2012 16:58:29 +0200 Subject: [PATCH] Remove redundant __contruct from VcsDriver implementations and move init code to initialize method --- .../Repository/Vcs/GitBitbucketDriver.php | 12 +++------ src/Composer/Repository/Vcs/GitDriver.php | 5 ---- src/Composer/Repository/Vcs/GitHubDriver.php | 19 +++----------- .../Repository/Vcs/HgBitbucketDriver.php | 12 +++------ src/Composer/Repository/Vcs/HgDriver.php | 9 ++----- src/Composer/Repository/Vcs/SvnDriver.php | 25 ++++++------------- src/Composer/Repository/Vcs/VcsDriver.php | 2 +- 7 files changed, 19 insertions(+), 65 deletions(-) diff --git a/src/Composer/Repository/Vcs/GitBitbucketDriver.php b/src/Composer/Repository/Vcs/GitBitbucketDriver.php index c0132cd10..b5cb8960d 100644 --- a/src/Composer/Repository/Vcs/GitBitbucketDriver.php +++ b/src/Composer/Repository/Vcs/GitBitbucketDriver.php @@ -27,20 +27,14 @@ class GitBitbucketDriver extends VcsDriver implements VcsDriverInterface protected $rootIdentifier; protected $infoCache = array(); - public function __construct($url, IOInterface $io) - { - preg_match('#^https://bitbucket\.org/([^/]+)/(.+?)\.git$#', $url, $match); - $this->owner = $match[1]; - $this->repository = $match[2]; - - parent::__construct($url, $io); - } - /** * {@inheritDoc} */ public function initialize() { + preg_match('#^https://bitbucket\.org/([^/]+)/(.+?)\.git$#', $this->url, $match); + $this->owner = $match[1]; + $this->repository = $match[2]; } /** diff --git a/src/Composer/Repository/Vcs/GitDriver.php b/src/Composer/Repository/Vcs/GitDriver.php index 4fe4fafb4..dd927fd1c 100644 --- a/src/Composer/Repository/Vcs/GitDriver.php +++ b/src/Composer/Repository/Vcs/GitDriver.php @@ -28,11 +28,6 @@ class GitDriver extends VcsDriver protected $repoDir; protected $infoCache = array(); - public function __construct($url, IOInterface $io, ProcessExecutor $process = null) - { - parent::__construct($url, $io, $process); - } - /** * {@inheritDoc} */ diff --git a/src/Composer/Repository/Vcs/GitHubDriver.php b/src/Composer/Repository/Vcs/GitHubDriver.php index 42633aafe..61a0589ac 100644 --- a/src/Composer/Repository/Vcs/GitHubDriver.php +++ b/src/Composer/Repository/Vcs/GitHubDriver.php @@ -39,27 +39,14 @@ class GitHubDriver extends VcsDriver protected $gitDriver; /** - * Constructor - * - * @param string $url - * @param IOInterface $io - * @param ProcessExecutor $process - * @param RemoteFilesystem $remoteFilesystem + * {@inheritDoc} */ - public function __construct($url, IOInterface $io, ProcessExecutor $process = null, RemoteFilesystem $remoteFilesystem = null) + public function initialize() { - preg_match('#^(?:https?|git)://github\.com/([^/]+)/(.+?)(?:\.git)?$#', $url, $match); + preg_match('#^(?:https?|git)://github\.com/([^/]+)/(.+?)(?:\.git)?$#', $this->url, $match); $this->owner = $match[1]; $this->repository = $match[2]; - parent::__construct($url, $io, $process, $remoteFilesystem); - } - - /** - * {@inheritDoc} - */ - public function initialize() - { $this->fetchRootIdentifier(); } diff --git a/src/Composer/Repository/Vcs/HgBitbucketDriver.php b/src/Composer/Repository/Vcs/HgBitbucketDriver.php index 993ece82d..43fff9aba 100644 --- a/src/Composer/Repository/Vcs/HgBitbucketDriver.php +++ b/src/Composer/Repository/Vcs/HgBitbucketDriver.php @@ -27,20 +27,14 @@ class HgBitbucketDriver extends VcsDriver protected $rootIdentifier; protected $infoCache = array(); - public function __construct($url, IOInterface $io) - { - preg_match('#^https://bitbucket\.org/([^/]+)/([^/]+)/?$#', $url, $match); - $this->owner = $match[1]; - $this->repository = $match[2]; - - parent::__construct($url, $io); - } - /** * {@inheritDoc} */ public function initialize() { + preg_match('#^https://bitbucket\.org/([^/]+)/([^/]+)/?$#', $this->url, $match); + $this->owner = $match[1]; + $this->repository = $match[2]; } /** diff --git a/src/Composer/Repository/Vcs/HgDriver.php b/src/Composer/Repository/Vcs/HgDriver.php index 833669cf9..17310d630 100644 --- a/src/Composer/Repository/Vcs/HgDriver.php +++ b/src/Composer/Repository/Vcs/HgDriver.php @@ -26,18 +26,13 @@ class HgDriver extends VcsDriver protected $rootIdentifier; protected $infoCache = array(); - public function __construct($url, IOInterface $io, ProcessExecutor $process = null) - { - $this->tmpDir = sys_get_temp_dir() . '/composer-' . preg_replace('{[^a-z0-9]}i', '-', $url) . '/'; - - parent::__construct($url, $io, $process); - } - /** * {@inheritDoc} */ public function initialize() { + $this->tmpDir = sys_get_temp_dir() . '/composer-' . preg_replace('{[^a-z0-9]}i', '-', $url) . '/'; + $url = escapeshellarg($this->url); $tmpDir = escapeshellarg($this->tmpDir); if (is_dir($this->tmpDir)) { diff --git a/src/Composer/Repository/Vcs/SvnDriver.php b/src/Composer/Repository/Vcs/SvnDriver.php index 6f13296ce..f5c3e04cd 100644 --- a/src/Composer/Repository/Vcs/SvnDriver.php +++ b/src/Composer/Repository/Vcs/SvnDriver.php @@ -35,24 +35,6 @@ class SvnDriver extends VcsDriver */ protected $util; - /** - * @param string $url - * @param IOInterface $io - * @param ProcessExecutor $process - * - * @return $this - */ - public function __construct($url, IOInterface $io, ProcessExecutor $process = null) - { - $url = self::normalizeUrl($url); - parent::__construct($this->baseUrl = rtrim($url, '/'), $io, $process); - - if (false !== ($pos = strrpos($url, '/trunk'))) { - $this->baseUrl = substr($url, 0, $pos); - } - $this->util = new SvnUtil($this->baseUrl, $io, $this->process); - } - /** * Execute an SVN command and try to fix up the process with credentials * if necessary. @@ -78,6 +60,13 @@ class SvnDriver extends VcsDriver */ public function initialize() { + $this->url = rtrim(self::normalizeUrl($this->url), '/'); + + if (false !== ($pos = strrpos($url, '/trunk'))) { + $this->baseUrl = substr($url, 0, $pos); + } + $this->util = new SvnUtil($this->baseUrl, $this->io, $this->process); + $this->getBranches(); $this->getTags(); } diff --git a/src/Composer/Repository/Vcs/VcsDriver.php b/src/Composer/Repository/Vcs/VcsDriver.php index f8d9893b9..d13b4b4a1 100644 --- a/src/Composer/Repository/Vcs/VcsDriver.php +++ b/src/Composer/Repository/Vcs/VcsDriver.php @@ -40,7 +40,7 @@ abstract class VcsDriver implements VcsDriverInterface * @param ProcessExecutor $process Process instance, injectable for mocking * @param callable $remoteFilesystem Remote Filesystem, injectable for mocking */ - public function __construct($url, IOInterface $io, Config $config, ProcessExecutor $process = null, $remoteFilesystem = null) + final public function __construct($url, IOInterface $io, Config $config, ProcessExecutor $process = null, $remoteFilesystem = null) { $this->url = $url; $this->io = $io;