Skip to content

Commit

Permalink
Merge pull request #96 from Adyen/formatting
Browse files Browse the repository at this point in the history
PW-822: PSR-2 Formatting
  • Loading branch information
rikterbeek authored Dec 3, 2018
2 parents d22384b + 6f3aaa1 commit 162fb2e
Show file tree
Hide file tree
Showing 77 changed files with 467 additions and 467 deletions.
12 changes: 6 additions & 6 deletions src/Adyen/AdyenException.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ class AdyenException extends Exception
/**
* @var null
*/
protected $_status;
protected $status;

/**
* @var null
*/
protected $_errorType;
protected $errorType;

/**
* AdyenException constructor.
Expand All @@ -27,8 +27,8 @@ class AdyenException extends Exception
*/
public function __construct($message = "", $code = 0, Exception $previous = null, $status = null, $errorType = null)
{
$this->_status = $status;
$this->_errorType = $errorType;
$this->status = $status;
$this->errorType = $errorType;
parent::__construct($message, (int)$code, $previous);
}

Expand All @@ -39,14 +39,14 @@ public function __construct($message = "", $code = 0, Exception $previous = null
*/
public function getStatus()
{
return $this->_status;
return $this->status;
}

/**
* Get Adyen Error type
*/
public function getErrorType()
{
return $this->_errorType;
return $this->errorType;
}
}
2 changes: 1 addition & 1 deletion src/Adyen/ApiKeyAuthenticatedService.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ class ApiKeyAuthenticatedService extends Service
/**
* @var bool
*/
protected $_requiresApiKey = true;
protected $requiresApiKey = true;
}
82 changes: 41 additions & 41 deletions src/Adyen/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ class Client
/**
* @var \Adyen\Config $config
*/
private $_config;
private $config;

/**
* @var
*/
private $_httpClient;
private $httpClient;

/**
* @var Logger $logger
Expand All @@ -62,9 +62,9 @@ public function __construct($config = null)
{
if (!$config) {
// create config
$this->_config = new \Adyen\Config();
$this->config = new \Adyen\Config();
} elseif ($config instanceof \Adyen\ConfigInterface) {
$this->_config = $config;
$this->config = $config;
} else {
throw new \Adyen\AdyenException("This config object is not supported, you need to implement the ConfigInterface");
}
Expand All @@ -75,7 +75,7 @@ public function __construct($config = null)
*/
public function getConfig()
{
return $this->_config;
return $this->config;
}

/**
Expand All @@ -85,7 +85,7 @@ public function getConfig()
*/
public function setUsername($username)
{
$this->_config->set('username', $username);
$this->config->set('username', $username);
}

/**
Expand All @@ -95,17 +95,17 @@ public function setUsername($username)
*/
public function setPassword($password)
{
$this->_config->set('password', $password);
$this->config->set('password', $password);
}

/**
* Set x-api-key for Web Service Client
*
* @param $xapikey
* @param $xApiKey
*/
public function setXApiKey($xApiKey)
{
$this->_config->set('x-api-key', $xApiKey);
$this->config->set('x-api-key', $xApiKey);
}

