Skip to content

Commit 85226ef

Browse files
committed
Apply demeter's law to api classes
1 parent 172ca49 commit 85226ef

7 files changed

Lines changed: 94 additions & 66 deletions

File tree

‎lib/Github/Api.php‎

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,38 @@ abstract class Github_Api implements Github_ApiInterface
1212
* The client
1313
* @var Github_Client
1414
*/
15-
protected $client;
15+
private $client;
1616

1717
public function __construct(Github_Client $client)
1818
{
1919
$this->client = $client;
2020
}
21+
22+
/**
23+
* Call any path, GET method
24+
* Ex: $api->get('repos/show/my-username/my-repo')
25+
*
26+
* @param string $path the GitHub path
27+
* @param array $parameters GET parameters
28+
* @param array $requestOptions reconfigure the request
29+
* @return array data returned
30+
*/
31+
protected function get($path, array $parameters = array(), $requestOptions = array())
32+
{
33+
return $this->client->get($path, $parameters, $requestOptions);
34+
}
35+
36+
/**
37+
* Call any path, POST method
38+
* Ex: $api->post('repos/show/my-username', array('email' => 'my-new-email@provider.org'))
39+
*
40+
* @param string $path the GitHub path
41+
* @param array $parameters POST parameters
42+
* @param array $requestOptions reconfigure the request
43+
* @return array data returned
44+
*/
45+
protected function post($path, array $parameters = array(), $requestOptions = array())
46+
{
47+
return $this->client->post($path, $parameters, $requestOptions);
48+
}
2149
}

‎lib/Github/Api/Commit.php‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class Github_Api_Commit extends Github_Api
2121
*/
2222
public function getBranchCommits($username, $repo, $branch)
2323
{
24-
$response = $this->client->get('commits/list/'.urlencode($username).'/'.urlencode($repo).'/'.urlencode($branch));
24+
$response = $this->get('commits/list/'.urlencode($username).'/'.urlencode($repo).'/'.urlencode($branch));
2525

2626
return $response['commits'];
2727
}
@@ -38,7 +38,7 @@ public function getBranchCommits($username, $repo, $branch)
3838
*/
3939
public function getFileCommits($username, $repo, $branch, $path)
4040
{
41-
$response = $this->client->get('commits/list/'.urlencode($username).'/'.urlencode($repo).'/'.urlencode($branch).'/'.urlencode($path));
41+
$response = $this->get('commits/list/'.urlencode($username).'/'.urlencode($repo).'/'.urlencode($branch).'/'.urlencode($path));
4242

4343
return $response['commits'];
4444
}
@@ -53,7 +53,7 @@ public function getFileCommits($username, $repo, $branch, $path)
5353
*/
5454
public function getCommit($username, $repo, $sha)
5555
{
56-
$response = $this->client->get('commits/show/'.urlencode($username).'/'.urlencode($repo).'/'.urlencode($sha));
56+
$response = $this->get('commits/show/'.urlencode($username).'/'.urlencode($repo).'/'.urlencode($sha));
5757

5858
return $response['commit'];
5959
}

