Skip to content
This repository has been archived by the owner on Sep 29, 2023. It is now read-only.

Fixed PSR code style errors #607

Merged
merged 3 commits into from
Jul 14, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions lib/PayPal/Cache/AuthorizationCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ abstract class AuthorizationCache
public static function pull($config = null, $clientId = null)
{
// Return if not enabled
if (!self::isEnabled($config)) { return null; }
if (!self::isEnabled($config)) {
return null;
}

$tokens = null;
$cachePath = self::cachePath($config);
Expand All @@ -32,7 +34,7 @@ public static function pull($config = null, $clientId = null)
if ($clientId && is_array($tokens) && array_key_exists($clientId, $tokens)) {
// If client Id is found, just send in that data only
return $tokens[$clientId];
} else if ($clientId) {
} elseif ($clientId) {
// If client Id is provided, but no key in persisted data found matching it.
return null;
}
Expand All @@ -54,7 +56,9 @@ public static function pull($config = null, $clientId = null)
public static function push($config = null, $clientId, $accessToken, $tokenCreateTime, $tokenExpiresIn)
{
// Return if not enabled
if (!self::isEnabled($config)) { return; }
if (!self::isEnabled($config)) {
return;
}

$cachePath = self::cachePath($config);
if (!is_dir(dirname($cachePath))) {
Expand All @@ -74,7 +78,7 @@ public static function push($config = null, $clientId, $accessToken, $tokenCreat
'tokenExpiresIn' => $tokenExpiresIn
);
}
if(!file_put_contents($cachePath, json_encode($tokens))) {
if (!file_put_contents($cachePath, json_encode($tokens))) {
throw new \Exception("Failed to write cache");
};
}
Expand Down Expand Up @@ -116,6 +120,4 @@ private static function getConfigValue($key, $config)
$config = ($config && is_array($config)) ? $config : PayPalConfigManager::getInstance()->getConfigHashmap();
return (array_key_exists($key, $config)) ? trim($config[$key]) : null;
}


}
13 changes: 8 additions & 5 deletions lib/PayPal/Common/PayPalModel.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

namespace PayPal\Common;

use PayPal\Validation\JsonValidator;
use PayPal\Validation\ModelAccessorValidator;

