Skip to content

Commit 43996f0

Browse files
kalessilbshaffer
authored andcommitted
Static Code Analysis with Php Inspections (EA Extended) (#1174)
* language level fixes * dead code dropped * one-time use variables inlined * control flow simplifications * changes code review * unnecessary parenthesises dropped * fixed CS
1 parent e430670 commit 43996f0

File tree

14 files changed

+33
-50
lines changed

14 files changed

+33
-50
lines changed

src/Google/AccessToken/Revoke.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,7 @@ public function revokeToken($token)
7272
$httpHandler = HttpHandlerFactory::build($this->http);
7373

7474
$response = $httpHandler($request);
75-
if ($response->getStatusCode() == 200) {
76-
return true;
77-
}
7875

79-
return false;
76+
return $response->getStatusCode() == 200;
8077
}
8178
}

src/Google/AccessToken/Verify.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@ public function __construct(
5353
CacheItemPoolInterface $cache = null,
5454
$jwt = null
5555
) {
56-
if (is_null($http)) {
56+
if (null === $http) {
5757
$http = new Client();
5858
}
5959

60-
if (is_null($cache)) {
60+
if (null === $cache) {
6161
$cache = new MemoryCacheItemPool;
6262
}
6363

src/Google/Client.php

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ public function refreshToken($refreshToken)
262262
*/
263263
public function fetchAccessTokenWithRefreshToken($refreshToken = null)
264264
{
265-
if (is_null($refreshToken)) {
265+
if (null === $refreshToken) {
266266
if (!isset($this->token['refresh_token'])) {
267267
throw new LogicException(
268268
'refresh token must be passed in or set as part of setAccessToken'
@@ -352,7 +352,7 @@ public function authorize(ClientInterface $http = null)
352352
$credentials = null;
353353
$token = null;
354354
$scopes = null;
355-
if (is_null($http)) {
355+
if (null === $http) {
356356
$http = $this->getHttpClient();
357357
}
358358

@@ -366,7 +366,7 @@ public function authorize(ClientInterface $http = null)
366366
} elseif ($token = $this->getAccessToken()) {
367367
$scopes = $this->prepareScopes();
368368
// add refresh subscriber to request a new token
369-
if ($this->isAccessTokenExpired() && isset($token['refresh_token'])) {
369+
if (isset($token['refresh_token']) && $this->isAccessTokenExpired()) {
370370
$credentials = $this->createUserRefreshCredentials(
371371
$scopes,
372372
$token['refresh_token']
@@ -477,10 +477,7 @@ public function isAccessTokenExpired()
477477
}
478478

479479
// If the token is set to expire in the next 30 seconds.
480-
$expired = ($created
481-
+ ($this->token['expires_in'] - 30)) < time();
482-
483-
return $expired;
480+
return ($created + ($this->token['expires_in'] - 30)) < time();
484481
}
485482

486483
public function getAuth()
@@ -598,7 +595,7 @@ public function setApplicationName($applicationName)
598595
public function setRequestVisibleActions($requestVisibleActions)
599596
{
600597
if (is_array($requestVisibleActions)) {
601-
$requestVisibleActions = join(" ", $requestVisibleActions);
598+
$requestVisibleActions = implode(" ", $requestVisibleActions);
602599
}
603600
$this->config['request_visible_actions'] = $requestVisibleActions;
604601
}
@@ -699,7 +696,7 @@ public function verifyIdToken($idToken = null)
699696
$this->config['jwt']
700697
);
701698

702-
if (is_null($idToken)) {
699+
if (null === $idToken) {
703700
$token = $this->getAccessToken();
704701
if (!isset($token['id_token'])) {
705702
throw new LogicException(
@@ -764,8 +761,8 @@ public function prepareScopes()
764761
if (empty($this->requestedScopes)) {
765762
return null;
766763
}
767-
$scopes = implode(' ', $this->requestedScopes);
768-
return $scopes;
764+
765+
return implode(' ', $this->requestedScopes);
769766
}
770767

771768
/**
@@ -1031,7 +1028,7 @@ public function setHttpClient(ClientInterface $http)
10311028
*/
10321029
public function getHttpClient()
10331030
{
1034-
if (is_null($this->http)) {
1031+
if (null === $this->http) {
10351032
$this->http = $this->createDefaultHttpClient();
10361033
}
10371034

src/Google/Collection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

33
if (!class_exists('Google_Client')) {
4-
require_once dirname(__FILE__) . '/autoload.php';
4+
require_once __DIR__ . '/autoload.php';
55
}
66

77
/**

src/Google/Http/Batch.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ public function parseResponse(ResponseInterface $response, $classes = array())
138138
$contentType = explode(';', $contentType);
139139
$boundary = false;
140140
foreach ($contentType as $part) {
141-
$part = (explode('=', $part, 2));
141+
$part = explode('=', $part, 2);
142142
if (isset($part[0]) && 'boundary' == trim($part[0])) {
143143
$boundary = $part[1];
144144
}
@@ -170,10 +170,6 @@ public function parseResponse(ResponseInterface $response, $classes = array())
170170

171171
// Need content id.
172172
$key = $headers['content-id'];
173-
$class = '';
174-
if (!empty($this->expected_classes[$key])) {
175-
$class = $this->expected_classes[$key];
176-
}
177173

178174
try {
179175
$response = Google_Http_REST::decodeHttpResponse($response, $requests[$i-1]);

src/Google/Http/MediaFileUpload.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,7 @@ private function process()
221221
Uri::withQueryValue($request->getUri(), 'uploadType', $uploadType)
222222
);
223223

224-
$mimeType = $this->mimeType ?
225-
$this->mimeType :
226-
$request->getHeaderLine('content-type');
224+
$mimeType = $this->mimeType ?: $request->getHeaderLine('content-type');
227225

228226
if (self::UPLOAD_RESUMABLE_TYPE == $uploadType) {
229227
$contentType = $mimeType;
@@ -233,7 +231,7 @@ private function process()
233231
$postBody = $this->data;
234232
} else if (self::UPLOAD_MULTIPART_TYPE == $uploadType) {
235233
// This is a multipart/related upload.
236-
$boundary = $this->boundary ? $this->boundary : mt_rand();
234+
$boundary = $this->boundary ?: mt_rand();
237235
$boundary = str_replace('"', '', $boundary);
238236
$contentType = 'multipart/related; boundary=' . $boundary;
239237
$related = "--$boundary\r\n";
@@ -280,7 +278,7 @@ public function getUploadType($meta)
280278

281279
public function getResumeUri()
282280
{
283-
if (is_null($this->resumeUri)) {
281+
if (null === $this->resumeUri) {
284282
$this->resumeUri = $this->fetchResumeUri();
285283
}
286284

@@ -289,7 +287,6 @@ public function getResumeUri()
289287

290288
private function fetchResumeUri()
291289
{
292-
$result = null;
293290
$body = $this->request->getBody();
294291
if ($body) {
295292
$headers = array(

src/Google/Http/REST.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public static function execute(
5151
array($client, $request, $expectedClass)
5252
);
5353

54-
if (!is_null($retryMap)) {
54+
if (null !== $retryMap) {
5555
$runner->setRetryMap($retryMap);
5656
}
5757

@@ -110,7 +110,7 @@ public static function decodeHttpResponse(
110110
$code = $response->getStatusCode();
111111

112112
// retry strategy
113-
if ((intVal($code)) >= 400) {
113+
if (intVal($code) >= 400) {
114114
// if we errored out, it should be safe to grab the response body
115115
$body = (string) $response->getBody();
116116

@@ -149,7 +149,7 @@ private static function determineExpectedClass($expectedClass, RequestInterface
149149
}
150150

151151
// if we don't have a request, we just use what's passed in
152-
if (is_null($request)) {
152+
if (null === $request) {
153153
return $expectedClass;
154154
}
155155

src/Google/Model.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,7 @@ private function nullPlaceholderCheck($value)
192192
*/
193193
private function getMappedName($key)
194194
{
195-
if (isset($this->internal_gapi_mappings) &&
196-
isset($this->internal_gapi_mappings[$key])) {
195+
if (isset($this->internal_gapi_mappings, $this->internal_gapi_mappings[$key])) {
197196
$key = $this->internal_gapi_mappings[$key];
198197
}
199198
return $key;

src/Google/Service/Resource.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ public function createRequestUri($restPath, $params)
267267
$queryVars = array();
268268
foreach ($params as $paramName => $paramSpec) {
269269
if ($paramSpec['type'] == 'boolean') {
270-
$paramSpec['value'] = ($paramSpec['value']) ? 'true' : 'false';
270+
$paramSpec['value'] = $paramSpec['value'] ? 'true' : 'false';
271271
}
272272
if ($paramSpec['location'] == 'path') {
273273
$uriTemplateVars[$paramName] = $paramSpec['value'];

src/Google/Task/Runner.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,6 @@ class Google_Task_Runner
5555
*/
5656
private $maxAttempts = 1;
5757

58-
/**
59-
* @var string $name The name of the current task (used for logging).
60-
*/
61-
private $name;
6258
/**
6359
* @var callable $action The task to run and possibly retry.
6460
*/
@@ -153,7 +149,6 @@ public function __construct(
153149
);
154150
}
155151

156-
$this->name = $name;
157152
$this->action = $action;
158153
$this->arguments = $arguments;
159154
}
@@ -269,8 +264,10 @@ public function allowedRetries($code, $errors = array())
269264
return $this->retryMap[$code];
270265
}
271266

272-
if (!empty($errors) && isset($errors[0]['reason']) &&
273-
isset($this->retryMap[$errors[0]['reason']])) {
267+
if (
268+
!empty($errors) &&
269+
isset($errors[0]['reason'], $this->retryMap[$errors[0]['reason']])
270+
) {
274271
return $this->retryMap[$errors[0]['reason']];
275272
}
276273

0 commit comments

Comments
 (0)