Skip to content
Browse files

Abstracted away getGitHubClosedIssueCount() and getGitHubOpenIssueCou…

…nt() into getGitHubIssueCount($state).
  • Loading branch information...
1 parent f14aca5 commit 647e5f57a7c2a6fd89b03197edc8fe0aff1b279f @boenrobot boenrobot committed Aug 9, 2012
Showing with 11 additions and 26 deletions.
  1. +11 −26 src/PEAR2Web/Models/Package.php
View
37 src/PEAR2Web/Models/Package.php
@@ -39,16 +39,16 @@ public function getGitHubClosedIssuesLink()
{
return self::GIT_HUB_LINK . $this->shortName . '/issues?state=closed';
}
-
- public function getGitHubClosedIssueCount()
+
+ public function getGitHubIssueCount($state)
{
$count = 0;
- $key = $this->name.'-closed-issues';
+ $key = $this->name."-{$state}-issues";
$json = $this->cache->get($key);
if ($json === false) {
- $uri = self::GIT_HUB_API . $this->shortName . '/issues?state=closed';
+ $uri = self::GIT_HUB_API . $this->shortName . '/issues?state=' . $state;
$json = file_get_contents($uri);
if ($json === false) {
$json = $this->cache->get($key, 'default', false);
@@ -58,34 +58,19 @@ public function getGitHubClosedIssueCount()
}
if ($json !== false) {
- $result = json_decode($json);
- $count = count($result->issues);
+ $count = count(json_decode($json));
}
return $count;
}
- public function getGitHubOpenIssueCount()
+ public function getGitHubClosedIssueCount()
{
- $count = 0;
-
- $key = $this->name.'-open-issues';
- $json = $this->cache->get($key);
-
- if ($json === false) {
- $uri = self::GIT_HUB_API . $this->shortName . '/issues?state=open';
- $json = file_get_contents($uri);
- if ($json === false) {
- $json = $this->cache->get($key, 'default', false);
- } else {
- $this->cache->save($json, $key);
- }
- }
-
- if ($json !== false) {
- $count = count(json_decode($json));
- }
+ return $this->getGitHubIssueCount('closed');
+ }
- return $count;
+ public function getGitHubOpenIssueCount()
+ {
+ return $this->getGitHubIssueCount('open');
}
}

0 comments on commit 647e5f5

Please sign in to comment.
Something went wrong with that request. Please try again.