Skip to content

Commit 9b66e47

Browse files
acrobatNyholm
authored andcommitted
Chainable/fluent configure methods (#544)
* Make chaining available in Stargazers Allows for: ```php $stargazers = $client->repo()->stargazers()->configure('star')->all('vuejs', 'vue'); ``` instead of ```php $stargazers = $client->repo()->stargazers(); $stargazers->configure('star'); $stargazers = $stargazers->all('vuejs', 'vue'); ``` * Make all configure methods chainable
1 parent 8a6d6e9 commit 9b66e47

File tree

7 files changed

+31
-0
lines changed

7 files changed

+31
-0
lines changed

lib/Github/Api/GitData/Blobs.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,16 @@ class Blobs extends AbstractApi
1919
* Configure the Accept header depending on the blob type.
2020
*
2121
* @param string|null $bodyType
22+
*
23+
* @return self
2224
*/
2325
public function configure($bodyType = null)
2426
{
2527
if ('raw' === $bodyType) {
2628
$this->acceptHeaderValue = sprintf('application/vnd.github.%s.raw', $this->client->getApiVersion());
2729
}
30+
31+
return $this;
2832
}
2933

3034
/**

lib/Github/Api/Issue/Comments.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ class Comments extends AbstractApi
2020
*
2121
* @link https://developer.github.com/v3/issues/comments/#custom-media-types
2222
* @param string|null $bodyType
23+
*
24+
* @return self
2325
*/
2426
public function configure($bodyType = null)
2527
{
@@ -28,6 +30,8 @@ public function configure($bodyType = null)
2830
}
2931

3032
$this->acceptHeaderValue = sprintf('application/vnd.github.%s.%s+json', $this->client->getApiVersion(), $bodyType);
33+
34+
return $this;
3135
}
3236

3337
/**

lib/Github/Api/Project/AbstractProjectApi.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,14 @@ abstract class AbstractProjectApi extends AbstractApi
1313
* Configure the accept header for Early Access to the projects api
1414
*
1515
* @see https://developer.github.com/v3/repos/projects/#projects
16+
*
17+
* @return self
1618
*/
1719
public function configure()
1820
{
1921
$this->acceptHeaderValue = 'application/vnd.github.inertia-preview+json';
22+
23+
return $this;
2024
}
2125

2226
public function show($id, array $params = array())

lib/Github/Api/Project/Cards.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,14 @@ class Cards extends AbstractApi
1414
* Configure the accept header for Early Access to the projects api
1515
*
1616
* @see https://developer.github.com/v3/repos/projects/#projects
17+
*
18+
* @return self
1719
*/
1820
public function configure()
1921
{
2022
$this->acceptHeaderValue = 'application/vnd.github.inertia-preview+json';
23+
24+
return $this;
2125
}
2226

2327
public function all($columnId, array $params = array())

lib/Github/Api/Project/Columns.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,14 @@ class Columns extends AbstractApi
1414
* Configure the accept header for Early Access to the projects api
1515
*
1616
* @see https://developer.github.com/v3/repos/projects/#projects
17+
*
18+
* return self
1719
*/
1820
public function configure()
1921
{
2022
$this->acceptHeaderValue = 'application/vnd.github.inertia-preview+json';
23+
24+
return $this;
2125
}
2226

2327
public function all($projectId, array $params = array())

lib/Github/Api/Repository/Comments.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ class Comments extends AbstractApi
1515
{
1616
use AcceptHeaderTrait;
1717

18+
/**
19+
* @param string|null $bodyType
20+
*
21+
* @return self
22+
*/
1823
public function configure($bodyType = null)
1924
{
2025
switch ($bodyType) {
@@ -35,6 +40,8 @@ public function configure($bodyType = null)
3540
}
3641

3742
$this->acceptHeaderValue = $header;
43+
44+
return $this;
3845
}
3946

4047
public function all($username, $repository, $sha = null)

lib/Github/Api/Repository/Stargazers.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,16 @@ class Stargazers extends AbstractApi
2020
* @see https://developer.github.com/v3/activity/starring/#alternative-response-with-star-creation-timestamps
2121
*
2222
* @param string $bodyType
23+
*
24+
* @return self
2325
*/
2426
public function configure($bodyType = null)
2527
{
2628
if ('star' === $bodyType) {
2729
$this->acceptHeaderValue = sprintf('application/vnd.github.%s.star+json', $this->client->getApiVersion());
2830
}
31+
32+
return $this;
2933
}
3034

3135
public function all($username, $repository)

0 commit comments

Comments
 (0)