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

Increment PHPStan to strictness level 2 #1488

Merged
merged 10 commits into from
Apr 27, 2023
3 changes: 3 additions & 0 deletions lib/Account.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ public static function retrieve($id = null, $opts = null)
return self::_retrieve($id, $opts);
}

// TODO (MAJOR): Remove legal_entity/additional_owners logic. These properties are not present in API versions
// after 2019-02-19, so we ought to deprecate them from new releases of the library.
anniel-stripe marked this conversation as resolved.
Show resolved Hide resolved
public function serializeParameters($force = false)
{
$update = parent::serializeParameters($force);
Expand All @@ -127,6 +129,7 @@ public function serializeParameters($force = false)
return $update;
}

// TODO (MAJOR): Remove legal_entity/additional_owners logic.
anniel-stripe marked this conversation as resolved.
Show resolved Hide resolved
private function serializeAdditionalOwners($legalEntity, $additionalOwners)
{
if (isset($legalEntity->_originalValues['additional_owners'])) {
Expand Down
3 changes: 1 addition & 2 deletions lib/ApiOperations/SingletonRetrieve.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@
trait SingletonRetrieve
{
/**
* @param array|string $id the ID of the API resource to retrieve,
* @param null|array|string $opts the ID of the API resource to retrieve,
* or an options array containing an `id` key
* @param null|array|string $opts
*
* @throws \Stripe\Exception\ApiErrorException if the request fails
*
Expand Down
4 changes: 2 additions & 2 deletions lib/ApiRequestor.php
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ private static function _defaultHeaders($apiKey, $clientInfo = null)
$uaString = 'Stripe/v1 PhpBindings/' . Stripe::VERSION;

$langVersion = \PHP_VERSION;
$uname_disabled = static::_isDisabled(\ini_get('disable_functions'), 'php_uname');
$uname_disabled = self::_isDisabled(\ini_get('disable_functions'), 'php_uname');
$uname = $uname_disabled ? '(disabled)' : \php_uname();

$appInfo = Stripe::getAppInfo();
Expand Down Expand Up @@ -377,7 +377,7 @@ private function _prepareRequest($method, $url, $params, $headers)

if ($params && \is_array($params)) {
$optionKeysInParams = \array_filter(
static::$OPTIONS_KEYS,
self::$OPTIONS_KEYS,
function ($key) use ($params) {
return \array_key_exists($key, $params);
}
Expand Down
3 changes: 2 additions & 1 deletion lib/ApiResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

/**
* Class ApiResource.
*/
*
* */
abstract class ApiResource extends StripeObject
{
use ApiOperations\Request;
Expand Down
14 changes: 10 additions & 4 deletions lib/Service/AbstractService.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,22 +72,28 @@ private static function formatParams($params)

protected function request($method, $path, $params, $opts)
{
return $this->getClient()->request($method, $path, static::formatParams($params), $opts);
return $this->getClient()->request($method, $path, self::formatParams($params), $opts);
}

protected function requestStream($method, $path, $readBodyChunkCallable, $params, $opts)
{
return $this->getStreamingClient()->requestStream($method, $path, $readBodyChunkCallable, static::formatParams($params), $opts);
// TODO (MAJOR): Add this method to StripeClientInterface
anniel-stripe marked this conversation as resolved.
Show resolved Hide resolved
// @phpstan-ignore-next-line
return $this->getStreamingClient()->requestStream($method, $path, $readBodyChunkCallable, self::formatParams($params), $opts);
}

protected function requestCollection($method, $path, $params, $opts)
{
return $this->getClient()->requestCollection($method, $path, static::formatParams($params), $opts);
// TODO (MAJOR): Add this method to StripeClientInterface
anniel-stripe marked this conversation as resolved.
Show resolved Hide resolved
// @phpstan-ignore-next-line
return $this->getClient()->requestCollection($method, $path, self::formatParams($params), $opts);
}

protected function requestSearchResult($method, $path, $params, $opts)
{
return $this->getClient()->requestSearchResult($method, $path, static::formatParams($params), $opts);
// TODO (MAJOR): Add this method to StripeClientInterface
anniel-stripe marked this conversation as resolved.
Show resolved Hide resolved
// @phpstan-ignore-next-line
return $this->getClient()->requestSearchResult($method, $path, self::formatParams($params), $opts);
}

protected function buildPath($basePath, ...$ids)
Expand Down
2 changes: 1 addition & 1 deletion lib/Service/AccountService.php
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ public function updatePerson($parentId, $id, $params = null, $opts = null)
*
* @param null|string $id
* @param null|array $params
* @param null|array|StripeUtilRequestOptions $opts
* @param null|array|\Stripe\Util\RequestOptions $opts
*
* @throws \Stripe\Exception\ApiErrorException if the request fails
*
Expand Down
2 changes: 2 additions & 0 deletions lib/StripeObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

/**
* Class StripeObject.
*
* @property null|string $id
*/
class StripeObject implements \ArrayAccess, \Countable, \JsonSerializable
{
Expand Down
8 changes: 4 additions & 4 deletions lib/Util/CaseInsensitiveArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function getIterator()
#[\ReturnTypeWillChange]
public function offsetSet($offset, $value)
{
$offset = static::maybeLowercase($offset);
$offset = self::maybeLowercase($offset);
if (null === $offset) {
$this->container[] = $value;
} else {
Expand All @@ -59,7 +59,7 @@ public function offsetSet($offset, $value)
#[\ReturnTypeWillChange]
public function offsetExists($offset)
{
$offset = static::maybeLowercase($offset);
$offset = self::maybeLowercase($offset);

return isset($this->container[$offset]);
}
Expand All @@ -70,7 +70,7 @@ public function offsetExists($offset)
#[\ReturnTypeWillChange]
public function offsetUnset($offset)
{
$offset = static::maybeLowercase($offset);
$offset = self::maybeLowercase($offset);
unset($this->container[$offset]);
}

Expand All @@ -80,7 +80,7 @@ public function offsetUnset($offset)
#[\ReturnTypeWillChange]
public function offsetGet($offset)
{
$offset = static::maybeLowercase($offset);
$offset = self::maybeLowercase($offset);

return isset($this->container[$offset]) ? $this->container[$offset] : null;
}
Expand Down
2 changes: 1 addition & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ includes:
- phpstan-baseline.neon

parameters:
level: 1
level: 2

bootstrapFiles:
- tests/bootstrap.php
Expand Down
26 changes: 15 additions & 11 deletions tests/Stripe/AccountTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,6 @@ public function testCanDeleteExternalAccount()
'/v1/accounts/' . self::TEST_RESOURCE_ID . '/external_accounts/' . self::TEST_EXTERNALACCOUNT_ID
);
$resource = Account::deleteExternalAccount(self::TEST_RESOURCE_ID, self::TEST_EXTERNALACCOUNT_ID);
static::assertTrue($resource->deleted);
}

public function testCanListExternalAccounts()
Expand Down Expand Up @@ -277,7 +276,7 @@ public function testCanDeletePerson()
'/v1/accounts/' . self::TEST_RESOURCE_ID . '/persons/' . self::TEST_PERSON_ID
);
$resource = Account::deletePerson(self::TEST_RESOURCE_ID, self::TEST_PERSON_ID);
static::assertTrue($resource->deleted);
static::assertInstanceOf(\Stripe\Person::class, $resource);
}

public function testCanListPersons()
Expand All @@ -290,13 +289,15 @@ public function testCanListPersons()
static::compatAssertIsArray($resources->data);
}

// TODO (MAJOR): Remove legal_entity/additional_owners logic.
public function testSerializeNewAdditionalOwners()
{
/** @var Account $obj */
$obj = Util\Util::convertToStripeObject([
'object' => 'account',
'legal_entity' => StripeObject::constructFrom([]),
], null);
$obj->legal_entity->additional_owners = [
$obj['legal_entity']->additional_owners = [
['first_name' => 'Joe'],
['first_name' => 'Jane'],
];
Expand All @@ -323,7 +324,7 @@ public function testSerializeAddAdditionalOwners()
],
],
], null);
$obj->legal_entity->additional_owners[2] = ['first_name' => 'Andrew'];
$obj['legal_entity']->additional_owners[2] = ['first_name' => 'Andrew'];

