From 25ed24915ac254879e4bdb930be70d5253dc8121 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bruno=20=C5=A0kvorc?= Date: Mon, 6 Feb 2017 13:57:47 +0100 Subject: [PATCH 1/2] 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'); ``` --- lib/Github/Api/Repository/Stargazers.php | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/Github/Api/Repository/Stargazers.php b/lib/Github/Api/Repository/Stargazers.php index 9267dff4fbd..a246606e1aa 100644 --- a/lib/Github/Api/Repository/Stargazers.php +++ b/lib/Github/Api/Repository/Stargazers.php @@ -26,6 +26,7 @@ public function configure($bodyType = null) if ('star' === $bodyType) { $this->acceptHeaderValue = sprintf('application/vnd.github.%s.star+json', $this->client->getApiVersion()); } + return $this; } public function all($username, $repository) From 0ae186e7f3264258c5bac1b77c45f1bbe95c5721 Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Sat, 25 Mar 2017 16:16:01 +0100 Subject: [PATCH 2/2] Make all configure methods chainable --- lib/Github/Api/GitData/Blobs.php | 4 ++++ lib/Github/Api/Issue/Comments.php | 4 ++++ lib/Github/Api/Project/AbstractProjectApi.php | 4 ++++ lib/Github/Api/Project/Cards.php | 4 ++++ lib/Github/Api/Project/Columns.php | 4 ++++ lib/Github/Api/Repository/Comments.php | 7 +++++++ lib/Github/Api/Repository/Stargazers.php | 3 +++ 7 files changed, 30 insertions(+) diff --git a/lib/Github/Api/GitData/Blobs.php b/lib/Github/Api/GitData/Blobs.php index b8abb415193..0cc980fef14 100644 --- a/lib/Github/Api/GitData/Blobs.php +++ b/lib/Github/Api/GitData/Blobs.php @@ -19,12 +19,16 @@ class Blobs extends AbstractApi * Configure the Accept header depending on the blob type. * * @param string|null $bodyType + * + * @return self */ public function configure($bodyType = null) { if ('raw' === $bodyType) { $this->acceptHeaderValue = sprintf('application/vnd.github.%s.raw', $this->client->getApiVersion()); } + + return $this; } /** diff --git a/lib/Github/Api/Issue/Comments.php b/lib/Github/Api/Issue/Comments.php index e72b964f02e..c860c74d64e 100644 --- a/lib/Github/Api/Issue/Comments.php +++ b/lib/Github/Api/Issue/Comments.php @@ -20,6 +20,8 @@ class Comments extends AbstractApi * * @link https://developer.github.com/v3/issues/comments/#custom-media-types * @param string|null $bodyType + * + * @return self */ public function configure($bodyType = null) { @@ -28,6 +30,8 @@ public function configure($bodyType = null) } $this->acceptHeaderValue = sprintf('application/vnd.github.%s.%s+json', $this->client->getApiVersion(), $bodyType); + + return $this; } /** diff --git a/lib/Github/Api/Project/AbstractProjectApi.php b/lib/Github/Api/Project/AbstractProjectApi.php index 55bc733424f..b64f1ca19b1 100644 --- a/lib/Github/Api/Project/AbstractProjectApi.php +++ b/lib/Github/Api/Project/AbstractProjectApi.php @@ -13,10 +13,14 @@ abstract class AbstractProjectApi extends AbstractApi * Configure the accept header for Early Access to the projects api * * @see https://developer.github.com/v3/repos/projects/#projects + * + * @return self */ public function configure() { $this->acceptHeaderValue = 'application/vnd.github.inertia-preview+json'; + + return $this; } public function show($id, array $params = array()) diff --git a/lib/Github/Api/Project/Cards.php b/lib/Github/Api/Project/Cards.php index 65765b75907..61eca191040 100644 --- a/lib/Github/Api/Project/Cards.php +++ b/lib/Github/Api/Project/Cards.php @@ -14,10 +14,14 @@ class Cards extends AbstractApi * Configure the accept header for Early Access to the projects api * * @see https://developer.github.com/v3/repos/projects/#projects + * + * @return self */ public function configure() { $this->acceptHeaderValue = 'application/vnd.github.inertia-preview+json'; + + return $this; } public function all($columnId, array $params = array()) diff --git a/lib/Github/Api/Project/Columns.php b/lib/Github/Api/Project/Columns.php index 16b9f25c327..76c555979bd 100644 --- a/lib/Github/Api/Project/Columns.php +++ b/lib/Github/Api/Project/Columns.php @@ -14,10 +14,14 @@ class Columns extends AbstractApi * Configure the accept header for Early Access to the projects api * * @see https://developer.github.com/v3/repos/projects/#projects + * + * return self */ public function configure() { $this->acceptHeaderValue = 'application/vnd.github.inertia-preview+json'; + + return $this; } public function all($projectId, array $params = array()) diff --git a/lib/Github/Api/Repository/Comments.php b/lib/Github/Api/Repository/Comments.php index b1d9abe7cbe..2827ee8ad5f 100644 --- a/lib/Github/Api/Repository/Comments.php +++ b/lib/Github/Api/Repository/Comments.php @@ -15,6 +15,11 @@ class Comments extends AbstractApi { use AcceptHeaderTrait; + /** + * @param string|null $bodyType + * + * @return self + */ public function configure($bodyType = null) { switch ($bodyType) { @@ -35,6 +40,8 @@ public function configure($bodyType = null) } $this->acceptHeaderValue = $header; + + return $this; } public function all($username, $repository, $sha = null) diff --git a/lib/Github/Api/Repository/Stargazers.php b/lib/Github/Api/Repository/Stargazers.php index a246606e1aa..5a298b717db 100644 --- a/lib/Github/Api/Repository/Stargazers.php +++ b/lib/Github/Api/Repository/Stargazers.php @@ -20,12 +20,15 @@ class Stargazers extends AbstractApi * @see https://developer.github.com/v3/activity/starring/#alternative-response-with-star-creation-timestamps * * @param string $bodyType + * + * @return self */ public function configure($bodyType = null) { if ('star' === $bodyType) { $this->acceptHeaderValue = sprintf('application/vnd.github.%s.star+json', $this->client->getApiVersion()); } + return $this; }