Skip to content
This repository was archived by the owner on Jan 13, 2022. It is now read-only.

Commit 0413e1c

Browse files
committed
Merge pull request #359 from kalessil/SCA
Static Code Analysis warnings fixed (partially)
2 parents ba3c9e5 + fe0624f commit 0413e1c

10 files changed

+32
-31
lines changed

src/Facebook/Entities/AccessToken.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,10 @@ public static function validateAccessToken(GraphSessionInfo $tokenInfo,
154154
$machineIdIsValid = $tokenInfo->getProperty('machine_id') == $machineId;
155155
$accessTokenIsValid = $tokenInfo->isValid();
156156

157+
$accessTokenIsStillAlive = true;
157158
// Not all access tokens return an expiration. E.g. an app access token.
158159
if ($tokenInfo->getExpiresAt() instanceof \DateTime) {
159160
$accessTokenIsStillAlive = $tokenInfo->getExpiresAt()->getTimestamp() >= time();
160-
} else {
161-
$accessTokenIsStillAlive = true;
162161
}
163162

164163
return $appIdIsValid && $machineIdIsValid && $accessTokenIsValid && $accessTokenIsStillAlive;
@@ -374,7 +373,7 @@ public function __toString()
374373
*/
375374
public function isAppSession()
376375
{
377-
return strpos($this->accessToken, "|") !== false;
376+
return strpos($this->accessToken, '|') !== false;
378377
}
379378

380379
}

