Skip to content

Commit de59c78

Browse files
author
Alexandre Salomé
committed
Merge pull request #37 from gitonomy/feat-exception
Used only gitonomy exceptions
2 parents 211aeef + b190e4c commit de59c78

20 files changed

+130
-81
lines changed

src/Gitonomy/Git/Admin.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
namespace Gitonomy\Git;
1414

15-
use Psr\Log\LoggerInterface;
15+
use Gitonomy\Git\Exception\RuntimeException;
1616
use Symfony\Component\Process\ProcessBuilder;
1717

1818
/**
@@ -54,7 +54,7 @@ public static function init($path, $bare = true, array $options = array())
5454
$process->run();
5555

5656
if (!$process->isSuccessFul()) {
57-
throw new \RuntimeException(sprintf("Error on repository initialization, command wasn't successful (%s). Error output:\n%s", $process->getCommandLine(), $process->getErrorOutput()));
57+
throw new RuntimeException(sprintf("Error on repository initialization, command wasn't successful (%s). Error output:\n%s", $process->getCommandLine(), $process->getErrorOutput()));
5858
}
5959

6060
return new Repository($path, $options);
@@ -63,9 +63,9 @@ public static function init($path, $bare = true, array $options = array())
6363
/**
6464
* Clone a repository to a local path.
6565
*
66-
* @param string $path indicates where to clone repository
67-
* @param string $url url of repository to clone
68-
* @param boolean $bare indicates if repository should be bare or have a working copy
66+
* @param string $path indicates where to clone repository
67+
* @param string $url url of repository to clone
68+
* @param boolean $bare indicates if repository should be bare or have a working copy
6969
* @param array $options options for Repository creation
7070
*
7171
* @return Repository
@@ -80,9 +80,9 @@ public static function cloneTo($path, $url, $bare = true, array $options = array
8080
/**
8181
* Mirrors a repository (fetch all revisions, not only branches).
8282
*
83-
* @param string $path indicates where to clone repository
84-
* @param string $url url of repository to clone
85-
* @param array $options options for Repository creation
83+
* @param string $path indicates where to clone repository
84+
* @param string $url url of repository to clone
85+
* @param array $options options for Repository creation
8686
*
8787
* @return Repository
8888
*/
@@ -94,10 +94,10 @@ public static function mirrorTo($path, $url, array $options = array())
9494
/**
9595
* Internal method to launch effective ``git clone`` command.
9696
*
97-
* @param string $path indicates where to clone repository
98-
* @param string $url url of repository to clone
99-
* @param array $args arguments to be added to the command-line
100-
* @param array $options options for Repository creation
97+
* @param string $path indicates where to clone repository
98+
* @param string $url url of repository to clone
99+
* @param array $args arguments to be added to the command-line
100+
* @param array $options options for Repository creation
101101
*
102102
* @return Repository
103103
*/
@@ -120,7 +120,7 @@ private static function cloneRepository($path, $url, array $args = array(), arra
120120
$process->run();
121121

122122
if (!$process->isSuccessFul()) {
123-
throw new \RuntimeException(sprintf('Error while initializing repository: %s', $process->getErrorOutput()));
123+
throw new RuntimeException(sprintf('Error while initializing repository: %s', $process->getErrorOutput()));
124124
}
125125

126126
return new Repository($path, $options);

src/Gitonomy/Git/Blame.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
namespace Gitonomy\Git;
1414

15+
use Gitonomy\Git\Exception\InvalidArgumentException;
1516
use Gitonomy\Git\Parser\BlameParser;
1617

1718
/**
@@ -42,13 +43,13 @@ public function __construct(Repository $repository, $revision, $file, $lineRange
4243
public function getLine($number)
4344
{
4445
if ($number < 1) {
45-
throw new \InvalidArgumentException('Line number should be at least 1');
46+
throw new InvalidArgumentException('Line number should be at least 1');
4647
}
4748

4849
$lines = $this->getLines();
4950

5051
if (!isset($lines[$number])) {
51-
throw new \InvalidArgumentException('Line does not exist');
52+
throw new InvalidArgumentException('Line does not exist');
5253
}
5354

5455
return $lines[$number];

src/Gitonomy/Git/Blob.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function getHash()
6060
/**
6161
* Returns content of the blob.
6262
*
63-
* @throws RuntimeException Error occurred while getting content of blob
63+
* @throws ProcessException Error occurred while getting content of blob
6464
*/
6565
public function getContent()
6666
{

src/Gitonomy/Git/Commit.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
use Gitonomy\Git\Util\StringHelper;
1616
use Gitonomy\Git\Diff\Diff;
1717
use Gitonomy\Git\Exception\ReferenceNotFoundException;
18+
use Gitonomy\Git\Exception\InvalidArgumentException;
19+
use Gitonomy\Git\Exception\ProcessException;
1820

1921
/**
2022
* Representation of a Git commit.
@@ -131,7 +133,7 @@ public function __construct(Repository $repository, $hash)
131133
/**
132134
* Initializes the commit, which means read data about it and fill object.
133135
*
134-
* @throws RuntimeException An error occurred during read of data.
136+
* @throws ReferenceNotFoundException An error occurred during read of data.
135137
*/
136138
private function initialize()
137139
{
@@ -142,7 +144,7 @@ private function initialize()
142144
$parser = new Parser\CommitParser();
143145
try {
144146
$result = $this->repository->run('cat-file', array('commit', $this->hash));
145-
} catch (\RuntimeException $e) {
147+
} catch (ProcessException $e) {
146148
throw new ReferenceNotFoundException(sprintf('Can not find reference "%s"', $this->hash));
147149
}
148150

@@ -328,12 +330,12 @@ public function getIncludingBranches($local = true, $remote = true)
328330
} elseif (!$local && $remote) {
329331
$arguments[] = '-r';
330332
} elseif (!$local && !$remote) {
331-
throw new \InvalidArgumentException('You should a least set one argument to true');
333+
throw new InvalidArgumentException('You should a least set one argument to true');
332334
}
333335

334336
try {
335337
$result = $this->repository->run('branch', $arguments);
336-
} catch (\Exception $e) {
338+
} catch (ProcessException $e) {
337339
return array();
338340
}
339341

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
namespace Gitonomy\Git\Exception;
4+
5+
class InvalidArgumentException extends \InvalidArgumentException implements GitExceptionInterface
6+
{
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
namespace Gitonomy\Git\Exception;
4+
5+
class LogicException extends \LogicException implements GitExceptionInterface
6+
{
7+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
namespace Gitonomy\Git\Exception;
4+
5+
use Symfony\Component\Process\Process;
6+
7+
class ProcessException extends RuntimeException implements GitExceptionInterface
8+
{
9+
protected $process;
10+
11+
public function __construct(Process $process)
12+
{
13+
parent::__construct("Error while running git command:\n".
14+
$process->getCommandLine()."\n".
15+
"\n".
16+
$process->getErrorOutput()
17+
);
18+
19+
$this->process = $process;
20+
}
21+
22+
public function getErrorOutput()
23+
{
24+
return $this->process->getErrorOutput();
25+
}
26+
27+
public function getOutput()
28+
{
29+
return $this->process->getOutput();
30+
}
31+
}

src/Gitonomy/Git/Exception/RuntimeException.php

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,6 @@
22

33
namespace Gitonomy\Git\Exception;
44

5-
use Symfony\Component\Process\Process;
6-
75
class RuntimeException extends \RuntimeException implements GitExceptionInterface
86
{
9-
protected $process;
10-
11-
public function __construct(Process $process)
12-
{
13-
parent::__construct("Error while running git command:\n".
14-
$process->getCommandLine()."\n".
15-
"\n".
16-
$process->getErrorOutput()
17-
);
18-
19-
$this->process = $process;
20-
}
21-
22-
public function getErrorOutput()
23-
{
24-
return $this->process->getErrorOutput();
25-
}
26-
27-
public function getOutput()
28-
{
29-
return $this->process->getOutput();
30-
}
317
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
namespace Gitonomy\Git\Exception;
4+
5+
class UnexpectedValueException extends \UnexpectedValueException implements GitExceptionInterface
6+
{
7+
}

src/Gitonomy/Git/Hooks.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212

1313
namespace Gitonomy\Git;
1414

15+
use Gitonomy\Git\Exception\InvalidArgumentException;
16+
use Gitonomy\Git\Exception\LogicException;
17+
1518
/**
1619
* Hooks collection, aggregated by repository.
1720
*
@@ -56,7 +59,7 @@ public function has($name)
5659
public function get($name)
5760
{
5861
if (!$this->has($name)) {
59-
throw new \InvalidArgumentException(sprintf('Hook named "%s" is not present', $name));
62+
throw new InvalidArgumentException(sprintf('Hook named "%s" is not present', $name));
6063
}
6164

6265
return file_get_contents($this->getPath($name));
@@ -74,12 +77,12 @@ public function get($name)
7477
public function setSymlink($name, $file)
7578
{
7679
if ($this->has($name)) {
77-
throw new \LogicException(sprintf('A hook "%s" is already defined', $name));
80+
throw new LogicException(sprintf('A hook "%s" is already defined', $name));
7881
}
7982

8083
$path = $this->getPath($name);
8184
if (false === symlink($file, $path)) {
82-
throw new \RuntimeException(sprintf('Unable to create hook "%s"', $name, $path));
85+
throw new RuntimeException(sprintf('Unable to create hook "%s"', $name, $path));
8386
}
8487
}
8588

@@ -94,7 +97,7 @@ public function setSymlink($name, $file)
9497
public function set($name, $content)
9598
{
9699
if ($this->has($name)) {
97-
throw new \LogicException(sprintf('A hook "%s" is already defined', $name));
100+
throw new LogicException(sprintf('A hook "%s" is already defined', $name));
98101
}
99102

100103
$path = $this->getPath($name);
@@ -112,7 +115,7 @@ public function set($name, $content)
112115
public function remove($name)
113116
{
114117
if (!$this->has($name)) {
115-
throw new \LogicException(sprintf('The hook "%s" was not found', $name));
118+
throw new LogicException(sprintf('The hook "%s" was not found', $name));
116119
}
117120

118121
unlink($this->getPath($name));

0 commit comments

Comments
 (0)