Skip to content

Commit

Permalink
Switches out phpcs for PHP CS Fixer for linting purposes.
Browse files Browse the repository at this point in the history
  • Loading branch information
bencorlett committed Sep 2, 2020
1 parent f6ba5d0 commit d58362a
Show file tree
Hide file tree
Showing 15 changed files with 98 additions and 61 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
/composer.lock
/coverage.xml
/.phpunit.result.cache
/.php_cs.cache
.DS_Store
30 changes: 30 additions & 0 deletions .php_cs.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

$finder = PhpCsFixer\Finder::create()->in(__DIR__ . '/src');

return PhpCsFixer\Config::create()
->setRules([
'@PSR2' => true,
'array_syntax' => ['syntax' => 'short'],
'binary_operator_spaces' => true,
'blank_line_before_return' => true,
'cast_spaces' => true,
'concat_space' => ['spacing' => 'one'],
'no_singleline_whitespace_before_semicolons' => true,
'not_operator_with_space' => true,
'ordered_imports' => true,
'phpdoc_align' => true,
'phpdoc_indent' => true,
'phpdoc_no_access' => true,
'phpdoc_no_alias_tag' => true,
'phpdoc_no_package' => true,
'phpdoc_scalar' => true,
'phpdoc_separation' => true,
'phpdoc_summary' => true,
'phpdoc_to_comment' => true,
'phpdoc_trim' => true,
'single_blank_line_at_eof' => true,
'ternary_operator_spaces' => true,
])
->setFinder($finder)
;
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ install:
- travis_retry composer update --prefer-dist $COMPOSER_OPTS

script:
- vendor/bin/phpcs --standard=psr2 src/
- vendor/bin/phpunit --exclude-group integration --coverage-text --coverage-clover coverage.xml
- vendor/bin/phpstan analyse -l 6 src/
- composer php-cs-fixer:lint
- composer test:unit
- composer analyze

after_script:
- wget https://scrutinizer-ci.com/ocular.phar
Expand Down
10 changes: 8 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,14 @@
"require-dev": {
"phpunit/phpunit": "^7.5",
"mockery/mockery": "^1.3",
"squizlabs/php_codesniffer": "^2.9",
"phpstan/phpstan": "^0.12.42"
"phpstan/phpstan": "^0.12.42",
"friendsofphp/php-cs-fixer": "^2.16"
},
"scripts": {
"analyze": "vendor/bin/phpstan analyse -l 6 src/",
"php-cs-fixer:lint": "vendor/bin/php-cs-fixer fix --verbose --dry-run",
"php-cs-fixer:format": "./vendor/bin/php-cs-fixer fix",
"test:unit": "vendor/bin/phpunit --coverage-text --coverage-clover coverage.xml"
},
"suggest": {
"ext-simplexml": "For decoding XML-based responses."
Expand Down
8 changes: 4 additions & 4 deletions src/Credentials/RsaClientCredentials.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ public function getRsaPublicKey()
return $this->rsaPublicKey;
}