Expand Down Expand Up @@ -67,7 +68,9 @@ public function __construct($data = null)
public static function getList($data)
{
// Return Null if Null
if ($data === null) { return null; }
if ($data === null) {
return null;
}

if (is_a($data, get_class(new \stdClass()))) {
//This means, root element is object
Expand Down Expand Up @@ -173,9 +176,9 @@ private function _convertToArray($param)
foreach ($param as $k => $v) {
if ($v instanceof PayPalModel) {
$ret[$k] = $v->toArray();
} else if (sizeof($v) <= 0 && is_array($v)) {
} elseif (sizeof($v) <= 0 && is_array($v)) {
$ret[$k] = array();
} else if (is_array($v)) {
} elseif (is_array($v)) {
$ret[$k] = $this->_convertToArray($v);
} else {
$ret[$k] = $v;
Expand Down Expand Up @@ -204,9 +207,9 @@ public function fromArray($arr)
// If the value is an array, it means, it is an object after conversion
if (is_array($v)) {
// Determine the class of the object
if (($clazz = ReflectionUtil::getPropertyClass(get_class($this), $k)) != null){
if (($clazz = ReflectionUtil::getPropertyClass(get_class($this), $k)) != null) {
// If the value is an associative array, it means, its an object. Just make recursive call to it.
if (empty($v)){
if (empty($v)) {
if (ReflectionUtil::isPropertyClassArray(get_class($this), $k)) {
// It means, it is an array of objects.
$this->assignValue($k, array());
Expand Down
2 changes: 1 addition & 1 deletion lib/PayPal/Common/PayPalResourceModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,4 @@ public function updateAccessToken($refreshToken, $apiContext)
$apiContext = $apiContext ? $apiContext : new ApiContext(self::$credential);
$apiContext->getCredential()->updateAccessToken($apiContext->getConfig(), $refreshToken);
}
}
}
1 change: 0 additions & 1 deletion lib/PayPal/Common/PayPalUserAgent.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ class PayPalUserAgent
*/
public static function getValue($sdkName, $sdkVersion)
{

$featureList = array(
'platform-ver=' . PHP_VERSION,
'bit=' . self::_getPHPBit(),
Expand Down
5 changes: 3 additions & 2 deletions lib/PayPal/Common/ReflectionUtil.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

namespace PayPal\Common;

use PayPal\Exception\PayPalConfigurationException;

/**
Expand Down Expand Up @@ -112,15 +113,15 @@ public static function propertyAnnotations($class, $propertyName)
}

// todo: smarter regexp
if ( !preg_match_all(
if (!preg_match_all(
'~\@([^\s@\(]+)[\t ]*(?:\(?([^\n@]+)\)?)?~i',
$refl->getDocComment(),
$annots,
PREG_PATTERN_ORDER)) {
return null;
}
foreach ($annots[1] as $i => $annot) {
$annotations[strtolower($annot)] = empty($annots[2][$i]) ? TRUE : rtrim($annots[2][$i], " \t\n\r)");
$annotations[strtolower($annot)] = empty($annots[2][$i]) ? true : rtrim($annots[2][$i], " \t\n\r)");
}

return $annotations;
Expand Down
2 changes: 1 addition & 1 deletion lib/PayPal/Converter/FormatConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public static function formatToPrice($value, $currency = null)
throw new \InvalidArgumentException("value cannot have decimals for $currency currency");
}
$decimals = $currencyDecimals[$currency];
} else if (strpos($value, ".") === false) {
} elseif (strpos($value, ".") === false) {
// Check if value has decimal values. If not no need to assign 2 decimals with .00 at the end
$decimals = 0;
}
Expand Down
6 changes: 0 additions & 6 deletions lib/PayPal/Core/PayPalConfigManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ public function addConfigs($configs = array())
*/
public function get($searchKey)
{

if (array_key_exists($searchKey, $this->configs)) {
return $this->configs[$searchKey];
} else {
Expand All @@ -108,7 +107,6 @@ public function get($searchKey)

return $arr;
}

}

/**
Expand All @@ -123,7 +121,6 @@ public function get($searchKey)
*/
public function getIniPrefix($userId = null)
{

if ($userId == null) {
$arr = array();
foreach ($this->configs as $key => $value) {
Expand Down Expand Up @@ -157,7 +154,4 @@ public function __clone()
{
trigger_error('Clone is not allowed.', E_USER_ERROR);
}

}


4 changes: 1 addition & 3 deletions lib/PayPal/Core/PayPalCredentialManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ private function initCredential($config)
$suffix++;
$key = $prefix . $suffix;
}

}

/**
Expand Down Expand Up @@ -146,7 +145,7 @@ public function getCredentialObject($userId = null)
{
if ($userId == null && array_key_exists($this->defaultAccountName, $this->credentialHashmap)) {
$credObj = $this->credentialHashmap[$this->defaultAccountName];
} else if (array_key_exists($userId, $this->credentialHashmap)) {
} elseif (array_key_exists($userId, $this->credentialHashmap)) {
$credObj = $this->credentialHashmap[$userId];
}

Expand All @@ -164,5 +163,4 @@ public function __clone()
{
trigger_error('Clone is not allowed.', E_USER_ERROR);
}

}
2 changes: 1 addition & 1 deletion lib/PayPal/Core/PayPalHttpConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class PayPalHttpConfig
public static $defaultCurlOptions = array(
CURLOPT_SSLVERSION => 6,
CURLOPT_CONNECTTIMEOUT => 10,
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 60, // maximum number of seconds to allow cURL functions to execute
CURLOPT_USERAGENT => 'PayPal-PHP-SDK',
CURLOPT_HTTPHEADER => array(),
Expand Down
12 changes: 5 additions & 7 deletions lib/PayPal/Core/PayPalHttpConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ public function __construct(PayPalHttpConfig $httpConfig, array $config)
*/
private function getHttpHeaders()
{

$ret = array();
foreach ($this->httpConfig->getHeaders() as $k => $v) {
$ret[] = "$k: $v";
Expand All @@ -78,8 +77,8 @@ public function execute($data)
//Initialize Curl Options
$ch = curl_init($this->httpConfig->getUrl());
$options = $this->httpConfig->getCurlOptions();
if(empty($options[CURLOPT_HTTPHEADER])) {
unset ($options[CURLOPT_HTTPHEADER]);
if (empty($options[CURLOPT_HTTPHEADER])) {
unset($options[CURLOPT_HTTPHEADER]);
}
curl_setopt_array($ch, $options);
curl_setopt($ch, CURLOPT_URL, $this->httpConfig->getUrl());
Expand All @@ -101,7 +100,7 @@ public function execute($data)
}

//Default Option if Method not of given types in switch case
if ($this->httpConfig->getMethod() != NULL) {
if ($this->httpConfig->getMethod() != null) {
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $this->httpConfig->getMethod());
}

Expand Down Expand Up @@ -174,14 +173,14 @@ public function execute($data)
"Retried $retries times." . $result);
$this->logger->debug("\n\n" . str_repeat('=', 128) . "\n");
throw $ex;
} else if ($httpStatus < 200 || $httpStatus >= 300) {
} elseif ($httpStatus < 200 || $httpStatus >= 300) {
$ex = new PayPalConnectionException(
$this->httpConfig->getUrl(),
"Got Http response code $httpStatus when accessing {$this->httpConfig->getUrl()}.",
$httpStatus
);
$ex->setData($result);
$this->logger->error("Got Http response code $httpStatus when accessing {$this->httpConfig->getUrl()}. " . $result );
$this->logger->error("Got Http response code $httpStatus when accessing {$this->httpConfig->getUrl()}. " . $result);
$this->logger->debug("\n\n" . str_repeat('=', 128) . "\n");
throw $ex;
}
Expand All @@ -191,5 +190,4 @@ public function execute($data)
//Return result object
return $result;
}

}
1 change: 0 additions & 1 deletion lib/PayPal/Core/PayPalLoggingManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,5 +116,4 @@ public function debug($message)
$this->logger->debug($message);
}
}

}
1 change: 0 additions & 1 deletion lib/PayPal/Exception/PayPalInvalidCredentialException.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,4 @@ public function errorMessage()
. ': <b>' . $this->getMessage() . '</b>';
return $errorMsg;
}

}
1 change: 0 additions & 1 deletion lib/PayPal/Exception/PayPalMissingCredentialException.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,4 @@ public function errorMessage()

return $errorMsg;
}

}
4 changes: 2 additions & 2 deletions lib/PayPal/Handler/OauthHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ private static function _getEndpoint($config)
{
if (isset($config['oauth.EndPoint'])) {
$baseEndpoint = $config['oauth.EndPoint'];
} else if (isset($config['service.EndPoint'])) {
} elseif (isset($config['service.EndPoint'])) {
$baseEndpoint = $config['service.EndPoint'];
} else if (isset($config['mode'])) {
} elseif (isset($config['mode'])) {
switch (strtoupper($config['mode'])) {
case 'SANDBOX':
$baseEndpoint = PayPalConstants::REST_SANDBOX_ENDPOINT;
Expand Down
3 changes: 1 addition & 2 deletions lib/PayPal/Handler/RestHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ public function __construct($apiContext)
*/
public function handle($httpConfig, $request, $options)
{

$credential = $this->apiContext->getCredential();
$config = $this->apiContext->getConfig();

Expand Down Expand Up @@ -105,7 +104,7 @@ private function _getEndpoint($config)
{
if (isset($config['service.EndPoint'])) {
return $config['service.EndPoint'];
} else if (isset($config['mode'])) {
} elseif (isset($config['mode'])) {
switch (strtoupper($config['mode'])) {
case 'SANDBOX':
return PayPalConstants::REST_SANDBOX_ENDPOINT;
Expand Down
2 changes: 1 addition & 1 deletion lib/PayPal/Log/PayPalDefaultLogFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ public function getLogger($className)
{
return new PayPalLogger($className);
}
}
}
3 changes: 1 addition & 2 deletions lib/PayPal/Log/PayPalLogFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,4 @@ interface PayPalLogFactory
* @return LoggerInterface instance of logger object implementing LoggerInterface
*/
public function getLogger($className);

}
}
5 changes: 2 additions & 3 deletions lib/PayPal/Log/PayPalLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use Psr\Log\AbstractLogger;
use Psr\Log\LogLevel;


class PayPalLogger extends AbstractLogger
{

Expand Down Expand Up @@ -75,11 +74,11 @@ public function initialize()

public function log($level, $message, array $context = array())
{
if($this->isLoggingEnabled) {
if ($this->isLoggingEnabled) {
// Checks if the message is at level below configured logging level
if (array_search($level, $this->loggingLevels) <= array_search($this->loggingLevel, $this->loggingLevels)) {
error_log("[" . date('d-m-Y h:i:s') . "] " . $this->loggerName . " : " . strtoupper($level) . ": $message\n", 3, $this->loggerFile);
}
}
}
}
}
6 changes: 3 additions & 3 deletions lib/PayPal/Security/Cipher.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Cipher
*/
const IV_SIZE = 16;

function __construct($secretKey)
public function __construct($secretKey)
{
$this->secretKey = $secretKey;
}
Expand All @@ -29,7 +29,7 @@ function __construct($secretKey)
* @param $input
* @return string
*/
function encrypt($input)
public function encrypt($input)
{
// Create a random IV. Not using mcrypt to generate one, as to not have a dependency on it.
$iv = substr(uniqid("", true), 0, Cipher::IV_SIZE);
Expand All @@ -45,7 +45,7 @@ function encrypt($input)
* @param $input
* @return string
*/
function decrypt($input)
public function decrypt($input)
{
// Decode the IV + data
$input = base64_decode($input);
Expand Down
2 changes: 0 additions & 2 deletions lib/PayPal/Transport/PayPalRestCall.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ public function __construct(ApiContext $apiContext)
*/
public function execute($handlers = array(), $path, $method, $data = '', $headers = array())
{

$config = $this->apiContext->getConfig();
$httpConfig = new PayPalHttpConfig(null, $method, $config);
$headers = $headers ? $headers : array();
Expand All @@ -75,5 +74,4 @@ public function execute($handlers = array(), $path, $method, $data = '', $header

return $response;
}

}
2 changes: 1 addition & 1 deletion lib/PayPal/Validation/ArgumentValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static function validate($argument, $argumentName = null)
if ($argument === null) {
// Error if Object Null
throw new \InvalidArgumentException("$argumentName cannot be null");
} else if (gettype($argument) == 'string' && trim($argument) == ''){
} elseif (gettype($argument) == 'string' && trim($argument) == '') {
// Error if String Empty
throw new \InvalidArgumentException("$argumentName string cannot be empty");
}
Expand Down
2 changes: 1 addition & 1 deletion lib/PayPal/Validation/JsonValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ public static function validate($string, $silent = false)
}
return true;
}
}
}
Loading