Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,14 @@ cache:
- $HOME/.composer/cache

php:
- 5.6
- 7.0
- 7.1

matrix:
include:
- php: hhvm
dist: trusty
- 7.2

sudo: false

install:
- travis_retry composer install --no-interaction
- composer install --no-interaction

script:
- vendor/bin/phpunit --verbose --coverage-text
10 changes: 7 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
}
],
"require": {
"php": "^5.6 || ^7.0",
"php": "^7.0",
"psr/http-message": "^1.0",
"psr/cache": "^1.0",
"php-http/httplug": "^1.1",
Expand All @@ -35,10 +35,14 @@
"cache/array-adapter": "^0.4"
},
"autoload": {
"psr-4": { "Github\\": "lib/Github/" }
"psr-4": {
"Github\\": "lib/Github/"
}
},
"autoload-dev": {
"psr-4": { "Github\\Tests\\": "test/Github/Tests/"}
"psr-4": {
"Github\\Tests\\": "test/Github/Tests/"
}
},
"minimum-stability": "dev",
"prefer-stable": true,
Expand Down
2 changes: 1 addition & 1 deletion doc/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class CommentsTest extends TestCase
$this->assertEquals($expectedValue, $result);
}

protected function getApiClass()
protected function getApiClass(): string
{
// Tell the "getAPIMock" what class to mock.
return \Github\Api\Gist\Comments::class;
Expand Down
24 changes: 9 additions & 15 deletions lib/Github/Api/AbstractApi.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);

namespace Github\Api;

Expand Down Expand Up @@ -26,9 +26,6 @@ abstract class AbstractApi implements ApiInterface
*/
protected $perPage;

/**
* @param Client $client
*/
public function __construct(Client $client)
{
$this->client = $client;
Expand All @@ -46,10 +43,7 @@ public function getPerPage()
return $this->perPage;
}