‎lib/Github/Api/Issue.php‎

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class Github_Api_Issue extends Github_Api
2020
*/
2121
public function getList($username, $repo, $state = 'open')
2222
{
23-
$response = $this->client->get('issues/list/'.urlencode($username).'/'.urlencode($repo).'/'.urlencode($state));
23+
$response = $this->get('issues/list/'.urlencode($username).'/'.urlencode($repo).'/'.urlencode($state));
2424

2525
return $response['issues'];
2626
}
@@ -37,7 +37,7 @@ public function getList($username, $repo, $state = 'open')
3737
*/
3838
public function search($username, $repo, $state, $searchTerm)
3939
{
40-
$response = $this->client->get('issues/search/'.urlencode($username).'/'.urlencode($repo).'/'.urlencode($state).'/'.urlencode($searchTerm));
40+
$response = $this->get('issues/search/'.urlencode($username).'/'.urlencode($repo).'/'.urlencode($state).'/'.urlencode($searchTerm));
4141

4242
return $response['issues'];
4343
}
@@ -52,7 +52,7 @@ public function search($username, $repo, $state, $searchTerm)
5252
*/
5353
public function searchLabel($username, $repo, $label)
5454
{
55-
$response = $this->client->get('issues/list/'.urlencode($username).'/'.urlencode($repo).'/label/'.urlencode($label));
55+
$response = $this->get('issues/list/'.urlencode($username).'/'.urlencode($repo).'/label/'.urlencode($label));
5656

5757
return $response['issues'];
5858
}
@@ -68,7 +68,7 @@ public function searchLabel($username, $repo, $label)
6868
*/
6969
public function show($username, $repo, $issueNumber)
7070
{
71-
$response = $this->client->get('issues/show/'.urlencode($username).'/'.urlencode($repo).'/'.urlencode($issueNumber));
71+
$response = $this->get('issues/show/'.urlencode($username).'/'.urlencode($repo).'/'.urlencode($issueNumber));
7272

7373
return $response['issue'];
7474
}
@@ -86,7 +86,7 @@ public function show($username, $repo, $issueNumber)
8686
*/
8787
public function open($username, $repo, $issueTitle, $issueBody)
8888
{
89-
$response = $this->client->post('issues/open/'.urlencode($username).'/'.urlencode($repo), array(
89+
$response = $this->post('issues/open/'.urlencode($username).'/'.urlencode($repo), array(
9090
'title' => $issueTitle,
9191
'body' => $issueBody
9292
));
@@ -105,7 +105,7 @@ public function open($username, $repo, $issueTitle, $issueBody)
105105
*/
106106
public function close($username, $repo, $issueNumber)
107107
{
108-
$response = $this->client->post('issues/close/'.urlencode($username).'/'.urlencode($repo).'/'.urlencode($issueNumber));
108+
$response = $this->post('issues/close/'.urlencode($username).'/'.urlencode($repo).'/'.urlencode($issueNumber));
109109

110110
return $response['issue'];
111111
}
@@ -123,7 +123,7 @@ public function close($username, $repo, $issueNumber)
123123
*/
124124
public function update($username, $repo, $issueNumber, array $data)
125125
{
126-
$response = $this->client->post('issues/edit/'.urlencode($username).'/'.urlencode($repo).'/'.urlencode($issueNumber), $data);
126+
$response = $this->post('issues/edit/'.urlencode($username).'/'.urlencode($repo).'/'.urlencode($issueNumber), $data);
127127

128128
return $response['issue'];
129129
}
@@ -139,7 +139,7 @@ public function update($username, $repo, $issueNumber, array $data)
139139
*/
140140
public function reOpen($username, $repo, $issueNumber)
141141
{
142-
$response = $this->client->post('issues/reopen/'.urlencode($username).'/'.urlencode($repo).'/'.urlencode($issueNumber));
142+
$response = $this->post('issues/reopen/'.urlencode($username).'/'.urlencode($repo).'/'.urlencode($issueNumber));
143143

144144
return $response['issue'];
145145
}
@@ -155,7 +155,7 @@ public function reOpen($username, $repo, $issueNumber)
155155
*/
156156
public function getComments($username, $repo, $issueNumber)
157157
{
158-
$response = $this->client->get('issues/comments/'.urlencode($username).'/'.urlencode($repo).'/'.urlencode($issueNumber));
158+
$response = $this->get('issues/comments/'.urlencode($username).'/'.urlencode($repo).'/'.urlencode($issueNumber));
159159

160160
return $response['comments'];
161161
}
@@ -172,7 +172,7 @@ public function getComments($username, $repo, $issueNumber)
172172
*/
173173
public function addComment($username, $repo, $issueNumber, $commentBody)
174174
{
175-
$response = $this->client->post('issues/comment/'.urlencode($username).'/'.urlencode($repo).'/'.urlencode($issueNumber), array(
175+
$response = $this->post('issues/comment/'.urlencode($username).'/'.urlencode($repo).'/'.urlencode($issueNumber), array(
176176
'comment' => $commentBody
177177
));
178178

@@ -189,7 +189,7 @@ public function addComment($username, $repo, $issueNumber, $commentBody)
189189
*/
190190
public function getLabels($username, $repo)
191191
{
192-
$response = $this->client->get('issues/labels/'.urlencode($username).'/'.urlencode($repo));
192+
$response = $this->get('issues/labels/'.urlencode($username).'/'.urlencode($repo));
193193

194194
return $response['labels'];
195195
}
@@ -206,7 +206,7 @@ public function getLabels($username, $repo)
206206
*/
207207
public function addLabel($username, $repo, $labelName, $issueNumber)
208208
{
209-
$response = $this->client->post('issues/label/add/'.urlencode($username).'/'.urlencode($repo).'/'.urlencode($labelName).'/'.urlencode($issueNumber));
209+
$response = $this->post('issues/label/add/'.urlencode($username).'/'.urlencode($repo).'/'.urlencode($labelName).'/'.urlencode($issueNumber));
210210

211211
return $response['labels'];
212212
}
@@ -223,7 +223,7 @@ public function addLabel($username, $repo, $labelName, $issueNumber)
223223
*/
224224
public function removeLabel($username, $repo, $labelName, $issueNumber)
225225
{
226-
$response = $this->client->post('issues/label/remove/'.urlencode($username).'/'.urlencode($repo).'/'.urlencode($labelName).'/'.urlencode($issueNumber));
226+
$response = $this->post('issues/label/remove/'.urlencode($username).'/'.urlencode($repo).'/'.urlencode($labelName).'/'.urlencode($issueNumber));
227227

228228
return $response['labels'];
229229
}

‎lib/Github/Api/Object.php‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class Github_Api_Object extends Github_Api
2020
*/
2121
public function showTree($username, $repo, $treeSHA)
2222
{
23-
$response = $this->client->get('tree/show/'.urlencode($username).'/'.urlencode($repo).'/'.urlencode($treeSHA));
23+
$response = $this->get('tree/show/'.urlencode($username).'/'.urlencode($repo).'/'.urlencode($treeSHA));
2424

2525
return $response['tree'];
2626
}
@@ -37,7 +37,7 @@ public function showTree($username, $repo, $treeSHA)
3737
*/
3838
public function listBlobs($username, $repo, $treeSHA)
3939
{
40-
$response = $this->client->get('blob/all/'.urlencode($username).'/'.urlencode($repo).'/'.urlencode($treeSHA));
40+
$response = $this->get('blob/all/'.urlencode($username).'/'.urlencode($repo).'/'.urlencode($treeSHA));
4141

4242
return $response['blobs'];
4343
}
@@ -54,7 +54,7 @@ public function listBlobs($username, $repo, $treeSHA)
5454
*/
5555
public function showBlob($username, $repo, $treeSHA, $path)
5656
{
57-
$response = $this->client->get('blob/show/'.urlencode($username).'/'.urlencode($repo).'/'.urlencode($treeSHA).'/'.urlencode($path));
57+
$response = $this->get('blob/show/'.urlencode($username).'/'.urlencode($repo).'/'.urlencode($treeSHA).'/'.urlencode($path));
5858

5959
return $response['blob'];
6060
}
@@ -70,7 +70,7 @@ public function showBlob($username, $repo, $treeSHA, $path)
7070
*/
7171
public function getRawData($username, $repo, $objectSHA)
7272
{
73-
$response = $this->client->get('blob/show/'.urlencode($username).'/'.urlencode($repo).'/'.urlencode($objectSHA), array(), array(
73+
$response = $this->get('blob/show/'.urlencode($username).'/'.urlencode($repo).'/'.urlencode($objectSHA), array(), array(
7474
'format' => 'text'
7575
));
7676

‎lib/Github/Api/Organization.php‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class Github_Api_Organization extends Github_Api
2929
*/
3030
public function show($name)
3131
{
32-
$response = $this->client->get('organizations/'.urlencode($name));
32+
$response = $this->get('organizations/'.urlencode($name));
3333

3434
return $response['organization'];
3535
}
@@ -43,7 +43,7 @@ public function show($name)
4343
*/
4444
public function getAllRepos($name)
4545
{
46-
$response = $this->client->get('organizations/repositories');
46+
$response = $this->get('organizations/repositories');
4747

4848
return $response['repositories'];
4949
}
@@ -57,7 +57,7 @@ public function getAllRepos($name)
5757
*/
5858
public function getPublicRepos($name)
5959
{
60-
$response = $this->client->get('organizations/'.urlencode($name).'/public_repositories');
60+
$response = $this->get('organizations/'.urlencode($name).'/public_repositories');
6161

6262
return $response['repositories'];
6363
}
@@ -71,7 +71,7 @@ public function getPublicRepos($name)
7171
*/
7272
public function getPublicMembers($name)
7373
{
74-
$response = $this->client->get('organizations/'.urlencode($name).'/public_members');
74+
$response = $this->get('organizations/'.urlencode($name).'/public_members');
7575

7676
return $response['users'];
7777
}
@@ -85,7 +85,7 @@ public function getPublicMembers($name)
8585
*/
8686
public function getTeams($name)
8787
{
88-
$response = $this->client->get('organizations/'.urlencode($name).'/teams');
88+
$response = $this->get('organizations/'.urlencode($name).'/teams');
8989

9090
return $response['teams'];
9191
}
@@ -107,7 +107,7 @@ public function addTeam($organization, $team, $permission, array $repositories =
107107
throw new InvalidArgumentException("Invalid value for the permission variable");
108108
}
109109

110-
$response = $this->client->post('organizations/'.urlencode($organization).'/teams', array(
110+
$response = $this->post('organizations/'.urlencode($organization).'/teams', array(
111111
'team' => $team,
112112
'permission' => $permission,
113113
'repo_names' => $repositories

0 commit comments

Comments
 (0)