$expected = [
'legal_entity' => [
Expand All @@ -346,7 +347,7 @@ public function testSerializePartiallyChangedAdditionalOwners()
],
],
], null);
$obj->legal_entity->additional_owners[1]->first_name = 'Stripe';
$obj['legal_entity']->additional_owners[1]->first_name = 'Stripe';

$expected = [
'legal_entity' => [
Expand Down Expand Up @@ -389,7 +390,7 @@ public function testSerializeUnsetAdditionalOwners()
],
],
], null);
$obj->legal_entity->additional_owners = null;
$obj['legal_entity']->additional_owners = null;

// Note that the empty string that we send for this one has a special
// meaning for the server, which interprets it as an array unset.
Expand All @@ -414,7 +415,7 @@ public function testSerializeAdditionalOwnersDeletedItem()
],
],
], null);
unset($obj->legal_entity->additional_owners[0]);
unset($obj['legal_entity']->additional_owners[0]);

$obj->serializeParameters();
}
Expand All @@ -424,7 +425,7 @@ public function testSerializeExternalAccountString()
$obj = Util\Util::convertToStripeObject([
'object' => 'account',
], null);
$obj->external_account = 'btok_123';
$obj['external_account'] = 'btok_123';

$expected = [
'external_account' => 'btok_123',
Expand All @@ -437,7 +438,7 @@ public function testSerializeExternalAccountHash()
$obj = Util\Util::convertToStripeObject([
'object' => 'account',
], null);
$obj->external_account = [
$obj['external_account'] = [
'object' => 'bank_account',
'routing_number' => '110000000',
'account_number' => '000123456789',
Expand All @@ -462,7 +463,7 @@ public function testSerializeBankAccountString()
$obj = Util\Util::convertToStripeObject([
'object' => 'account',
], null);
$obj->bank_account = 'btok_123';
$obj['bank_account'] = 'btok_123';

$expected = [
'bank_account' => 'btok_123',
Expand All @@ -475,7 +476,7 @@ public function testSerializeBankAccountHash()
$obj = Util\Util::convertToStripeObject([
'object' => 'account',
], null);
$obj->bank_account = [
$obj['bank_account'] = [
'object' => 'bank_account',
'routing_number' => '110000000',
'account_number' => '000123456789',
Expand All @@ -497,6 +498,7 @@ public function testSerializeBankAccountHash()

public function testSerializeNewIndividual()
{
/** @var \Stripe\Account $obj */
$obj = Util\Util::convertToStripeObject([
'object' => 'account',
], null);
Expand All @@ -508,6 +510,7 @@ public function testSerializeNewIndividual()

public function testSerializePartiallyChangedIndividual()
{
/** @var \Stripe\Account $obj */
$obj = Util\Util::convertToStripeObject([
'object' => 'account',
'individual' => Util\Util::convertToStripeObject([
Expand Down Expand Up @@ -537,6 +540,7 @@ public function testSerializeUnchangedIndividual()

public function testSerializeUnsetIndividual()
{
/** @var \Stripe\Account $obj */
$obj = Util\Util::convertToStripeObject([
'object' => 'account',
'individual' => Util\Util::convertToStripeObject([
Expand Down
2 changes: 2 additions & 0 deletions tests/Stripe/CustomerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ public function testCanListSources()

public function testSerializeSourceString()
{
/** @var mixed $obj */
$obj = Util\Util::convertToStripeObject([
'object' => 'customer',
], null);
Expand All @@ -155,6 +156,7 @@ public function testSerializeSourceString()

public function testSerializeSourceMap()
{
/** @var mixed $obj */
$obj = Util\Util::convertToStripeObject([
'object' => 'customer',
], null);
Expand Down
4 changes: 2 additions & 2 deletions tests/Stripe/OAuthTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function testToken()
'grant_type' => 'authorization_code',
'code' => 'this_is_an_authorization_code',
]);
static::assertSame('sk_access_token', $resp->access_token);
static::assertSame('sk_access_token', $resp['access_token']);
}

public function testDeauthorize()
Expand All @@ -97,6 +97,6 @@ public function testDeauthorize()
$resp = OAuth::deauthorize([
'stripe_user_id' => 'acct_test_deauth',
]);
static::assertSame('acct_test_deauth', $resp->stripe_user_id);
static::assertSame('acct_test_deauth', $resp['stripe_user_id']);
}
}
4 changes: 2 additions & 2 deletions tests/Stripe/Service/OAuthServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public function testToken()
'grant_type' => 'authorization_code',
'code' => 'this_is_an_authorization_code',
]);
static::assertSame('sk_access_token', $resp->access_token);
static::assertSame('sk_access_token', $resp['access_token']);
}

public function testDeauthorize()
Expand All @@ -135,6 +135,6 @@ public function testDeauthorize()
'client_id' => 'ca_123',
'stripe_user_id' => 'acct_test',
]);
static::assertSame('acct_test', $resp->stripe_user_id);
static::assertSame('acct_test', $resp['stripe_user_id']);
}
}
11 changes: 7 additions & 4 deletions tests/Stripe/SourceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,15 @@ public function testCanSaveCardExpiryDate()
$response
);

$source->card->exp_month = 12;
$source->card->exp_year = 2022;
/** @var mixed $card */
$card = $source->card;

$card->exp_month = 12;
$card->exp_year = 2022;
$source->save();

static::assertSame(12, $source->card->exp_month);
static::assertSame(2022, $source->card->exp_year);
static::assertSame(12, $source['card']['exp_month']);
static::assertSame(2022, $source['card']['exp_year']);
}

public function testIsDetachableWhenAttached()
Expand Down
Loading