Browse Source

Remove redundant __contruct from VcsDriver implementations and move init code to initialize method

Jerome Tamarelle 13 years ago
parent
commit
949728f812

+ 3 - 9
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];
     }
 
     /**

+ 0 - 5
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}
      */

+ 3 - 16
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();
     }
 

+ 3 - 9
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];
     }
 
     /**

+ 2 - 7
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)) {

+ 7 - 18
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();
     }

+ 1 - 1
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;