Skip to content

Commit

Permalink
Merge pull request facebookarchive#359 from kalessil/SCA
Browse files Browse the repository at this point in the history
Static Code Analysis warnings fixed (partially)
  • Loading branch information
gfosco committed Feb 19, 2015
2 parents ba3c9e5 + fe0624f commit 0413e1c
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 31 deletions.
5 changes: 2 additions & 3 deletions src/Facebook/Entities/AccessToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,10 @@ public static function validateAccessToken(GraphSessionInfo $tokenInfo,
$machineIdIsValid = $tokenInfo->getProperty('machine_id') == $machineId;
$accessTokenIsValid = $tokenInfo->isValid();

$accessTokenIsStillAlive = true;
// Not all access tokens return an expiration. E.g. an app access token.
if ($tokenInfo->getExpiresAt() instanceof \DateTime) {
$accessTokenIsStillAlive = $tokenInfo->getExpiresAt()->getTimestamp() >= time();
} else {
$accessTokenIsStillAlive = true;
}

return $appIdIsValid && $machineIdIsValid && $accessTokenIsValid && $accessTokenIsStillAlive;
Expand Down Expand Up @@ -374,7 +373,7 @@ public function __toString()
*/
public function isAppSession()
{
return strpos($this->accessToken, "|") !== false;
return strpos($this->accessToken, '|') !== false;
}

}
5 changes: 3 additions & 2 deletions src/Facebook/Entities/SignedRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -298,9 +298,10 @@ public static function hashSignature($encodedData, $appSecret = null)
*/
public static function validateSignature($hashedSig, $sig)
{
if (mb_strlen($hashedSig) === mb_strlen($sig)) {
$intSignatureLength = mb_strlen($sig);
if (mb_strlen($hashedSig) === $intSignatureLength) {
$validate = 0;
for ($i = 0; $i < mb_strlen($sig); $i++) {
for ($i = 0; $i < $intSignatureLength; $i++) {
$validate |= ord($hashedSig[$i]) ^ ord($sig[$i]);
}
if ($validate === 0) {
Expand Down
8 changes: 4 additions & 4 deletions src/Facebook/FacebookRedirectLoginHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public function __construct($redirectUrl, $appId = null, $appSecret = null)
*
* @return string
*/
public function getLoginUrl($scope = array(), $version = null, $displayAsPopup = false, $authType = false)
public function getLoginUrl(array $scope = array(), $version = null, $displayAsPopup = false, $authType = false)
{
$version = ($version ?: FacebookRequest::GRAPH_API_VERSION);
$this->state = $this->random(16);
Expand Down Expand Up @@ -124,7 +124,7 @@ public function getLoginUrl($scope = array(), $version = null, $displayAsPopup =
*
* @return string
*/
public function getReRequestUrl($scope = array(), $version = null)
public function getReRequestUrl(array $scope = array(), $version = null)
{
$version = ($version ?: FacebookRequest::GRAPH_API_VERSION);
$this->state = $this->random(16);
Expand Down Expand Up @@ -276,12 +276,12 @@ public function random($bytes)
{
if (!is_numeric($bytes)) {
throw new FacebookSDKException(
"random() expects an integer"
'random() expects an integer'
);
}
if ($bytes < 1) {
throw new FacebookSDKException(
"random() expects an integer greater than zero"
'random() expects an integer greater than zero'
);
}
$buf = '';
Expand Down
20 changes: 10 additions & 10 deletions src/Facebook/FacebookRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,13 +199,13 @@ public function __construct(

$params = ($parameters ?: array());
if ($session
&& !isset($params["access_token"])) {
$params["access_token"] = $session->getToken();
&& ! isset($params['access_token'])) {
$params['access_token'] = $session->getToken();
}
if (FacebookSession::useAppSecretProof()
&& !isset($params["appsecret_proof"])) {
$params["appsecret_proof"] = $this->getAppSecretProof(
$params["access_token"]
if (! isset($params['appsecret_proof'])
&& FacebookSession::useAppSecretProof()) {
$params['appsecret_proof'] = $this->getAppSecretProof(
$params['access_token']
);
}
$this->params = $params;
Expand Down Expand Up @@ -240,7 +240,7 @@ public function execute()
$url = $this->getRequestURL();
$params = $this->getParameters();

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

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

Expand All @@ -260,7 +260,7 @@ public function execute()

static::$requestCount++;

$etagHit = 304 == $connection->getResponseHttpStatusCode();
$etagHit = 304 === $connection->getResponseHttpStatusCode();

$headers = $connection->getResponseHeaders();
$etagReceived = isset($headers['ETag']) ? $headers['ETag'] : null;
Expand Down Expand Up @@ -302,7 +302,7 @@ public function getAppSecretProof($token)
*
* @return string
*/
public static function appendParamsToUrl($url, $params = array())
public static function appendParamsToUrl($url, array $params = array())
{
if (!$params) {
return $url;
Expand Down
4 changes: 2 additions & 2 deletions src/Facebook/FacebookRequestException.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public static function create($raw, $data, $statusCode)
if (!isset($data['error']['code']) && isset($data['code'])) {
$data = array('error' => $data);
}
$code = (isset($data['error']['code']) ? $data['error']['code'] : null);
$code = (isset($data['error']['code']) ? (int) $data['error']['code'] : null);

if (isset($data['error']['error_subcode'])) {
switch ($data['error']['error_subcode']) {
Expand Down Expand Up @@ -124,7 +124,7 @@ public static function create($raw, $data, $statusCode)
}

// Missing Permissions
if ($code == 10 || ($code >= 200 && $code <= 299)) {
if ($code === 10 || ($code >= 200 && $code <= 299)) {
return new FacebookPermissionException($raw, $data, $statusCode);
}

Expand Down
7 changes: 4 additions & 3 deletions src/Facebook/FacebookSignedRequestFromInputHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function __construct($appId = null, $appSecret = null)
/**
* Instantiates a new SignedRequest entity.
*
* @param string|null
* @param string|null $rawSignedRequest
*/
public function instantiateSignedRequest($rawSignedRequest = null)
{
Expand Down Expand Up @@ -157,8 +157,9 @@ public function getRawSignedRequestFromPost()
*/
public function getRawSignedRequestFromCookie()
{
if (isset($_COOKIE['fbsr_' . $this->appId])) {
return $_COOKIE['fbsr_' . $this->appId];
$strCookieKey = 'fbsr_' . $this->appId;
if (isset($_COOKIE[$strCookieKey])) {
return $_COOKIE[$strCookieKey];
}
return null;
}
Expand Down
8 changes: 4 additions & 4 deletions src/Facebook/HttpClients/FacebookCurlHttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public function getResponseHttpStatusCode()
*
* @throws \Facebook\FacebookSDKException
*/
public function send($url, $method = 'GET', $parameters = array())
public function send($url, $method = 'GET', array $parameters = array())
{
$this->openConnection($url, $method, $parameters);
$this->tryToSendRequest();
Expand All @@ -167,7 +167,7 @@ public function send($url, $method = 'GET', $parameters = array())
* @param string $method The request method
* @param array $parameters The key value pairs to be sent in the body
*/
public function openConnection($url, $method = 'GET', $parameters = array())
public function openConnection($url, $method = 'GET', array $parameters = array())
{
$options = array(
CURLOPT_URL => $url,
Expand All @@ -180,14 +180,14 @@ public function openConnection($url, $method = 'GET', $parameters = array())
CURLOPT_CAINFO => __DIR__ . '/certs/DigiCertHighAssuranceEVRootCA.pem',
);

if ($method !== "GET") {
if ($method !== 'GET') {
$options[CURLOPT_POSTFIELDS] = $parameters;
}
if ($method === 'DELETE' || $method === 'PUT') {
$options[CURLOPT_CUSTOMREQUEST] = $method;
}

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

Expand Down
2 changes: 1 addition & 1 deletion src/Facebook/HttpClients/FacebookGuzzleHttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public function getResponseHttpStatusCode()
*
* @throws \Facebook\FacebookSDKException
*/
public function send($url, $method = 'GET', $parameters = array())
public function send($url, $method = 'GET', array $parameters = array())
{
$options = array();
if ($parameters) {
Expand Down
2 changes: 1 addition & 1 deletion src/Facebook/HttpClients/FacebookHttpable.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,6 @@ public function getResponseHttpStatusCode();
*
* @throws \Facebook\FacebookSDKException
*/
public function send($url, $method = 'GET', $parameters = array());
public function send($url, $method = 'GET', array $parameters = array());

}
2 changes: 1 addition & 1 deletion src/Facebook/HttpClients/FacebookStreamHttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public function getResponseHttpStatusCode()
*
* @throws \Facebook\FacebookSDKException
*/
public function send($url, $method = 'GET', $parameters = array())
public function send($url, $method = 'GET', array $parameters = array())
{
$options = array(
'http' => array(
Expand Down

0 comments on commit 0413e1c

Please sign in to comment.