From 3598dd711b045f71bc00e16035f7388288cfa3bc Mon Sep 17 00:00:00 2001 From: Olivier Bellone Date: Tue, 8 Dec 2020 12:12:50 -0800 Subject: [PATCH 1/7] Upgrade PHP-CS-Fixer to 2.17.1 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 1a72a4abc..17bde01c3 100644 --- a/composer.json +++ b/composer.json @@ -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": { From cef557d44c61222c7e61cf90f437f25c4532bb1f Mon Sep 17 00:00:00 2001 From: Olivier Bellone Date: Tue, 8 Dec 2020 12:13:46 -0800 Subject: [PATCH 2/7] Enable native_constant_invocation rule --- .php_cs.dist | 1 + 1 file changed, 1 insertion(+) diff --git a/.php_cs.dist b/.php_cs.dist index 83660ffcd..ab067fb80 100644 --- a/.php_cs.dist +++ b/.php_cs.dist @@ -13,6 +13,7 @@ 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 --- From 61c5ded5b44d95abf7d6dc813d1f3ce672db928c Mon Sep 17 00:00:00 2001 From: Olivier Bellone Date: Tue, 8 Dec 2020 12:19:33 -0800 Subject: [PATCH 3/7] Comply with no_alias_language_construct_call rule --- tests/StripeMock.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/StripeMock.php b/tests/StripeMock.php index 0efcaba4a..d1a1669b1 100644 --- a/tests/StripeMock.php +++ b/tests/StripeMock.php @@ -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; From 0ce0dff83c0774fa3a5d09352ba2333d330fbcf5 Mon Sep 17 00:00:00 2001 From: Olivier Bellone Date: Tue, 8 Dec 2020 15:16:00 -0800 Subject: [PATCH 4/7] Comply with array_push rule --- lib/HttpClient/CurlClient.php | 4 ++-- lib/StripeObject.php | 2 +- lib/Util/RequestOptions.php | 2 +- lib/Util/Util.php | 6 +++--- lib/WebhookSignature.php | 2 +- tests/Stripe/CollectionTest.php | 14 +++++++------- 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/lib/HttpClient/CurlClient.php b/lib/HttpClient/CurlClient.php index ae78a6cd7..8f677b350 100644 --- a/lib/HttpClient/CurlClient.php +++ b/lib/HttpClient/CurlClient.php @@ -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(); } } @@ -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; diff --git a/lib/StripeObject.php b/lib/StripeObject.php index a7a331f85..eca01a00e 100644 --- a/lib/StripeObject.php +++ b/lib/StripeObject.php @@ -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)) { diff --git a/lib/Util/RequestOptions.php b/lib/Util/RequestOptions.php index 1effb9ab5..89924bb6c 100644 --- a/lib/Util/RequestOptions.php +++ b/lib/Util/RequestOptions.php @@ -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); } diff --git a/lib/Util/Util.php b/lib/Util/Util.php index 595a7d61d..4f390500a 100644 --- a/lib/Util/Util.php +++ b/lib/Util/Util.php @@ -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; @@ -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; @@ -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); diff --git a/lib/WebhookSignature.php b/lib/WebhookSignature.php index 1bb22db8f..46cbb28b5 100644 --- a/lib/WebhookSignature.php +++ b/lib/WebhookSignature.php @@ -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]; } } diff --git a/tests/Stripe/CollectionTest.php b/tests/Stripe/CollectionTest.php index df40fdf3c..3958a0bb6 100644 --- a/tests/Stripe/CollectionTest.php +++ b/tests/Stripe/CollectionTest.php @@ -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); @@ -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); @@ -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); @@ -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); @@ -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); @@ -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); @@ -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); } From 8959b568e234ec2091c5aab802953c235dfe7cab Mon Sep 17 00:00:00 2001 From: Olivier Bellone Date: Tue, 8 Dec 2020 15:26:35 -0800 Subject: [PATCH 5/7] Comply with blank_line_before_statement rule --- .php_cs.dist | 6 ++++++ lib/ApiRequestor.php | 11 +++++++++++ lib/HttpClient/CurlClient.php | 2 ++ tests/bootstrap.php | 3 +++ 4 files changed, 22 insertions(+) diff --git a/.php_cs.dist b/.php_cs.dist index ab067fb80..2ebf9f3d8 100644 --- a/.php_cs.dist +++ b/.php_cs.dist @@ -18,6 +18,12 @@ return PhpCsFixer\Config::create() // --- 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'], diff --git a/lib/ApiRequestor.php b/lib/ApiRequestor.php index d3d7e7af1..048c462c0 100644 --- a/lib/ApiRequestor.php +++ b/lib/ApiRequestor.php @@ -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); } @@ -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); } diff --git a/lib/HttpClient/CurlClient.php b/lib/HttpClient/CurlClient.php index 8f677b350..b82451857 100644 --- a/lib/HttpClient/CurlClient.php +++ b/lib/HttpClient/CurlClient.php @@ -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 " @@ -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,'; diff --git a/tests/bootstrap.php b/tests/bootstrap.php index ad7cc1e50..4b498bd81 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -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); } @@ -43,6 +44,7 @@ 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); } @@ -50,6 +52,7 @@ 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); } From 8a4d42562bbd22d9650ca42803b6b4d352c456af Mon Sep 17 00:00:00 2001 From: Olivier Bellone Date: Tue, 8 Dec 2020 15:32:34 -0800 Subject: [PATCH 6/7] Comply with operator_linebreak rule --- lib/Account.php | 6 +++--- lib/ApiResource.php | 4 ++-- lib/Collection.php | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/Account.php b/lib/Account.php index 5cd0d80da..4fa789f21 100644 --- a/lib/Account.php +++ b/lib/Account.php @@ -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; } } diff --git a/lib/ApiResource.php b/lib/ApiResource.php index 064f99c1a..521010b3f 100644 --- a/lib/ApiResource.php +++ b/lib/ApiResource.php @@ -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; } } diff --git a/lib/Collection.php b/lib/Collection.php index ec5bebb7a..899299d3d 100644 --- a/lib/Collection.php +++ b/lib/Collection.php @@ -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; } From 00a5e65715b9577c3059114236dddbcdb2fa1da3 Mon Sep 17 00:00:00 2001 From: Olivier Bellone Date: Tue, 8 Dec 2020 15:33:37 -0800 Subject: [PATCH 7/7] Comply with ordered_traits rule --- lib/EphemeralKey.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/EphemeralKey.php b/lib/EphemeralKey.php index 544f0d785..253256cfd 100644 --- a/lib/EphemeralKey.php +++ b/lib/EphemeralKey.php @@ -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