src/Facebook/Entities/SignedRequest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,9 +298,10 @@ public static function hashSignature($encodedData, $appSecret = null)
298298
*/
299299
public static function validateSignature($hashedSig, $sig)
300300
{
301-
if (mb_strlen($hashedSig) === mb_strlen($sig)) {
301+
$intSignatureLength = mb_strlen($sig);
302+
if (mb_strlen($hashedSig) === $intSignatureLength) {
302303
$validate = 0;
303-
for ($i = 0; $i < mb_strlen($sig); $i++) {
304+
for ($i = 0; $i < $intSignatureLength; $i++) {
304305
$validate |= ord($hashedSig[$i]) ^ ord($sig[$i]);
305306
}
306307
if ($validate === 0) {

src/Facebook/FacebookRedirectLoginHelper.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public function __construct($redirectUrl, $appId = null, $appSecret = null)
9090
*
9191
* @return string
9292
*/
93-
public function getLoginUrl($scope = array(), $version = null, $displayAsPopup = false, $authType = false)
93+
public function getLoginUrl(array $scope = array(), $version = null, $displayAsPopup = false, $authType = false)
9494
{
9595
$version = ($version ?: FacebookRequest::GRAPH_API_VERSION);
9696
$this->state = $this->random(16);
@@ -124,7 +124,7 @@ public function getLoginUrl($scope = array(), $version = null, $displayAsPopup =
124124
*
125125
* @return string
126126
*/
127-
public function getReRequestUrl($scope = array(), $version = null)
127+
public function getReRequestUrl(array $scope = array(), $version = null)
128128
{
129129
$version = ($version ?: FacebookRequest::GRAPH_API_VERSION);
130130
$this->state = $this->random(16);
@@ -276,12 +276,12 @@ public function random($bytes)
276276
{
277277
if (!is_numeric($bytes)) {
278278
throw new FacebookSDKException(
279-
"random() expects an integer"
279+
'random() expects an integer'
280280
);
281281
}
282282
if ($bytes < 1) {
283283
throw new FacebookSDKException(
284-
"random() expects an integer greater than zero"
284+
'random() expects an integer greater than zero'
285285
);
286286
}
287287
$buf = '';

src/Facebook/FacebookRequest.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -199,13 +199,13 @@ public function __construct(
199199

200200
$params = ($parameters ?: array());
201201
if ($session
202-
&& !isset($params["access_token"])) {
203-
$params["access_token"] = $session->getToken();
202+
&& ! isset($params['access_token'])) {
203+
$params['access_token'] = $session->getToken();
204204
}
205-
if (FacebookSession::useAppSecretProof()
206-
&& !isset($params["appsecret_proof"])) {
207-
$params["appsecret_proof"] = $this->getAppSecretProof(
208-
$params["access_token"]
205+
if (! isset($params['appsecret_proof'])
206+
&& FacebookSession::useAppSecretProof()) {
207+
$params['appsecret_proof'] = $this->getAppSecretProof(
208+
$params['access_token']
209209
);
210210
}
211211
$this->params = $params;
@@ -240,7 +240,7 @@ public function execute()
240240
$url = $this->getRequestURL();
241241
$params = $this->getParameters();
242242

243-
if ($this->method === "GET") {
243+
if ($this->method === 'GET') {
244244
$url = self::appendParamsToUrl($url, $params);
245245
$params = array();
246246
}
@@ -250,7 +250,7 @@ public function execute()
250250
$connection->addRequestHeader('Accept-Encoding', '*'); // Support all available encodings.
251251

252252
// ETag
253-
if (isset($this->etag)) {
253+
if (null !== $this->etag) {
254254
$connection->addRequestHeader('If-None-Match', $this->etag);
255255
}
256256

@@ -260,7 +260,7 @@ public function execute()
260260

261261
static::$requestCount++;
262262

263-
$etagHit = 304 == $connection->getResponseHttpStatusCode();
263+
$etagHit = 304 === $connection->getResponseHttpStatusCode();
264264

265265
$headers = $connection->getResponseHeaders();
266266
$etagReceived = isset($headers['ETag']) ? $headers['ETag'] : null;
@@ -302,7 +302,7 @@ public function getAppSecretProof($token)
302302
*
303303
* @return string
304304
*/
305-
public static function appendParamsToUrl($url, $params = array())
305+
public static function appendParamsToUrl($url, array $params = array())
306306
{
307307
if (!$params) {
308308
return $url;

src/Facebook/FacebookRequestException.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public static function create($raw, $data, $statusCode)
8080
if (!isset($data['error']['code']) && isset($data['code'])) {
8181
$data = array('error' => $data);
8282
}
83-
$code = (isset($data['error']['code']) ? $data['error']['code'] : null);
83+
$code = (isset($data['error']['code']) ? (int) $data['error']['code'] : null);
8484

8585
if (isset($data['error']['error_subcode'])) {
8686
switch ($data['error']['error_subcode']) {
@@ -124,7 +124,7 @@ public static function create($raw, $data, $statusCode)
124124
}
125125

126126
// Missing Permissions
127-
if ($code == 10 || ($code >= 200 && $code <= 299)) {
127+
if ($code === 10 || ($code >= 200 && $code <= 299)) {
128128
return new FacebookPermissionException($raw, $data, $statusCode);
129129
}
130130

src/Facebook/FacebookSignedRequestFromInputHelper.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public function __construct($appId = null, $appSecret = null)
6969
/**
7070
* Instantiates a new SignedRequest entity.
7171
*
72-
* @param string|null
72+
* @param string|null $rawSignedRequest
7373
*/
7474
public function instantiateSignedRequest($rawSignedRequest = null)
7575
{
@@ -157,8 +157,9 @@ public function getRawSignedRequestFromPost()
157157
*/
158158
public function getRawSignedRequestFromCookie()
159159
{
160-
if (isset($_COOKIE['fbsr_' . $this->appId])) {
161-
return $_COOKIE['fbsr_' . $this->appId];
160+
$strCookieKey = 'fbsr_' . $this->appId;
161+
if (isset($_COOKIE[$strCookieKey])) {
162+
return $_COOKIE[$strCookieKey];
162163
}
163164
return null;
164165
}

src/Facebook/HttpClients/FacebookCurlHttpClient.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ public function getResponseHttpStatusCode()
141141
*
142142
* @throws \Facebook\FacebookSDKException
143143
*/
144-
public function send($url, $method = 'GET', $parameters = array())
144+
public function send($url, $method = 'GET', array $parameters = array())
145145
{
146146
$this->openConnection($url, $method, $parameters);
147147
$this->tryToSendRequest();
@@ -167,7 +167,7 @@ public function send($url, $method = 'GET', $parameters = array())
167167
* @param string $method The request method
168168
* @param array $parameters The key value pairs to be sent in the body
169169
*/
170-
public function openConnection($url, $method = 'GET', $parameters = array())
170+
public function openConnection($url, $method = 'GET', array $parameters = array())
171171
{
172172
$options = array(
173173
CURLOPT_URL => $url,
@@ -180,14 +180,14 @@ public function openConnection($url, $method = 'GET', $parameters = array())
180180
CURLOPT_CAINFO => __DIR__ . '/certs/DigiCertHighAssuranceEVRootCA.pem',
181181
);
182182

183-
if ($method !== "GET") {
183+
if ($method !== 'GET') {
184184
$options[CURLOPT_POSTFIELDS] = $parameters;
185185
}
186186
if ($method === 'DELETE' || $method === 'PUT') {
187187
$options[CURLOPT_CUSTOMREQUEST] = $method;
188188
}
189189

190-
if (!empty($this->requestHeaders)) {
190+
if (count($this->requestHeaders) > 0) {
191191
$options[CURLOPT_HTTPHEADER] = $this->compileRequestHeaders();
192192
}
193193

src/Facebook/HttpClients/FacebookGuzzleHttpClient.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public function getResponseHttpStatusCode()
101101
*
102102
* @throws \Facebook\FacebookSDKException
103103
*/
104-
public function send($url, $method = 'GET', $parameters = array())
104+
public function send($url, $method = 'GET', array $parameters = array())
105105
{
106106
$options = array();
107107
if ($parameters) {

src/Facebook/HttpClients/FacebookHttpable.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,6 @@ public function getResponseHttpStatusCode();
6363
*
6464
* @throws \Facebook\FacebookSDKException
6565
*/
66-
public function send($url, $method = 'GET', $parameters = array());
66+
public function send($url, $method = 'GET', array $parameters = array());
6767

6868
}

src/Facebook/HttpClients/FacebookStreamHttpClient.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public function getResponseHttpStatusCode()
9797
*
9898
* @throws \Facebook\FacebookSDKException
9999
*/
100-
public function send($url, $method = 'GET', $parameters = array())
100+
public function send($url, $method = 'GET', array $parameters = array())
101101
{
102102
$options = array(
103103
'http' => array(

0 commit comments

Comments
 (0)