if (!file_exists($this->rsaPublicKeyFile) || !is_readable($this->rsaPublicKeyFile)) {
if ( ! file_exists($this->rsaPublicKeyFile) || ! is_readable($this->rsaPublicKeyFile)) {
throw new CredentialsException('Could not read the public key file.');
}

$this->rsaPublicKey = openssl_get_publickey(file_get_contents($this->rsaPublicKeyFile));

if (!$this->rsaPublicKey) {
if ( ! $this->rsaPublicKey) {
throw new CredentialsException('Cannot access public key for signing');
}

Expand All @@ -77,13 +77,13 @@ public function getRsaPrivateKey()
return $this->rsaPrivateKey;
}

if (!file_exists($this->rsaPrivateKeyFile) || !is_readable($this->rsaPrivateKeyFile)) {
if ( ! file_exists($this->rsaPrivateKeyFile) || ! is_readable($this->rsaPrivateKeyFile)) {
throw new CredentialsException('Could not read the private key file.');
}

$this->rsaPrivateKey = openssl_pkey_get_private(file_get_contents($this->rsaPrivateKeyFile));

if (!$this->rsaPrivateKey) {
if ( ! $this->rsaPrivateKey) {
throw new CredentialsException('Cannot access private key for signing');
}

Expand Down
2 changes: 1 addition & 1 deletion src/Server/Bitbucket.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function userDetails($data, TokenCredentials $tokenCredentials): User

foreach ($data as $key => $value) {
if (strpos($key, 'url') !== false) {
if (!in_array($key, $used, true)) {
if ( ! in_array($key, $used, true)) {
$used[] = $key;
}

Expand Down
16 changes: 8 additions & 8 deletions src/Server/Magento.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,14 @@ public function urlUserDetails(): string

public function userDetails($data, TokenCredentials $tokenCredentials): User
{
if (!is_array($data) || empty($data)) {
if ( ! is_array($data) || empty($data)) {
throw new LogicException('Not possible to get user info');
}

$id = key($data);
$id = key($data);
$data = current($data);

$user = new User();
$user = new User();
$user->uid = $id;

$mapping = [
Expand All @@ -88,7 +88,7 @@ public function userDetails($data, TokenCredentials $tokenCredentials): User
];

foreach ($mapping as $userKey => $dataKey) {
if (!isset($data[$dataKey])) {
if ( ! isset($data[$dataKey])) {
continue;
}
$user->{$userKey} = $data[$dataKey];
Expand Down Expand Up @@ -154,11 +154,11 @@ protected function getHttpClientDefaultHeaders(): array
*/
private function parseConfigurationArray(array $configuration = []): void
{
if (!isset($configuration['host'])) {
if ( ! isset($configuration['host'])) {
throw new InvalidArgumentException('Missing Magento Host');
}

$url = parse_url($configuration['host']);
$url = parse_url($configuration['host']);
$this->baseUri = sprintf('%s://%s', $url['scheme'], $url['host']);

if (isset($url['port'])) {
Expand All @@ -168,8 +168,8 @@ private function parseConfigurationArray(array $configuration = []): void
if (isset($url['path'])) {
$this->baseUri .= '/' . trim($url['path'], '/');
}
$this->isAdmin = !empty($configuration['admin']);
if (!empty($configuration['adminUrl'])) {
$this->isAdmin = ! empty($configuration['admin']);
if ( ! empty($configuration['adminUrl'])) {
$this->adminUrl = $configuration['adminUrl'] . '/oauth_authorize';
} else {
$this->adminUrl = $this->baseUri . '/admin/oauth_authorize';
Expand Down
40 changes: 20 additions & 20 deletions src/Server/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
use GuzzleHttp\Exception\BadResponseException;
use GuzzleHttp\Exception\GuzzleException;
use InvalidArgumentException;
use League\OAuth1\Client\Credentials\ClientCredentialsInterface;
use League\OAuth1\Client\Credentials\ClientCredentials;
use League\OAuth1\Client\Credentials\CredentialsInterface;
use League\OAuth1\Client\Credentials\ClientCredentialsInterface;
use League\OAuth1\Client\Credentials\CredentialsException;
use League\OAuth1\Client\Credentials\CredentialsInterface;
use League\OAuth1\Client\Credentials\RsaClientCredentials;
use League\OAuth1\Client\Credentials\TemporaryCredentials;
use League\OAuth1\Client\Credentials\TokenCredentials;
Expand Down Expand Up @@ -52,13 +52,13 @@ public function __construct($clientCredentials, SignatureInterface $signature =
// Pass through an array or client credentials, we don't care
if (is_array($clientCredentials)) {
$clientCredentials = $this->createClientCredentials($clientCredentials);
} elseif (!$clientCredentials instanceof ClientCredentialsInterface) {
} elseif ( ! $clientCredentials instanceof ClientCredentialsInterface) {
throw new InvalidArgumentException('Client credentials must be an array or valid object.');
}

$this->clientCredentials = $clientCredentials;

if (!$signature && $clientCredentials instanceof RsaClientCredentials) {
if ( ! $signature && $clientCredentials instanceof RsaClientCredentials) {
$signature = new RsaSha1Signature($clientCredentials);
}
$this->signature = $signature ?: new HmacSha1Signature($clientCredentials);
Expand All @@ -77,9 +77,9 @@ public function getTemporaryCredentials(): TemporaryCredentials

$client = $this->createHttpClient();

$header = $this->temporaryCredentialsProtocolHeader($uri);
$header = $this->temporaryCredentialsProtocolHeader($uri);
$authorizationHeader = ['Authorization' => $header];
$headers = $this->buildHttpClientHeaders($authorizationHeader);
$headers = $this->buildHttpClientHeaders($authorizationHeader);

try {
$response = $client->post($uri, [
Expand All @@ -89,7 +89,7 @@ public function getTemporaryCredentials(): TemporaryCredentials
throw $this->getCredentialsExceptionForBadResponse($e, 'temporary credentials');
}

return $this->createTemporaryCredentials((string)$response->getBody());
return $this->createTemporaryCredentials((string) $response->getBody());
}

/**
Expand All @@ -108,7 +108,7 @@ public function getAuthorizationUrl($temporaryIdentifier): string

$parameters = ['oauth_token' => $temporaryIdentifier];

$url = $this->urlAuthorization();
$url = $this->urlAuthorization();
$queryString = http_build_query($parameters);

return $this->buildUrl($url, $queryString);
Expand Down Expand Up @@ -146,7 +146,7 @@ public function getTokenCredentials(
);
}

$uri = $this->urlTokenCredentials();
$uri = $this->urlTokenCredentials();
$bodyParameters = ['oauth_verifier' => $verifier];

$client = $this->createHttpClient();
Expand All @@ -162,7 +162,7 @@ public function getTokenCredentials(
throw $this->getCredentialsExceptionForBadResponse($e, 'token credentials');
}

return $this->createTokenCredentials((string)$response->getBody());
return $this->createTokenCredentials((string) $response->getBody());
}

/**
Expand Down Expand Up @@ -229,7 +229,7 @@ public function getUserScreenName(TokenCredentials $tokenCredentials, bool $forc
*/
protected function fetchUserDetails(TokenCredentials $tokenCredentials, bool $force = true)
{
if (!$this->cachedUserDetailsResponse || $force) {
if ( ! $this->cachedUserDetailsResponse || $force) {
$url = $this->urlUserDetails();

$client = $this->createHttpClient();
Expand All @@ -245,7 +245,7 @@ protected function fetchUserDetails(TokenCredentials $tokenCredentials, bool $fo
}
switch ($this->responseType) {
case 'json':
return $this->cachedUserDetailsResponse = json_decode((string)$response->getBody(), true);
return $this->cachedUserDetailsResponse = json_decode((string) $response->getBody(), true);

case 'xml':
if (function_exists('simplexml_load_string')) {
Expand All @@ -254,7 +254,7 @@ protected function fetchUserDetails(TokenCredentials $tokenCredentials, bool $fo
break;

case 'string':
parse_str((string)$response->getBody(), $this->cachedUserDetailsResponse);
parse_str((string) $response->getBody(), $this->cachedUserDetailsResponse);
break;
}

Expand Down Expand Up @@ -311,7 +311,7 @@ public function getHeaders(
string $url,
array $bodyParameters = []
): array {
$header = $this->protocolHeader(strtoupper($method), $url, $credentials, $bodyParameters);
$header = $this->protocolHeader(strtoupper($method), $url, $credentials, $bodyParameters);
$authorizationHeader = ['Authorization' => $header];

return $this->buildHttpClientHeaders($authorizationHeader);
Expand All @@ -323,7 +323,7 @@ public function getHeaders(
protected function getHttpClientDefaultHeaders(): array
{
$defaultHeaders = [];
if (!empty($this->userAgent)) {
if ( ! empty($this->userAgent)) {
$defaultHeaders['User-Agent'] = $this->userAgent;
}

Expand All @@ -348,7 +348,7 @@ protected function createClientCredentials(array $options): ClientCredentials
$keys = ['identifier', 'secret'];

foreach ($keys as $key) {
if (!isset($options[$key])) {
if ( ! isset($options[$key])) {
throw new InvalidArgumentException("Missing client credentials key [$key] from options.");
}
}
Expand Down Expand Up @@ -378,8 +378,8 @@ protected function getCredentialsExceptionForBadResponse(
BadResponseException $e,
string $type
): CredentialsException {
$response = $e->getResponse();
$body = $response->getBody();
$response = $e->getResponse();
$body = $response->getBody();
$statusCode = $response->getStatusCode();

return new CredentialsException(
Expand All @@ -401,7 +401,7 @@ protected function createTemporaryCredentials(string $body): TemporaryCredential
{
parse_str($body, $data);

if (!$data || !is_array($data)) {
if ( ! $data || ! is_array($data)) {
throw new CredentialsException('Unable to parse temporary credentials response.');
}

Expand All @@ -425,7 +425,7 @@ protected function createTokenCredentials(string $body): TokenCredentials
{
parse_str($body, $data);

if (!$data || !is_array($data)) {
if ( ! $data || ! is_array($data)) {
throw new CredentialsException('Unable to parse token credentials response.');
}

Expand Down
4 changes: 2 additions & 2 deletions src/Server/Trello.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public function urlTemporaryCredentials(): string

public function urlAuthorization(): string
{
return 'https://trello.com/1/OAuthAuthorizeToken?'.
return 'https://trello.com/1/OAuthAuthorizeToken?' .
$this->buildAuthorizationQueryParameters();
}

Expand All @@ -116,7 +116,7 @@ public function urlTokenCredentials(): string

public function urlUserDetails(): string
{
return 'https://trello.com/1/members/me?key='.$this->applicationKey.'&token='.$this->accessToken;
return 'https://trello.com/1/members/me?key=' . $this->applicationKey . '&token=' . $this->accessToken;
}

public function userDetails($data, TokenCredentials $tokenCredentials): User
Expand Down
6 changes: 3 additions & 3 deletions src/Server/Tumblr.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function urlUserDetails(): string
public function userDetails($data, TokenCredentials $tokenCredentials): User
{
// If the API has broke, return nothing
if (!is_array($data['response']['user'] ?? null)) {
if ( ! is_array($data['response']['user'] ?? null)) {
throw new LogicException('Not possible to get user info');
}

Expand All @@ -52,7 +52,7 @@ public function userDetails($data, TokenCredentials $tokenCredentials): User
*/
public function userUid($data, TokenCredentials $tokenCredentials)
{
if (!is_array($data['response']['user'] ?? null)) {
if ( ! is_array($data['response']['user'] ?? null)) {
return null;
}

Expand All @@ -68,7 +68,7 @@ public function userEmail($data, TokenCredentials $tokenCredentials):? string

public function userScreenName($data, TokenCredentials $tokenCredentials):? string
{
if (!is_array($data['response']['user'] ?? null)) {
if ( ! is_array($data['response']['user'] ?? null)) {
return null;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Server/Twitter.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function userDetails($data, TokenCredentials $tokenCredentials): User

foreach ($data as $key => $value) {
if (strpos($key, 'url') !== false) {
if (!in_array($key, $used, true)) {
if ( ! in_array($key, $used, true)) {
$used[] = $key;
}

Expand Down
Loading

0 comments on commit d58362a

Please sign in to comment.