Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump PHP-CS-Fixer and update code #1057

Merged
merged 7 commits into from
Dec 9, 2020
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
7 changes: 7 additions & 0 deletions .php_cs.dist
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,17 @@ return PhpCsFixer\Config::create()
// Additional rules
'fopen_flags' => true,
'linebreak_after_opening_tag' => true,
'native_constant_invocation' => true,
'native_function_invocation' => true,

// --- Diffs from @PhpCsFixer / @PhpCsFixer:risky ---

// This is the same as the default for the @PhpCsFixer ruleset, minus
// the following values: ['include', 'include_once', 'require',
// 'require_once']. We could enable them and remove this line after
// updating codegen for the `init.php` file to be compliant.
'blank_line_before_statement' => ['statements' => ['break', 'case', 'continue', 'declare', 'default', 'exit', 'goto', 'return', 'switch', 'throw', 'try']],

// This is just prettier / easier to read.
'concat_space' => ['spacing' => 'one'],

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"php-coveralls/php-coveralls": "^2.1",
"squizlabs/php_codesniffer": "^3.3",
"symfony/process": "~3.4",
"friendsofphp/php-cs-fixer": "2.16.5"
"friendsofphp/php-cs-fixer": "2.17.1"
},
"autoload": {
"psr-4": {
Expand Down
6 changes: 3 additions & 3 deletions lib/Account.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,9 @@ private function serializeAdditionalOwners($legalEntity, $additionalOwners)
$update = ($v instanceof StripeObject) ? $v->serializeParameters() : $v;

if ([] !== $update) {
if (!$originalValue ||
!\array_key_exists($i, $originalValue) ||
($update !== $legalEntity->serializeParamsValue($originalValue[$i], null, false, true))) {
if (!$originalValue
|| !\array_key_exists($i, $originalValue)
|| ($update !== $legalEntity->serializeParamsValue($originalValue[$i], null, false, true))) {
$updateArr[$i] = $update;
}
}
Expand Down
11 changes: 11 additions & 0 deletions lib/ApiRequestor.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,14 +187,19 @@ private static function _specificAPIError($rbody, $rcode, $rheaders, $resp, $err
// no break
case 404:
return Exception\InvalidRequestException::factory($msg, $rcode, $rbody, $resp, $rheaders, $code, $param);

case 401:
return Exception\AuthenticationException::factory($msg, $rcode, $rbody, $resp, $rheaders, $code);

case 402:
return Exception\CardException::factory($msg, $rcode, $rbody, $resp, $rheaders, $code, $declineCode, $param);

case 403:
return Exception\PermissionException::factory($msg, $rcode, $rbody, $resp, $rheaders, $code);

case 429:
return Exception\RateLimitException::factory($msg, $rcode, $rbody, $resp, $rheaders, $code, $param);

default:
return Exception\UnknownApiErrorException::factory($msg, $rcode, $rbody, $resp, $rheaders, $code);
}
Expand All @@ -218,16 +223,22 @@ private static function _specificOAuthError($rbody, $rcode, $rheaders, $resp, $e
switch ($errorCode) {
case 'invalid_client':
return Exception\OAuth\InvalidClientException::factory($description, $rcode, $rbody, $resp, $rheaders, $errorCode);

case 'invalid_grant':
return Exception\OAuth\InvalidGrantException::factory($description, $rcode, $rbody, $resp, $rheaders, $errorCode);

case 'invalid_request':
return Exception\OAuth\InvalidRequestException::factory($description, $rcode, $rbody, $resp, $rheaders, $errorCode);

case 'invalid_scope':
return Exception\OAuth\InvalidScopeException::factory($description, $rcode, $rbody, $resp, $rheaders, $errorCode);

case 'unsupported_grant_type':
return Exception\OAuth\UnsupportedGrantTypeException::factory($description, $rcode, $rbody, $resp, $rheaders, $errorCode);

case 'unsupported_response_type':
return Exception\OAuth\UnsupportedResponseTypeException::factory($description, $rcode, $rbody, $resp, $rheaders, $errorCode);

default:
return Exception\OAuth\UnknownOAuthErrorException::factory($description, $rcode, $rbody, $resp, $rheaders, $errorCode);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/ApiResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ public function __set($k, $v)
{
parent::__set($k, $v);
$v = $this->{$k};
if ((static::getSavedNestedResources()->includes($k)) &&
($v instanceof ApiResource)) {
if ((static::getSavedNestedResources()->includes($k))
&& ($v instanceof ApiResource)) {
$v->saveWithParent = true;
}
}
Expand Down
4 changes: 2 additions & 2 deletions lib/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ public function autoPagingIterator()

while (true) {
$filters = $this->filters ?: [];
if (\array_key_exists('ending_before', $filters) &&
!\array_key_exists('starting_after', $filters)) {
if (\array_key_exists('ending_before', $filters)
&& !\array_key_exists('starting_after', $filters)) {
foreach ($page->getReverseIterator() as $item) {
yield $item;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/EphemeralKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ class EphemeralKey extends ApiResource
{
const OBJECT_NAME = 'ephemeral_key';

use ApiOperations\Delete;

use ApiOperations\Create {
create as protected _create;
}

use ApiOperations\Delete;

/**
* @param null|array $params
* @param null|array|string $opts
Expand Down
6 changes: 4 additions & 2 deletions lib/HttpClient/CurlClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ public function request($method, $absUrl, $headers, $params, $hasFile)
// add an Idempotency-Key header
if (('post' === $method) && (Stripe::$maxNetworkRetries > 0)) {
if (!$this->hasHeader($headers, 'Idempotency-Key')) {
\array_push($headers, 'Idempotency-Key: ' . $this->randomGenerator->uuid());
$headers[] = 'Idempotency-Key: ' . $this->randomGenerator->uuid();
}
}

Expand All @@ -253,7 +253,7 @@ public function request($method, $absUrl, $headers, $params, $hasFile)
// we'll error under that condition. To compensate for that problem
// for the time being, override cURL's behavior by simply always
// sending an empty `Expect:` header.
\array_push($headers, 'Expect: ');
$headers[] = 'Expect: ';

$absUrl = Util\Util::utf8($absUrl);
$opts[\CURLOPT_URL] = $absUrl;
Expand Down Expand Up @@ -366,6 +366,7 @@ private function handleCurlError($url, $errno, $message, $numRetries)
. 'https://twitter.com/stripestatus, or';

break;

case \CURLE_SSL_CACERT:
case \CURLE_SSL_PEER_CERTIFICATE:
$msg = "Could not verify Stripe's SSL certificate. Please make sure "
Expand All @@ -374,6 +375,7 @@ private function handleCurlError($url, $errno, $message, $numRetries)
. 'If this problem persists,';

break;

default:
$msg = 'Unexpected error communicating with Stripe. '
. 'If this problem persists,';
Expand Down
2 changes: 1 addition & 1 deletion lib/StripeObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ public function serializeParamsValue($value, $original, $unsaved, $force, $key =
// Sequential array, i.e. a list
$update = [];
foreach ($value as $v) {
\array_push($update, $this->serializeParamsValue($v, null, true, $force));
$update[] = $this->serializeParamsValue($v, null, true, $force);
}
// This prevents an array that's unchanged from being resent.
if ($update !== $this->serializeParamsValue($original, null, true, $force, $key)) {
Expand Down
2 changes: 1 addition & 1 deletion lib/Util/RequestOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ private function redactedApiKey()
$redactedLast = \strlen($last) > 4
? (\str_repeat('*', \strlen($last) - 4) . \substr($last, -4))
: $last;
\array_push($pieces, $redactedLast);
$pieces[] = $redactedLast;

return \implode('_', $pieces);
}
Expand Down
6 changes: 3 additions & 3 deletions lib/Util/Util.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public static function convertToStripeObject($resp, $opts)
if (self::isList($resp)) {
$mapped = [];
foreach ($resp as $i) {
\array_push($mapped, self::convertToStripeObject($i, $opts));
$mapped[] = self::convertToStripeObject($i, $opts);
}

return $mapped;
Expand Down Expand Up @@ -138,7 +138,7 @@ public static function objectsToIds($h)
if (static::isList($h)) {
$results = [];
foreach ($h as $v) {
\array_push($results, static::objectsToIds($v));
$results[] = static::objectsToIds($v);
}

return $results;
Expand Down Expand Up @@ -169,7 +169,7 @@ public static function encodeParameters($params)
$pieces = [];
foreach ($flattenedParams as $param) {
list($k, $v) = $param;
\array_push($pieces, self::urlEncode($k) . '=' . self::urlEncode($v));
$pieces[] = self::urlEncode($k) . '=' . self::urlEncode($v);
}

return \implode('&', $pieces);
Expand Down
2 changes: 1 addition & 1 deletion lib/WebhookSignature.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ private static function getSignatures($header, $scheme)
foreach ($items as $item) {
$itemParts = \explode('=', $item, 2);
if (\trim($itemParts[0]) === $scheme) {
\array_push($signatures, $itemParts[1]);
$signatures[] = $itemParts[1];
}
}

Expand Down
14 changes: 7 additions & 7 deletions tests/Stripe/CollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public function testCanIterate()

$seen = [];
foreach ($collection as $item) {
\array_push($seen, $item['id']);
$seen[] = $item['id'];
}

static::assertSame(['1', '2', '3'], $seen);
Expand All @@ -128,7 +128,7 @@ public function testCanIterateBackwards()

$seen = [];
foreach ($collection->getReverseIterator() as $item) {
\array_push($seen, $item['id']);
$seen[] = $item['id'];
}

static::assertSame(['3', '2', '1'], $seen);
Expand All @@ -138,7 +138,7 @@ public function testSupportsIteratorToArray()
{
$seen = [];
foreach (\iterator_to_array($this->fixture) as $item) {
\array_push($seen, $item['id']);
$seen[] = $item['id'];
}

static::assertSame(['1'], $seen);
Expand All @@ -163,7 +163,7 @@ public function testProvidesAutoPagingIterator()

$seen = [];
foreach ($this->fixture->autoPagingIterator() as $item) {
\array_push($seen, $item['id']);
$seen[] = $item['id'];
}

static::assertSame(['1', '2', '3'], $seen);
Expand All @@ -188,7 +188,7 @@ public function testAutoPagingIteratorSupportsIteratorToArray()

$seen = [];
foreach (\iterator_to_array($this->fixture->autoPagingIterator()) as $item) {
\array_push($seen, $item['id']);
$seen[] = $item['id'];
}

static::assertSame(['1', '2', '3'], $seen);
Expand Down Expand Up @@ -220,7 +220,7 @@ public function testProvidesAutoPagingIteratorThatSupportsBackwardsPagination()

$seen = [];
foreach ($collection->autoPagingIterator() as $item) {
\array_push($seen, $item['id']);
$seen[] = $item['id'];
}

static::assertSame(['3', '2', '1'], $seen);
Expand Down Expand Up @@ -287,7 +287,7 @@ public function testNextPage()
$nextPage = $this->fixture->nextPage();
$ids = [];
foreach ($nextPage->data as $element) {
\array_push($ids, $element['id']);
$ids[] = $element['id'];
}
static::assertSame(['2', '3'], $ids);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/StripeMock.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public static function start()
if (static::$process->isRunning()) {
echo 'Started stripe-mock, PID = ' . static::$process->getPid() . "\n";
} else {
die('stripe-mock terminated early, exit code = ' . static::$process->wait());
exit('stripe-mock terminated early, exit code = ' . static::$process->wait());
}

return true;
Expand Down
3 changes: 3 additions & 0 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
if (\curl_errno($ch)) {
echo "Couldn't reach stripe-mock at `" . MOCK_HOST . ':' . MOCK_PORT . '`. Is ' .
"it running? Please see README for setup instructions.\n";

exit(1);
}

Expand All @@ -43,13 +44,15 @@
echo 'Could not retrieve Stripe-Mock-Version header. Are you sure ' .
'that the server at `' . MOCK_HOST . ':' . MOCK_PORT . '` is a stripe-mock ' .
'instance?';

exit(1);
}

if ('master' !== $version && -1 === \version_compare($version, MOCK_MINIMUM_VERSION)) {
echo 'Your version of stripe-mock (' . $version . ') is too old. The minimum ' .
'version to run this test suite is ' . MOCK_MINIMUM_VERSION . '. ' .
"Please see its repository for upgrade instructions.\n";

exit(1);
}

Expand Down