Skip to content

Commit

Permalink
SCA (Static Code Analysis) warnings partially fixed (code style, if c…
Browse files Browse the repository at this point in the history
…onditionals, strict types, performance).
  • Loading branch information
kalessil committed Feb 15, 2015
1 parent b524d13 commit 3e272f9
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 40 deletions.
11 changes: 5 additions & 6 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 All @@ -178,7 +177,7 @@ public static function getAccessTokenFromCode($code, $appId = null, $appSecret =
{
$params = array(
'code' => $code,
'redirect_uri' => '',
'redirect_uri' => ''
);

if ($machineId) {
Expand All @@ -203,7 +202,7 @@ public static function getCodeFromAccessToken($accessToken, $appId = null, $appS

$params = array(
'access_token' => $accessToken,
'redirect_uri' => '',
'redirect_uri' => ''
);

return static::requestCode($params, $appId, $appSecret);
Expand All @@ -221,7 +220,7 @@ public function extend($appId = null, $appSecret = null)
{
$params = array(
'grant_type' => 'fb_exchange_token',
'fb_exchange_token' => $this->accessToken,
'fb_exchange_token' => $this->accessToken
);

return static::requestAccessToken($params, $appId, $appSecret);
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 @@ -194,13 +194,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 @@ -229,7 +229,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 @@ -239,7 +239,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 @@ -249,7 +249,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 @@ -291,7 +291,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
9 changes: 5 additions & 4 deletions src/Facebook/FacebookSignedRequestFromInputHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ abstract class FacebookSignedRequestFromInputHelper
/**
* @var string|null Random string to prevent CSRF.
*/
public $state = null;
public $state;

/**
* Initialize the helper and process available signed request data.
Expand All @@ -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
4 changes: 2 additions & 2 deletions src/Facebook/HttpClients/FacebookCurl.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ class FacebookCurl
{

/**
* @var resource Curl resource instance
* @var resource|null Curl resource instance
*/
protected $curl = null;
protected $curl;

/**
* Make a new curl reference instance
Expand Down
10 changes: 5 additions & 5 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 @@ -177,17 +177,17 @@ public function openConnection($url, $method = 'GET', $parameters = array())
CURLOPT_HEADER => true, // Enable header processing
CURLOPT_SSL_VERIFYHOST => 2,
CURLOPT_SSL_VERIFYPEER => true,
CURLOPT_CAINFO => __DIR__ . '/certs/DigiCertHighAssuranceEVRootCA.pem',
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());

}
6 changes: 3 additions & 3 deletions 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 All @@ -109,8 +109,8 @@ public function send($url, $method = 'GET', $parameters = array())
'verify_peer' => true,
'verify_peer_name' => true,
'allow_self_signed' => true, // All root certificates are self-signed
'cafile' => __DIR__ . '/certs/DigiCertHighAssuranceEVRootCA.pem',
),
'cafile' => __DIR__ . '/certs/DigiCertHighAssuranceEVRootCA.pem'
)
);

if ($parameters) {
Expand Down

0 comments on commit 3e272f9

Please sign in to comment.