/**
* @param null|int $perPage
*/
public function setPerPage($perPage)
public function setPerPage(int $perPage = null)
{
$this->perPage = (null === $perPage ? $perPage : (int) $perPage);

Expand All @@ -65,7 +59,7 @@ public function setPerPage($perPage)
*
* @return array|string
*/
protected function get($path, array $parameters = array(), array $requestHeaders = array())
protected function get(string $path, array $parameters = [], array $requestHeaders = [])
{
if (null !== $this->perPage && !isset($parameters['per_page'])) {
$parameters['per_page'] = $this->perPage;
Expand All @@ -92,7 +86,7 @@ protected function get($path, array $parameters = array(), array $requestHeaders
*
* @return \Psr\Http\Message\ResponseInterface
*/
protected function head($path, array $parameters = array(), array $requestHeaders = array())
protected function head(string $path, array $parameters = [], array $requestHeaders = []): \Psr\Http\Message\ResponseInterface
{
if (array_key_exists('ref', $parameters) && is_null($parameters['ref'])) {
unset($parameters['ref']);
Expand All @@ -112,7 +106,7 @@ protected function head($path, array $parameters = array(), array $requestHeader
*
* @return array|string
*/
protected function post($path, array $parameters = array(), array $requestHeaders = array())
protected function post(string $path, array $parameters = [], array $requestHeaders = [])
{
return $this->postRaw(
$path,
Expand All @@ -130,7 +124,7 @@ protected function post($path, array $parameters = array(), array $requestHeader
*
* @return array|string
*/
protected function postRaw($path, $body, array $requestHeaders = array())
protected function postRaw(string $path, string $body, array $requestHeaders = [])
{
$response = $this->client->getHttpClient()->post(
$path,
Expand All @@ -150,7 +144,7 @@ protected function postRaw($path, $body, array $requestHeaders = array())
*
* @return array|string
*/
protected function patch($path, array $parameters = array(), array $requestHeaders = array())
protected function patch(string $path, array $parameters = [], array $requestHeaders = [])
{
$response = $this->client->getHttpClient()->patch(
$path,
Expand All @@ -170,7 +164,7 @@ protected function patch($path, array $parameters = array(), array $requestHeade
*
* @return array|string
*/
protected function put($path, array $parameters = array(), array $requestHeaders = array())
protected function put(string $path, array $parameters = [], array $requestHeaders = [])
{
$response = $this->client->getHttpClient()->put(
$path,
Expand All @@ -190,7 +184,7 @@ protected function put($path, array $parameters = array(), array $requestHeaders
*
* @return array|string
*/
protected function delete($path, array $parameters = array(), array $requestHeaders = array())
protected function delete(string $path, array $parameters = [], array $requestHeaders = [])
{
$response = $this->client->getHttpClient()->delete(
$path,
Expand Down
24 changes: 13 additions & 11 deletions lib/Github/Api/AcceptHeaderTrait.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<?php
<?php declare(strict_types=1);

namespace Github\Api;

use Psr\Http\Message\ResponseInterface;

/**
* A trait to make sure we add accept headers on all requests.
*
Expand All @@ -11,37 +13,37 @@ trait AcceptHeaderTrait
{
protected $acceptHeaderValue = null;

protected function get($path, array $parameters = array(), array $requestHeaders = array())
protected function get(string $path, array $parameters = [], array $requestHeaders = [])
{
return parent::get($path, $parameters, $this->mergeHeaders($requestHeaders));
}

protected function head($path, array $parameters = array(), array $requestHeaders = array())
protected function head(string $path, array $parameters = [], array $requestHeaders = []): ResponseInterface
{
return parent::head($path, $parameters, $this->mergeHeaders($requestHeaders));
}

protected function post($path, array $parameters = array(), array $requestHeaders = array())
protected function post(string $path, array $parameters = [], array $requestHeaders = [])
{
return parent::post($path, $parameters, $this->mergeHeaders($requestHeaders));
}

protected function postRaw($path, $body, array $requestHeaders = array())
protected function postRaw(string $path, string $body, array $requestHeaders = [])
{
return parent::postRaw($path, $body, $this->mergeHeaders($requestHeaders));
}

protected function patch($path, array $parameters = array(), array $requestHeaders = array())
protected function patch(string $path, array $parameters = [], array $requestHeaders = [])
{
return parent::patch($path, $parameters, $this->mergeHeaders($requestHeaders));
}

protected function put($path, array $parameters = array(), array $requestHeaders = array())
protected function put(string $path, array $parameters = [], array $requestHeaders = [])
{
return parent::put($path, $parameters, $this->mergeHeaders($requestHeaders));
}

protected function delete($path, array $parameters = array(), array $requestHeaders = array())
protected function delete(string $path, array $parameters = [], array $requestHeaders = [])
{
return parent::delete($path, $parameters, $this->mergeHeaders($requestHeaders));
}
Expand All @@ -50,11 +52,11 @@ protected function delete($path, array $parameters = array(), array $requestHead
* Append a new accept header on all requests
* @return array
*/
private function mergeHeaders(array $headers = array())
private function mergeHeaders(array $headers = []): array
{
$default = array();
$default = [];
if ($this->acceptHeaderValue) {
$default = array('Accept' => $this->acceptHeaderValue);
$default = ['Accept' => $this->acceptHeaderValue];
}

return array_merge($default, $headers);
Expand Down
4 changes: 2 additions & 2 deletions lib/Github/Api/ApiInterface.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);

namespace Github\Api;

Expand All @@ -11,5 +11,5 @@ interface ApiInterface
{
public function getPerPage();

public function setPerPage($perPage);
public function setPerPage(int $perPage = null);
}
32 changes: 8 additions & 24 deletions lib/Github/Api/Apps.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);

namespace Github\Api;

Expand All @@ -17,9 +17,9 @@ class Apps extends AbstractApi
*
* @return array token and token metadata
*/
public function createInstallationToken($installationId, $userId = null)
public function createInstallationToken(int $installationId, int $userId = null): array
{
$parameters = array();
$parameters = [];
if ($userId) {
$parameters['user_id'] = $userId;
}
Expand All @@ -31,10 +31,8 @@ public function createInstallationToken($installationId, $userId = null)
* Find all installations for the authenticated application.
*
* @link https://developer.github.com/v3/apps/#find-installations
*
* @return array
*/
public function findInstallations()
public function findInstallations(): array
{
return $this->get('/app/installations');
}
Expand All @@ -43,14 +41,10 @@ public function findInstallations()
* List repositories that are accessible to the authenticated installation.
*
* @link https://developer.github.com/v3/apps/installations/#list-repositories
*
* @param int $userId
*
* @return array
*/
public function listRepositories($userId = null)
public function listRepositories(int $userId = null): array
{
$parameters = array();
$parameters = [];
if ($userId) {
$parameters['user_id'] = $userId;
}
Expand All @@ -62,13 +56,8 @@ public function listRepositories($userId = null)
* Add a single repository to an installation.
*
* @link https://developer.github.com/v3/apps/installations/#add-repository-to-installation
*
* @param int $installationId
* @param int $repositoryId
*
* @return array
*/
public function addRepository($installationId, $repositoryId)
public function addRepository(int $installationId, int $repositoryId): array
{
return $this->put('/installations/'.rawurlencode($installationId).'/repositories/'.rawurlencode($repositoryId));
}
Expand All @@ -77,13 +66,8 @@ public function addRepository($installationId, $repositoryId)
* Remove a single repository from an installation.
*
* @link https://developer.github.com/v3/apps/installations/#remove-repository-from-installation
*
* @param int $installationId
* @param int $repositoryId
*
* @return array
*/
public function removeRepository($installationId, $repositoryId)
public function removeRepository(int $installationId, int $repositoryId): array
{
return $this->delete('/installations/'.rawurlencode($installationId).'/repositories/'.rawurlencode($repositoryId));
}
Expand Down
Loading