Skip to content

Commit 93c5d19

Browse files
authored
Merge pull request #765 from acrobat/code-improvement-static-code-analysis
Code improvements found with code analysis
2 parents 346099c + 4b83145 commit 93c5d19

File tree

10 files changed

+23
-23
lines changed

10 files changed

+23
-23
lines changed

lib/Github/Api/AbstractApi.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ protected function get($path, array $parameters = [], array $requestHeaders = []
9898
if (null !== $this->perPage && !isset($parameters['per_page'])) {
9999
$parameters['per_page'] = $this->perPage;
100100
}
101-
if (array_key_exists('ref', $parameters) && is_null($parameters['ref'])) {
101+
if (array_key_exists('ref', $parameters) && null === $parameters['ref']) {
102102
unset($parameters['ref']);
103103
}
104104

@@ -122,7 +122,7 @@ protected function get($path, array $parameters = [], array $requestHeaders = []
122122
*/
123123
protected function head($path, array $parameters = [], array $requestHeaders = [])
124124
{
125-
if (array_key_exists('ref', $parameters) && is_null($parameters['ref'])) {
125+
if (array_key_exists('ref', $parameters) && null === $parameters['ref']) {
126126
unset($parameters['ref']);
127127
}
128128

lib/Github/Api/AcceptHeaderTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*/
1010
trait AcceptHeaderTrait
1111
{
12-
protected $acceptHeaderValue = null;
12+
protected $acceptHeaderValue;
1313

1414
protected function get($path, array $parameters = [], array $requestHeaders = [])
1515
{

lib/Github/Api/CurrentUser/Emails.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function add($emails)
5252
if (is_string($emails)) {
5353
$emails = [$emails];
5454
} elseif (0 === count($emails)) {
55-
throw new InvalidArgumentException();
55+
throw new InvalidArgumentException('The user emails parameter should be a single email or an array of emails');
5656
}
5757

5858
return $this->post('/user/emails', $emails);
@@ -74,7 +74,7 @@ public function remove($emails)
7474
if (is_string($emails)) {
7575
$emails = [$emails];
7676
} elseif (0 === count($emails)) {
77-
throw new InvalidArgumentException();
77+
throw new InvalidArgumentException('The user emails parameter should be a single email or an array of emails');
7878
}
7979

8080
return $this->delete('/user/emails', $emails);

lib/Github/Api/Gists.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class Gists extends AbstractApi
2828
*/
2929
public function configure($bodyType = null)
3030
{
31-
if (!in_array($bodyType, ['base64'])) {
31+
if ('base64' !== $bodyType) {
3232
$bodyType = 'raw';
3333
}
3434

lib/Github/Api/Issue/Labels.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,10 @@ public function update($username, $repository, $label, $newName, $color)
120120
*
121121
* @link https://developer.github.com/v3/issues/labels/#remove-a-label-from-an-issue
122122
*
123-
* @param string $username
124-
* @param string $repository
125-
* @param int $issue
126-
* @param string $labels
123+
* @param string $username
124+
* @param string $repository
125+
* @param int $issue
126+
* @param string|array $labels
127127
*
128128
* @return array
129129
*
@@ -134,7 +134,7 @@ public function add($username, $repository, $issue, $labels)
134134
if (is_string($labels)) {
135135
$labels = [$labels];
136136
} elseif (0 === count($labels)) {
137-
throw new InvalidArgumentException();
137+
throw new InvalidArgumentException('The labels parameter should be a single label or an array of labels');
138138
}
139139

140140
return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($issue).'/labels', $labels);

lib/Github/Api/PullRequest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class PullRequest extends AbstractApi
3131
*/
3232
public function configure($bodyType = null, $apiVersion = null)
3333
{
34-
if (!in_array($apiVersion, [])) {
34+
if (null === $apiVersion) {
3535
$apiVersion = $this->client->getApiVersion();
3636
}
3737

lib/Github/Api/PullRequest/Comments.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class Comments extends AbstractApi
2727
*/
2828
public function configure($bodyType = null, $apiVersion = null)
2929
{
30-
if (!in_array($apiVersion, ['squirrel-girl-preview'])) {
30+
if ($apiVersion !== 'squirrel-girl-preview') {
3131
$apiVersion = $this->client->getApiVersion();
3232
}
3333

lib/Github/Api/Repository/Contents.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ public function exists($username, $repository, $path, $reference = null)
143143
'ref' => $reference,
144144
]);
145145

146-
if ($response->getStatusCode() != 200) {
146+
if ($response->getStatusCode() !== 200) {
147147
return false;
148148
}
149149
} catch (TwoFactorAuthenticationRequiredException $ex) {

lib/Github/Client.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ public function authenticate($tokenOrLogin, $password = null, $authMethod = null
322322
throw new InvalidArgumentException('You need to specify authentication method!');
323323
}
324324

325-
if (null === $authMethod && in_array($password, [self::AUTH_URL_TOKEN, self::AUTH_URL_CLIENT_ID, self::AUTH_HTTP_PASSWORD, self::AUTH_HTTP_TOKEN, self::AUTH_JWT])) {
325+
if (null === $authMethod && in_array($password, [self::AUTH_URL_TOKEN, self::AUTH_URL_CLIENT_ID, self::AUTH_HTTP_PASSWORD, self::AUTH_HTTP_TOKEN, self::AUTH_JWT], true)) {
326326
$authMethod = $password;
327327
$password = null;
328328
}

lib/Github/HttpClient/Plugin/GithubExceptionThrower.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,26 +30,26 @@ public function handleRequest(RequestInterface $request, callable $next, callabl
3030

3131
// If error:
3232
$remaining = ResponseMediator::getHeader($response, 'X-RateLimit-Remaining');
33-
if (null != $remaining && 1 > $remaining && 'rate_limit' !== substr($request->getRequestTarget(), 1, 10)) {
33+
if (null !== $remaining && 1 > $remaining && 'rate_limit' !== substr($request->getRequestTarget(), 1, 10)) {
3434
$limit = ResponseMediator::getHeader($response, 'X-RateLimit-Limit');
3535
$reset = ResponseMediator::getHeader($response, 'X-RateLimit-Reset');
3636

3737
throw new ApiLimitExceedException($limit, $reset);
3838
}
3939

40-
if (401 === $response->getStatusCode()) {
41-
if ($response->hasHeader('X-GitHub-OTP') && 0 === strpos((string) ResponseMediator::getHeader($response, 'X-GitHub-OTP'), 'required;')) {
42-
$type = substr((string) ResponseMediator::getHeader($response, 'X-GitHub-OTP'), 9);
40+
if ((401 === $response->getStatusCode()) && $response->hasHeader('X-GitHub-OTP') && 0 === strpos((string) ResponseMediator::getHeader($response, 'X-GitHub-OTP'), 'required;')) {
41+
$type = substr((string) ResponseMediator::getHeader($response, 'X-GitHub-OTP'), 9);
4342

44-
throw new TwoFactorAuthenticationRequiredException($type);
45-
}
43+
throw new TwoFactorAuthenticationRequiredException($type);
4644
}
4745

4846
$content = ResponseMediator::getContent($response);
4947
if (is_array($content) && isset($content['message'])) {
50-
if (400 == $response->getStatusCode()) {
48+
if (400 === $response->getStatusCode()) {
5149
throw new ErrorException($content['message'], 400);
52-
} elseif (422 == $response->getStatusCode() && isset($content['errors'])) {
50+
}
51+
52+
if (422 === $response->getStatusCode() && isset($content['errors'])) {
5353
$errors = [];
5454
foreach ($content['errors'] as $error) {
5555
switch ($error['code']) {

0 commit comments

Comments
 (0)