Skip to content

Commit

Permalink
[TASK] Make code throw custom NumerologExceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
NamelessCoder committed Sep 6, 2015
1 parent 84e023a commit fd2a22d
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/AccessException.php
Expand Up @@ -4,6 +4,6 @@
/**
* Class AccessException
*/
class AccessException extends \RuntimeException {
class AccessException extends NumerologException {

}
5 changes: 4 additions & 1 deletion src/Client.php
Expand Up @@ -35,7 +35,10 @@ public function query(Query $query) {
$body = file_get_contents($this->getEndpointUrl() . $query->toQueryString());
$decoded = json_decode($body, JSON_OBJECT_AS_ARRAY);
if (NULL === $decoded) {
throw new \RuntimeException($body);
throw new NumerologException($body);
}
if (!empty($decoded['error'])) {
throw new NumerologException($decoded['error']);
}
return $decoded;
}
Expand Down
6 changes: 3 additions & 3 deletions src/Database.php
Expand Up @@ -102,7 +102,7 @@ public function query(Query $query) {
$result = $this->saveValue($packageName, $counterName, $value);
break;
default:
throw new \RuntimeException(sprintf('Invalid Numerolog action: %s', $action));
throw new NumerologException(sprintf('Invalid Numerolog action: %s', $action));
}
$response = array(
'values' => $result
Expand All @@ -114,13 +114,13 @@ public function query(Query $query) {
// return only the indicated sub-set of statistics
$poll = $query->getPoll();
if (empty($poll)) {
throw new \RuntimeException('Poll command used with empty poll argument');
throw new NumerologException('Poll command used with empty poll argument');
} elseif (isset($response[$poll])) {
$response = $response[$poll];
} elseif (isset($response['statistics'][$poll])) {
$response = $response['statistics'][$poll];
} else {
throw new \RuntimeException(sprintf('Invalid polling data requested: %s', $poll));
throw new NumerologException(sprintf('Invalid polling data requested: %s', $poll));
}
} else {
$response['querytime'] = round(((microtime(TRUE) - $time) * 1000), 5);
Expand Down
2 changes: 1 addition & 1 deletion src/NotFoundException.php
Expand Up @@ -4,6 +4,6 @@
/**
* Class NotFoundException
*/
class NotFoundException extends \RuntimeException {
class NotFoundException extends NumerologException {

}
9 changes: 9 additions & 0 deletions src/NumerologException.php
@@ -0,0 +1,9 @@
<?php
namespace NamelessCoder\Numerolog;

/**
* Class NumerologException
*/
class NumerologException extends \RuntimeException {

}

0 comments on commit fd2a22d

Please sign in to comment.