/**
Expand All @@ -119,30 +119,30 @@ public function setXApiKey($xApiKey)
public function setEnvironment($environment, $liveEndpointUrlPrefix = null)
{
if ($environment == \Adyen\Environment::TEST) {
$this->_config->set('environment', \Adyen\Environment::TEST);
$this->_config->set('endpoint', self::ENDPOINT_TEST);
$this->_config->set('endpointDirectorylookup', self::ENDPOINT_TEST_DIRECTORY_LOOKUP);
$this->_config->set('endpointTerminalCloud', self::ENDPOINT_TERMINAL_CLOUD_TEST);
$this->_config->set('endpointCheckout', self::ENDPOINT_CHECKOUT_TEST);
$this->_config->set('endpointNotification', self::ENDPOINT_NOTIFICATION_TEST);
$this->_config->set('endpointAccount', self::ENDPOINT_ACCOUNT_TEST);
$this->_config->set('endpointFund', self::ENDPOINT_FUND_TEST);
$this->config->set('environment', \Adyen\Environment::TEST);
$this->config->set('endpoint', self::ENDPOINT_TEST);
$this->config->set('endpointDirectorylookup', self::ENDPOINT_TEST_DIRECTORY_LOOKUP);
$this->config->set('endpointTerminalCloud', self::ENDPOINT_TERMINAL_CLOUD_TEST);
$this->config->set('endpointCheckout', self::ENDPOINT_CHECKOUT_TEST);
$this->config->set('endpointNotification', self::ENDPOINT_NOTIFICATION_TEST);
$this->config->set('endpointAccount', self::ENDPOINT_ACCOUNT_TEST);
$this->config->set('endpointFund', self::ENDPOINT_FUND_TEST);
} elseif ($environment == \Adyen\Environment::LIVE) {
$this->_config->set('environment', \Adyen\Environment::LIVE);
$this->_config->set('endpointDirectorylookup', self::ENDPOINT_LIVE_DIRECTORY_LOOKUP);
$this->_config->set('endpointTerminalCloud', self::ENDPOINT_TERMINAL_CLOUD_LIVE);
$this->_config->set('endpointNotification', self::ENDPOINT_NOTIFICATION_LIVE);
$this->_config->set('endpointAccount', self::ENDPOINT_ACCOUNT_LIVE);
$this->_config->set('endpointFund', self::ENDPOINT_FUND_LIVE);
$this->config->set('environment', \Adyen\Environment::LIVE);
$this->config->set('endpointDirectorylookup', self::ENDPOINT_LIVE_DIRECTORY_LOOKUP);
$this->config->set('endpointTerminalCloud', self::ENDPOINT_TERMINAL_CLOUD_LIVE);
$this->config->set('endpointNotification', self::ENDPOINT_NOTIFICATION_LIVE);
$this->config->set('endpointAccount', self::ENDPOINT_ACCOUNT_LIVE);
$this->config->set('endpointFund', self::ENDPOINT_FUND_LIVE);

if ($liveEndpointUrlPrefix) {
$this->_config->set('endpoint',
$this->config->set('endpoint',
self::ENDPOINT_PROTOCOL . $liveEndpointUrlPrefix . self::ENDPOINT_LIVE_SUFFIX);
$this->_config->set('endpointCheckout',
$this->config->set('endpointCheckout',
self::ENDPOINT_PROTOCOL . $liveEndpointUrlPrefix . self::ENDPOINT_CHECKOUT_LIVE_SUFFIX);
} else {
$this->_config->set('endpoint', self::ENDPOINT_LIVE);
$this->_config->set('endpointCheckout', null); // not supported please specify unique identifier
$this->config->set('endpoint', self::ENDPOINT_LIVE);
$this->config->set('endpointCheckout', null); // not supported please specify unique identifier
}
} else {
// environment does not exist
Expand All @@ -158,7 +158,7 @@ public function setEnvironment($environment, $liveEndpointUrlPrefix = null)
*/
public function setRequestUrl($url)
{
$this->_config->set('endpoint', $url);
$this->config->set('endpoint', $url);
}

/**
Expand All @@ -168,23 +168,23 @@ public function setRequestUrl($url)
*/
public function setDirectoryLookupUrl($url)
{
$this->_config->set('endpointDirectorylookup', $url);
$this->config->set('endpointDirectorylookup', $url);
}

/**
* @param $merchantAccount
*/
public function setMerchantAccount($merchantAccount)
{
$this->_config->set('merchantAccount', $merchantAccount);
$this->config->set('merchantAccount', $merchantAccount);
}

/**
* @param $applicationName
*/
public function setApplicationName($applicationName)
{
$this->_config->set('applicationName', $applicationName);
$this->config->set('applicationName', $applicationName);
}

