Browse Source

Updated to clean up code and rename variables to camelcase

mwhittom 11 years ago
parent
commit
8207518e04

+ 9 - 9
src/Composer/Repository/Vcs/PerforceDriver.php

@@ -26,8 +26,8 @@ class PerforceDriver extends VcsDriver
     protected $depot;
     protected $branch;
     protected $perforce;
-    protected $composer_info;
-    protected $composer_info_identifier;
+    protected $composerInfo;
+    protected $composerInfoIdentifier;
 
     /**
      * {@inheritDoc}
@@ -65,9 +65,9 @@ class PerforceDriver extends VcsDriver
      */
     public function getComposerInformation($identifier)
     {
-        if (isset($this->composer_info_identifier)) {
-            if (strcmp($identifier, $this->composer_info_identifier) === 0) {
-                return $this->composer_info;
+        if (isset($this->composerInfoIdentifier)) {
+            if (strcmp($identifier, $this->composerInfoIdentifier) === 0) {
+                return $this->composerInfo;
             }
         }
         $composer_info = $this->perforce->getComposerInformation($identifier);
@@ -139,11 +139,11 @@ class PerforceDriver extends VcsDriver
      */
     public function hasComposerFile($identifier)
     {
-        $this->composer_info = $this->perforce->getComposerInformation("//$this->depot/$identifier");
-        $this->composer_info_identifier = $identifier;
+        $this->composerInfo = $this->perforce->getComposerInformation("//$this->depot/$identifier");
+        $this->composerInfoIdentifier = $identifier;
         $result = false;
-        if (isset($this->composer_info)) {
-            $result = count($this->composer_info) > 0;
+        if (isset($this->composerInfo)) {
+            $result = count($this->composerInfo) > 0;
         }
         return $result;
     }

+ 25 - 32
src/Composer/Util/Perforce.php

@@ -31,7 +31,7 @@ class Perforce
     protected $p4DepotType;
     protected $p4Branch;
     protected $process;
-    protected $unique_perforce_client_name;
+    protected $uniquePerforceClientName;
     protected $windowsFlag;
 
 
@@ -59,12 +59,12 @@ class Perforce
 
     public function initialize($repoConfig)
     {
-        $this->unique_perforce_client_name = $this->generateUniquePerforceClientName();
-        if (!isset ($repoConfig)) {
+        $this->uniquePerforceClientName = $this->generateUniquePerforceClientName();
+        if (null == $repoConfig) {
             return;
         }
         if (isset($repoConfig['unique_perforce_client_name'])) {
-            $this->unique_perforce_client_name = $repoConfig['unique_perforce_client_name'];
+            $this->uniquePerforceClientName = $repoConfig['unique_perforce_client_name'];
         }
 
         if (isset($repoConfig['depot'])) {
@@ -119,8 +119,8 @@ class Perforce
     public function getClient()
     {
         if (!isset($this->p4Client)) {
-            $clean_stream_name = str_replace("@", "", str_replace("/", "_", str_replace("//", "", $this->getStream())));
-            $this->p4Client = "composer_perforce_" . $this->unique_perforce_client_name . "_" . $clean_stream_name;
+            $cleanStreamName = str_replace("@", "", str_replace("/", "_", str_replace("//", "", $this->getStream())));
+            $this->p4Client = "composer_perforce_" . $this->uniquePerforceClientName . "_" . $cleanStreamName;
         }
 
         return $this->p4Client;
@@ -327,7 +327,7 @@ class Perforce
         $spec = fopen($clientSpec, 'w');
         try {
             $this->writeClientSpecToFile($spec);
-        } catch (Exception $e) {
+        } catch (\Exception $e) {
             fclose($spec);
             throw $e;
         }
@@ -369,9 +369,9 @@ class Perforce
         fclose($pipes[1]);
         fclose($pipes[2]);
 
-        $return_code = proc_close($process);
+        $returnCode = proc_close($process);
 
-        return $return_code;
+        return $returnCode;
     }
 
 
@@ -389,34 +389,27 @@ class Perforce
         }
     }
 
-    public static function checkServerExists($url, ProcessExecutor $process_executor)
+    public static function checkServerExists($url, ProcessExecutor $processExecutor)
     {
-        $process = $process_executor ? : new ProcessExecutor;
         $result = "";
-        $process->execute("p4 -p $url info -s", $result);
-        $index = strpos($result, "error");
-        if ($index === false) {
-            return true;
-        }
-
-        return false;
+        $processExecutor->execute("p4 -p $url info -s", $result);
+        return false === strpos($result, "error");
     }
 
     public function getComposerInformation($identifier)
     {
         $index = strpos($identifier, "@");
         if ($index === false) {
-            $composer_json = "$identifier/composer.json";
+            $composerJson = "$identifier/composer.json";
 
-            return $this->getComposerInformationFromPath($composer_json);
-        } else {
-            return $this->getComposerInformationFromLabel($identifier, $index);
+            return $this->getComposerInformationFromPath($composerJson);
         }
+        return $this->getComposerInformationFromLabel($identifier, $index);
     }
 
-    public function getComposerInformationFromPath($composer_json)
+    public function getComposerInformationFromPath($composerJson)
     {
-        $command = $this->generateP4Command(" print $composer_json");
+        $command = $this->generateP4Command(" print $composerJson");
         $result = $this->executeCommand($command);
         $index = strpos($result, "{");
         if ($index === false) {
@@ -434,8 +427,8 @@ class Perforce
 
     public function getComposerInformationFromLabel($identifier, $index)
     {
-        $composer_json_path = substr($identifier, 0, $index) . "/composer.json" . substr($identifier, $index);
-        $command = $this->generateP4Command(" files $composer_json_path", false);
+        $composerJsonPath = substr($identifier, 0, $index) . "/composer.json" . substr($identifier, $index);
+        $command = $this->generateP4Command(" files $composerJsonPath", false);
         $result = $this->executeCommand($command);
         $index2 = strpos($result, "no such file(s).");
         if ($index2 === false) {
@@ -444,9 +437,9 @@ class Perforce
                 $phrase = trim(substr($result, $index3));
                 $fields = explode(" ", $phrase);
                 $id = $fields[1];
-                $composer_json = substr($identifier, 0, $index) . "/composer.json@" . $id;
+                $composerJson = substr($identifier, 0, $index) . "/composer.json@" . $id;
 
-                return $this->getComposerInformationFromPath($composer_json);
+                return $this->getComposerInformationFromPath($composerJson);
             }
         }
 
@@ -455,9 +448,9 @@ class Perforce
 
     public function getBranches()
     {
-        $possible_branches = array();
+        $possibleBranches = array();
         if (!$this->isStream()) {
-            $possible_branches[$this->p4Branch] = $this->getStream();
+            $possibleBranches[$this->p4Branch] = $this->getStream();
         } else {
             $command = $this->generateP4Command("streams //$this->p4Depot/...");
             $result = $this->executeCommand($command);
@@ -466,12 +459,12 @@ class Perforce
                 $resBits = explode(" ", $line);
                 if (count($resBits) > 4) {
                     $branch = preg_replace("/[^A-Za-z0-9 ]/", '', $resBits[4]);
-                    $possible_branches[$branch] = $resBits[1];
+                    $possibleBranches[$branch] = $resBits[1];
                 }
             }
         }
         $branches = array();
-        $branches['master'] = $possible_branches[$this->p4Branch];
+        $branches['master'] = $possibleBranches[$this->p4Branch];
 
         return $branches;
     }

+ 0 - 1
tests/Composer/Test/Package/Archiver/ArchivableFilesFinderTest.php

@@ -146,7 +146,6 @@ class ArchivableFilesFinderTest extends \PHPUnit_Framework_TestCase
 
     public function testHgExcludes()
     {
-        $this->markTestSkipped('Mercurial test does not work.');
         // Ensure that Mercurial is available for testing.
         if (!$this->isProcessAvailable('hg')) {
             return $this->markTestSkipped('Mercurial is not available.');

+ 6 - 6
tests/Composer/Test/Repository/Vcs/PerforceDriverTest.php

@@ -54,12 +54,12 @@ class PerforceDriverTest extends \PHPUnit_Framework_TestCase
     public function testInitializeCapturesVariablesFromRepoConfig()
     {
         $this->setUp();
-        $repo_config = array(
+        $repoConfig = array(
             'url'    => 'TEST_PERFORCE_URL',
             'depot'  => 'TEST_DEPOT_CONFIG',
             'branch' => 'TEST_BRANCH_CONFIG'
         );
-        $driver = new PerforceDriver($repo_config, $this->io, $this->config, $this->process, $this->remoteFileSystem);
+        $driver = new PerforceDriver($repoConfig, $this->io, $this->config, $this->process, $this->remoteFileSystem);
         $process = $this->getMock('Composer\Util\ProcessExecutor');
         $arguments = array(
             array('depot' => 'TEST_DEPOT', 'branch' => 'TEST_BRANCH'),
@@ -80,12 +80,12 @@ class PerforceDriverTest extends \PHPUnit_Framework_TestCase
     public function testInitializeLogsInAndConnectsClient()
     {
         $this->setUp();
-        $repo_config = array(
+        $repoConfig = array(
             'url'    => 'TEST_PERFORCE_URL',
             'depot'  => 'TEST_DEPOT_CONFIG',
             'branch' => 'TEST_BRANCH_CONFIG'
         );
-        $driver = new PerforceDriver($repo_config, $this->io, $this->config, $this->process, $this->remoteFileSystem);
+        $driver = new PerforceDriver($repoConfig, $this->io, $this->config, $this->process, $this->remoteFileSystem);
         $perforce = $this->getMockBuilder('Composer\Util\Perforce')->disableOriginalConstructor()->getMock();
         $perforce->expects($this->at(0))
         ->method('p4Login')
@@ -105,12 +105,12 @@ class PerforceDriverTest extends \PHPUnit_Framework_TestCase
     public function testHasComposerFile()
     {
         $this->setUp();
-        $repo_config = array(
+        $repoConfig = array(
             'url'    => 'TEST_PERFORCE_URL',
             'depot'  => 'TEST_DEPOT_CONFIG',
             'branch' => 'TEST_BRANCH_CONFIG'
         );
-        $driver = new PerforceDriver($repo_config, $this->io, $this->config, $this->process, $this->remoteFileSystem);
+        $driver = new PerforceDriver($repoConfig, $this->io, $this->config, $this->process, $this->remoteFileSystem);
         $process = $this->getMock('Composer\Util\ProcessExecutor');
         $arguments = array(
             array('depot' => 'TEST_DEPOT', 'branch' => 'TEST_BRANCH'),