From d689aa7d481d046ec6cc2460745737b6ac22aded Mon Sep 17 00:00:00 2001 From: Clemens Sahs Date: Mon, 5 May 2014 16:13:27 +0200 Subject: [PATCH 1/3] clean up RepositoryIntrospector --- .../Ocular/Util/RepositoryIntrospector.php | 25 +++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/src/Scrutinizer/Ocular/Util/RepositoryIntrospector.php b/src/Scrutinizer/Ocular/Util/RepositoryIntrospector.php index b96ac8a..c846ff0 100644 --- a/src/Scrutinizer/Ocular/Util/RepositoryIntrospector.php +++ b/src/Scrutinizer/Ocular/Util/RepositoryIntrospector.php @@ -19,30 +19,21 @@ public function __construct($repositoryDir) public function getCurrentRevision() { - $proc = new Process('git rev-parse HEAD', $this->dir); - if (0 !== $proc->run()) { - throw new ProcessFailedException($proc); - } + $proc = $this->exec('git rev-parse HEAD'); return trim($proc->getOutput()); } public function getCurrentParents() { - $proc = new Process('git log --pretty="%P" -n1 HEAD', $this->dir); - if (0 !== $proc->run()) { - throw new ProcessFailedException($proc); - } + $proc = $this->exec('git log --pretty="%P" -n1 HEAD'); return explode(' ', trim($proc->getOutput())); } public function getQualifiedName() { - $proc = new Process('git remote -v', $this->dir); - if (0 !== $proc->run()) { - throw new ProcessFailedException($proc); - } + $proc = $this->exec('git remote -v'); $output = $proc->getOutput(); @@ -75,4 +66,12 @@ private function getRepositoryType($host) throw new \LogicException(sprintf('Unknown host "%s".', $host)); } } -} \ No newline at end of file + + protected function exec($command, $dir = null) + { + $proc = new Process($command, $dir ?: $this->dir); + if (0 !== $proc->run()) { + throw new ProcessFailedException($proc); + } + } +} From 1937bbd60b8401e31ac1c35dc626b5076561c0e9 Mon Sep 17 00:00:00 2001 From: Clemens Sahs Date: Mon, 5 May 2014 16:17:05 +0200 Subject: [PATCH 2/3] add doc to new method --- src/Scrutinizer/Ocular/Util/RepositoryIntrospector.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Scrutinizer/Ocular/Util/RepositoryIntrospector.php b/src/Scrutinizer/Ocular/Util/RepositoryIntrospector.php index c846ff0..a36184a 100644 --- a/src/Scrutinizer/Ocular/Util/RepositoryIntrospector.php +++ b/src/Scrutinizer/Ocular/Util/RepositoryIntrospector.php @@ -67,6 +67,12 @@ private function getRepositoryType($host) } } + /** + * + * @param string $command + * @param string $dir + * @throws ProcessFailedException + */ protected function exec($command, $dir = null) { $proc = new Process($command, $dir ?: $this->dir); From 00e9d56e9fdec0aa51b5c24d0c2abab1574ee4d5 Mon Sep 17 00:00:00 2001 From: Clemens Sahs Date: Mon, 5 May 2014 16:19:29 +0200 Subject: [PATCH 3/3] add some more method doc [ci skip] --- .../Ocular/Util/RepositoryIntrospector.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/Scrutinizer/Ocular/Util/RepositoryIntrospector.php b/src/Scrutinizer/Ocular/Util/RepositoryIntrospector.php index a36184a..10f58e0 100644 --- a/src/Scrutinizer/Ocular/Util/RepositoryIntrospector.php +++ b/src/Scrutinizer/Ocular/Util/RepositoryIntrospector.php @@ -31,6 +31,11 @@ public function getCurrentParents() return explode(' ', trim($proc->getOutput())); } + /** + * + * @throws \RuntimeException + * @return string + */ public function getQualifiedName() { $proc = $this->exec('git remote -v'); @@ -53,6 +58,12 @@ public function getQualifiedName() throw new \RuntimeException(sprintf("Could not extract repository name from:\n%s", $output)); } + /** + * + * @param string $host + * @throws \LogicException + * @return string + */ private function getRepositoryType($host) { switch ($host) {