/**
Expand All @@ -196,7 +196,7 @@ public function setApplicationName($applicationName)
*/
public function setExternalPlatform($name, $version, $integrator = "")
{
$this->_config->set('externalPlatform',
$this->config->set('externalPlatform',
array('name' => $name, 'version' => $version, 'integrator' => $integrator));
}

Expand All @@ -208,7 +208,7 @@ public function setExternalPlatform($name, $version, $integrator = "")
*/
public function setAdyenPaymentSource($name, $version)
{
$this->_config->set('adyenPaymentSource', array('name' => $name, 'version' => $version));
$this->config->set('adyenPaymentSource', array('name' => $name, 'version' => $version));
}

/**
Expand All @@ -218,7 +218,7 @@ public function setAdyenPaymentSource($name, $version)
*/
public function setInputType($value)
{
$this->_config->set('inputType', $value);
$this->config->set('inputType', $value);
}

/**
Expand All @@ -228,15 +228,15 @@ public function setInputType($value)
*/
public function setOutputType($value)
{
$this->_config->set('outputType', $value);
$this->config->set('outputType', $value);
}

/**
* @param $value
*/
public function setTimeout($value)
{
$this->_config->set('timeout', $value);
$this->config->set('timeout', $value);
}

/**
Expand Down Expand Up @@ -344,24 +344,24 @@ public function getApiFundVersion()
*/
public function setHttpClient(\Adyen\HttpClient\ClientInterface $httpClient)
{
$this->_httpClient = $httpClient;
$this->httpClient = $httpClient;
}

/**
* @return mixed
*/
public function getHttpClient()
{
if (is_null($this->_httpClient)) {
$this->_httpClient = $this->_createDefaultHttpClient();
if (is_null($this->httpClient)) {
$this->httpClient = $this->createDefaultHttpClient();
}
return $this->_httpClient;
return $this->httpClient;
}

/**
* @return HttpClient\CurlClient
*/
protected function _createDefaultHttpClient()
protected function createDefaultHttpClient()
{
return new \Adyen\HttpClient\CurlClient();
}
Expand Down
4 changes: 2 additions & 2 deletions src/Adyen/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Service
/**
* @var bool
*/
protected $_requiresApiKey = false;
protected $requiresApiKey = false;

/**
* Service constructor.
Expand Down Expand Up @@ -47,6 +47,6 @@ public function getClient()
*/
public function requiresApiKey()
{
return $this->_requiresApiKey;
return $this->requiresApiKey;
}
}
36 changes: 18 additions & 18 deletions src/Adyen/Service/AbstractResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ abstract class AbstractResource
/**
* @var \Adyen\Service
*/
protected $_service;
protected $service;

/**
* @var string
*/
protected $_endpoint;
protected $endpoint;

/**
* @var bool
Expand All @@ -28,8 +28,8 @@ abstract class AbstractResource
*/
public function __construct(\Adyen\Service $service, $endpoint, $allowApplicationInfo = false)
{
$this->_service = $service;
$this->_endpoint = $endpoint;
$this->service = $service;
$this->endpoint = $endpoint;
$this->allowApplicationInfo = $allowApplicationInfo;
}

Expand All @@ -43,27 +43,27 @@ public function __construct(\Adyen\Service $service, $endpoint, $allowApplicatio
public function request($params)
{
// convert to PHP Array if type is inputType is json
if ($this->_service->getClient()->getConfig()->getInputType() == 'json') {
if ($this->service->getClient()->getConfig()->getInputType() == 'json') {
$params = json_decode($params, true);
if ($params === null && json_last_error() !== JSON_ERROR_NONE) {
$msg = 'The parameters in the request expect valid JSON but JSON error code found: ' . json_last_error();
$this->_service->getClient()->getLogger()->error($msg);
$this->service->getClient()->getLogger()->error($msg);
throw new \Adyen\AdyenException($msg);
}
}

if (!is_array($params)) {
$msg = 'The parameter is not valid array';
$this->_service->getClient()->getLogger()->error($msg);
$this->service->getClient()->getLogger()->error($msg);
throw new \Adyen\AdyenException($msg);
}

$params = $this->addDefaultParametersToRequest($params);

$params = $this->handleApplicationInfoInRequest($params);

$curlClient = $this->_service->getClient()->getHttpClient();
return $curlClient->requestJson($this->_service, $this->_endpoint, $params);
$curlClient = $this->service->getClient()->getHttpClient();
return $curlClient->requestJson($this->service, $this->endpoint, $params);
}

/**
Expand All @@ -76,12 +76,12 @@ public function requestPost($params)
// check if paramenters has a value
if (!$params) {
$msg = 'The parameters in the request are empty';
$this->_service->getClient()->getLogger()->error($msg);
$this->service->getClient()->getLogger()->error($msg);
throw new \Adyen\AdyenException($msg);
}

$curlClient = $this->_service->getClient()->getHttpClient();
return $curlClient->requestPost($this->_service, $this->_endpoint, $params);
$curlClient = $this->service->getClient()->getHttpClient();
return $curlClient->requestPost($this->service, $this->endpoint, $params);
}

/**
Expand All @@ -93,8 +93,8 @@ public function requestPost($params)
private function addDefaultParametersToRequest($params)
{
// check if merchantAccount is setup in client and request is missing merchantAccount then add it
if (!isset($params['merchantAccount']) && $this->_service->getClient()->getConfig()->getMerchantAccount()) {
$params['merchantAccount'] = $this->_service->getClient()->getConfig()->getMerchantAccount();
if (!isset($params['merchantAccount']) && $this->service->getClient()->getConfig()->getMerchantAccount()) {
$params['merchantAccount'] = $this->service->getClient()->getConfig()->getMerchantAccount();
}

return $params;
Expand All @@ -112,15 +112,15 @@ private function handleApplicationInfoInRequest($params)
// Only add if allowed
if ($this->allowApplicationInfo) {
// add/overwrite applicationInfo adyenLibrary even if it's already set
$params['applicationInfo']['adyenLibrary']['name'] = $this->_service->getClient()->getLibraryName();
$params['applicationInfo']['adyenLibrary']['version'] = $this->_service->getClient()->getLibraryVersion();
$params['applicationInfo']['adyenLibrary']['name'] = $this->service->getClient()->getLibraryName();
$params['applicationInfo']['adyenLibrary']['version'] = $this->service->getClient()->getLibraryVersion();

if ($adyenPaymentSource = $this->_service->getClient()->getConfig()->getAdyenPaymentSource()) {
if ($adyenPaymentSource = $this->service->getClient()->getConfig()->getAdyenPaymentSource()) {
$params['applicationInfo']['adyenPaymentSource']['version'] = $adyenPaymentSource['version'];
$params['applicationInfo']['adyenPaymentSource']['name'] = $adyenPaymentSource['name'];
}

if ($externalPlatform = $this->_service->getClient()->getConfig()->getExternalPlatform()) {
if ($externalPlatform = $this->service->getClient()->getConfig()->getExternalPlatform()) {
$params['applicationInfo']['externalPlatform']['version'] = $externalPlatform['version'];
$params['applicationInfo']['externalPlatform']['name'] = $externalPlatform['name'];

Expand Down
Loading

0 comments on commit 162fb2e

Please sign in to comment.