Skip to content

Commit

Permalink
Replaced all cases of explicit class strings with the SomeClass:class…
Browse files Browse the repository at this point in the history
… constant available in 5.6.
  • Loading branch information
nickdnk authored and ob-stripe committed Aug 2, 2019
1 parent 4b2be0e commit e76eff7
Show file tree
Hide file tree
Showing 52 changed files with 333 additions and 333 deletions.
8 changes: 4 additions & 4 deletions lib/ApiOperations/All.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ public static function all($params = null, $opts = null)

list($response, $opts) = static::_staticRequest('get', $url, $params, $opts);
$obj = \Stripe\Util\Util::convertToStripeObject($response->json, $opts);
if (!is_a($obj, 'Stripe\\Collection')) {
$class = get_class($obj);
$message = "Expected type \"Stripe\\Collection\", got \"$class\" instead";
throw new \Stripe\Error\Api($message);
if (!($obj instanceof \Stripe\Collection)) {
throw new \Stripe\Error\Api(
'Expected type ' . \Stripe\Collection::class . ', got "' . get_class($obj) . '" instead.'
);
}
$obj->setLastResponse($response);
$obj->setRequestParams($params);
Expand Down
162 changes: 81 additions & 81 deletions lib/Util/Util.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,88 +67,88 @@ public static function convertToStripeObject($resp, $opts)
{
$types = [
// data structures
\Stripe\Collection::OBJECT_NAME => 'Stripe\\Collection',
\Stripe\Collection::OBJECT_NAME => \Stripe\Collection::class,

// business objects
\Stripe\Account::OBJECT_NAME => 'Stripe\\Account',
\Stripe\AccountLink::OBJECT_NAME => 'Stripe\\AccountLink',
\Stripe\AlipayAccount::OBJECT_NAME => 'Stripe\\AlipayAccount',
\Stripe\ApplePayDomain::OBJECT_NAME => 'Stripe\\ApplePayDomain',
\Stripe\ApplicationFee::OBJECT_NAME => 'Stripe\\ApplicationFee',
\Stripe\Balance::OBJECT_NAME => 'Stripe\\Balance',
\Stripe\BalanceTransaction::OBJECT_NAME => 'Stripe\\BalanceTransaction',
\Stripe\BankAccount::OBJECT_NAME => 'Stripe\\BankAccount',
\Stripe\BitcoinReceiver::OBJECT_NAME => 'Stripe\\BitcoinReceiver',
\Stripe\BitcoinTransaction::OBJECT_NAME => 'Stripe\\BitcoinTransaction',
\Stripe\Capability::OBJECT_NAME => 'Stripe\\Capability',
\Stripe\Card::OBJECT_NAME => 'Stripe\\Card',
\Stripe\Charge::OBJECT_NAME => 'Stripe\\Charge',
\Stripe\Checkout\Session::OBJECT_NAME => 'Stripe\\Checkout\\Session',
\Stripe\CountrySpec::OBJECT_NAME => 'Stripe\\CountrySpec',
\Stripe\Coupon::OBJECT_NAME => 'Stripe\\Coupon',
\Stripe\CreditNote::OBJECT_NAME => 'Stripe\\CreditNote',
\Stripe\Customer::OBJECT_NAME => 'Stripe\\Customer',
\Stripe\CustomerBalanceTransaction::OBJECT_NAME => 'Stripe\\CustomerBalanceTransaction',
\Stripe\Discount::OBJECT_NAME => 'Stripe\\Discount',
\Stripe\Dispute::OBJECT_NAME => 'Stripe\\Dispute',
\Stripe\EphemeralKey::OBJECT_NAME => 'Stripe\\EphemeralKey',
\Stripe\Event::OBJECT_NAME => 'Stripe\\Event',
\Stripe\ExchangeRate::OBJECT_NAME => 'Stripe\\ExchangeRate',
\Stripe\ApplicationFeeRefund::OBJECT_NAME => 'Stripe\\ApplicationFeeRefund',
\Stripe\File::OBJECT_NAME => 'Stripe\\File',
\Stripe\File::OBJECT_NAME_ALT => 'Stripe\\File',
\Stripe\FileLink::OBJECT_NAME => 'Stripe\\FileLink',
\Stripe\Invoice::OBJECT_NAME => 'Stripe\\Invoice',
\Stripe\InvoiceItem::OBJECT_NAME => 'Stripe\\InvoiceItem',
\Stripe\InvoiceLineItem::OBJECT_NAME => 'Stripe\\InvoiceLineItem',
\Stripe\IssuerFraudRecord::OBJECT_NAME => 'Stripe\\IssuerFraudRecord',
\Stripe\Issuing\Authorization::OBJECT_NAME => 'Stripe\\Issuing\\Authorization',
\Stripe\Issuing\Card::OBJECT_NAME => 'Stripe\\Issuing\\Card',
\Stripe\Issuing\CardDetails::OBJECT_NAME => 'Stripe\\Issuing\\CardDetails',
\Stripe\Issuing\Cardholder::OBJECT_NAME => 'Stripe\\Issuing\\Cardholder',
\Stripe\Issuing\Dispute::OBJECT_NAME => 'Stripe\\Issuing\\Dispute',
\Stripe\Issuing\Transaction::OBJECT_NAME => 'Stripe\\Issuing\\Transaction',
\Stripe\LoginLink::OBJECT_NAME => 'Stripe\\LoginLink',
\Stripe\Order::OBJECT_NAME => 'Stripe\\Order',
\Stripe\OrderItem::OBJECT_NAME => 'Stripe\\OrderItem',
\Stripe\OrderReturn::OBJECT_NAME => 'Stripe\\OrderReturn',
\Stripe\PaymentIntent::OBJECT_NAME => 'Stripe\\PaymentIntent',
\Stripe\PaymentMethod::OBJECT_NAME => 'Stripe\\PaymentMethod',
\Stripe\Payout::OBJECT_NAME => 'Stripe\\Payout',
\Stripe\Person::OBJECT_NAME => 'Stripe\\Person',
\Stripe\Plan::OBJECT_NAME => 'Stripe\\Plan',
\Stripe\Product::OBJECT_NAME => 'Stripe\\Product',
\Stripe\Radar\EarlyFraudWarning::OBJECT_NAME => 'Stripe\\Radar\\EarlyFraudWarning',
\Stripe\Radar\ValueList::OBJECT_NAME => 'Stripe\\Radar\\ValueList',
\Stripe\Radar\ValueListItem::OBJECT_NAME => 'Stripe\\Radar\\ValueListItem',
\Stripe\Recipient::OBJECT_NAME => 'Stripe\\Recipient',
\Stripe\RecipientTransfer::OBJECT_NAME => 'Stripe\\RecipientTransfer',
\Stripe\Refund::OBJECT_NAME => 'Stripe\\Refund',
\Stripe\Reporting\ReportRun::OBJECT_NAME => 'Stripe\\Reporting\\ReportRun',
\Stripe\Reporting\ReportType::OBJECT_NAME => 'Stripe\\Reporting\\ReportType',
\Stripe\Review::OBJECT_NAME => 'Stripe\\Review',
\Stripe\SetupIntent::OBJECT_NAME => 'Stripe\\SetupIntent',
\Stripe\SKU::OBJECT_NAME => 'Stripe\\SKU',
\Stripe\Sigma\ScheduledQueryRun::OBJECT_NAME => 'Stripe\\Sigma\\ScheduledQueryRun',
\Stripe\Source::OBJECT_NAME => 'Stripe\\Source',
\Stripe\SourceTransaction::OBJECT_NAME => 'Stripe\\SourceTransaction',
\Stripe\Subscription::OBJECT_NAME => 'Stripe\\Subscription',
\Stripe\SubscriptionItem::OBJECT_NAME => 'Stripe\\SubscriptionItem',
\Stripe\SubscriptionSchedule::OBJECT_NAME => 'Stripe\\SubscriptionSchedule',
\Stripe\SubscriptionScheduleRevision::OBJECT_NAME => 'Stripe\\SubscriptionScheduleRevision',
\Stripe\TaxId::OBJECT_NAME => 'Stripe\\TaxId',
\Stripe\TaxRate::OBJECT_NAME => 'Stripe\\TaxRate',
\Stripe\ThreeDSecure::OBJECT_NAME => 'Stripe\\ThreeDSecure',
\Stripe\Terminal\ConnectionToken::OBJECT_NAME => 'Stripe\\Terminal\\ConnectionToken',
\Stripe\Terminal\Location::OBJECT_NAME => 'Stripe\\Terminal\\Location',
\Stripe\Terminal\Reader::OBJECT_NAME => 'Stripe\\Terminal\\Reader',
\Stripe\Token::OBJECT_NAME => 'Stripe\\Token',
\Stripe\Topup::OBJECT_NAME => 'Stripe\\Topup',
\Stripe\Transfer::OBJECT_NAME => 'Stripe\\Transfer',
\Stripe\TransferReversal::OBJECT_NAME => 'Stripe\\TransferReversal',
\Stripe\UsageRecord::OBJECT_NAME => 'Stripe\\UsageRecord',
\Stripe\UsageRecordSummary::OBJECT_NAME => 'Stripe\\UsageRecordSummary',
\Stripe\WebhookEndpoint::OBJECT_NAME => 'Stripe\\WebhookEndpoint',
\Stripe\Account::OBJECT_NAME => \Stripe\Account::class,
\Stripe\AccountLink::OBJECT_NAME => \Stripe\AccountLink::class,
\Stripe\AlipayAccount::OBJECT_NAME => \Stripe\AlipayAccount::class,
\Stripe\ApplePayDomain::OBJECT_NAME => \Stripe\ApplePayDomain::class,
\Stripe\ApplicationFee::OBJECT_NAME => \Stripe\ApplicationFee::class,
\Stripe\ApplicationFeeRefund::OBJECT_NAME => \Stripe\ApplicationFeeRefund::class,
\Stripe\Balance::OBJECT_NAME => \Stripe\Balance::class,
\Stripe\BalanceTransaction::OBJECT_NAME => \Stripe\BalanceTransaction::class,
\Stripe\BankAccount::OBJECT_NAME => \Stripe\BankAccount::class,
\Stripe\BitcoinReceiver::OBJECT_NAME => \Stripe\BitcoinReceiver::class,
\Stripe\BitcoinTransaction::OBJECT_NAME => \Stripe\BitcoinTransaction::class,
\Stripe\Capability::OBJECT_NAME => \Stripe\Capability::class,
\Stripe\Card::OBJECT_NAME => \Stripe\Card::class,
\Stripe\Charge::OBJECT_NAME => \Stripe\Charge::class,
\Stripe\Checkout\Session::OBJECT_NAME => \Stripe\Checkout\Session::class,
\Stripe\CountrySpec::OBJECT_NAME => \Stripe\CountrySpec::class,
\Stripe\Coupon::OBJECT_NAME => \Stripe\Coupon::class,
\Stripe\CreditNote::OBJECT_NAME => \Stripe\CreditNote::class,
\Stripe\Customer::OBJECT_NAME => \Stripe\Customer::class,
\Stripe\CustomerBalanceTransaction::OBJECT_NAME => \Stripe\CustomerBalanceTransaction::class,
\Stripe\Discount::OBJECT_NAME => \Stripe\Discount::class,
\Stripe\Dispute::OBJECT_NAME => \Stripe\Dispute::class,
\Stripe\EphemeralKey::OBJECT_NAME => \Stripe\EphemeralKey::class,
\Stripe\Event::OBJECT_NAME => \Stripe\Event::class,
\Stripe\ExchangeRate::OBJECT_NAME => \Stripe\ExchangeRate::class,
\Stripe\File::OBJECT_NAME => \Stripe\File::class,
\Stripe\File::OBJECT_NAME_ALT => \Stripe\File::class,
\Stripe\FileLink::OBJECT_NAME => \Stripe\FileLink::class,
\Stripe\Invoice::OBJECT_NAME => \Stripe\Invoice::class,
\Stripe\InvoiceItem::OBJECT_NAME => \Stripe\InvoiceItem::class,
\Stripe\InvoiceLineItem::OBJECT_NAME => \Stripe\InvoiceLineItem::class,
\Stripe\IssuerFraudRecord::OBJECT_NAME => \Stripe\IssuerFraudRecord::class,
\Stripe\Issuing\Authorization::OBJECT_NAME => \Stripe\Issuing\Authorization::class,
\Stripe\Issuing\Card::OBJECT_NAME => \Stripe\Issuing\Card::class,
\Stripe\Issuing\CardDetails::OBJECT_NAME => \Stripe\Issuing\CardDetails::class,
\Stripe\Issuing\Cardholder::OBJECT_NAME => \Stripe\Issuing\Cardholder::class,
\Stripe\Issuing\Dispute::OBJECT_NAME => \Stripe\Issuing\Dispute::class,
\Stripe\Issuing\Transaction::OBJECT_NAME => \Stripe\Issuing\Transaction::class,
\Stripe\LoginLink::OBJECT_NAME => \Stripe\LoginLink::class,
\Stripe\Order::OBJECT_NAME => \Stripe\Order::class,
\Stripe\OrderItem::OBJECT_NAME => \Stripe\OrderItem::class,
\Stripe\OrderReturn::OBJECT_NAME => \Stripe\OrderReturn::class,
\Stripe\PaymentIntent::OBJECT_NAME => \Stripe\PaymentIntent::class,
\Stripe\PaymentMethod::OBJECT_NAME => \Stripe\PaymentMethod::class,
\Stripe\Payout::OBJECT_NAME => \Stripe\Payout::class,
\Stripe\Person::OBJECT_NAME => \Stripe\Person::class,
\Stripe\Plan::OBJECT_NAME => \Stripe\Plan::class,
\Stripe\Product::OBJECT_NAME => \Stripe\Product::class,
\Stripe\Radar\EarlyFraudWarning::OBJECT_NAME => \Stripe\Radar\EarlyFraudWarning::class,
\Stripe\Radar\ValueList::OBJECT_NAME => \Stripe\Radar\ValueList::class,
\Stripe\Radar\ValueListItem::OBJECT_NAME => \Stripe\Radar\ValueListItem::class,
\Stripe\Recipient::OBJECT_NAME => \Stripe\Recipient::class,
\Stripe\RecipientTransfer::OBJECT_NAME => \Stripe\RecipientTransfer::class,
\Stripe\Refund::OBJECT_NAME => \Stripe\Refund::class,
\Stripe\Reporting\ReportRun::OBJECT_NAME => \Stripe\Reporting\ReportRun::class,
\Stripe\Reporting\ReportType::OBJECT_NAME => \Stripe\Reporting\ReportType::class,
\Stripe\Review::OBJECT_NAME => \Stripe\Review::class,
\Stripe\SetupIntent::OBJECT_NAME => \Stripe\SetupIntent::class,
\Stripe\Sigma\ScheduledQueryRun::OBJECT_NAME => \Stripe\Sigma\ScheduledQueryRun::class,
\Stripe\SKU::OBJECT_NAME => \Stripe\SKU::class,
\Stripe\Source::OBJECT_NAME => \Stripe\Source::class,
\Stripe\SourceTransaction::OBJECT_NAME => \Stripe\SourceTransaction::class,
\Stripe\Subscription::OBJECT_NAME => \Stripe\Subscription::class,
\Stripe\SubscriptionItem::OBJECT_NAME => \Stripe\SubscriptionItem::class,
\Stripe\SubscriptionSchedule::OBJECT_NAME => \Stripe\SubscriptionSchedule::class,
\Stripe\SubscriptionScheduleRevision::OBJECT_NAME => \Stripe\SubscriptionScheduleRevision::class,
\Stripe\TaxId::OBJECT_NAME => \Stripe\TaxId::class,
\Stripe\TaxRate::OBJECT_NAME => \Stripe\TaxRate::class,
\Stripe\ThreeDSecure::OBJECT_NAME => \Stripe\ThreeDSecure::class,
\Stripe\Terminal\ConnectionToken::OBJECT_NAME => \Stripe\Terminal\ConnectionToken::class,
\Stripe\Terminal\Location::OBJECT_NAME => \Stripe\Terminal\Location::class,
\Stripe\Terminal\Reader::OBJECT_NAME => \Stripe\Terminal\Reader::class,
\Stripe\Token::OBJECT_NAME => \Stripe\Token::class,
\Stripe\Topup::OBJECT_NAME => \Stripe\Topup::class,
\Stripe\Transfer::OBJECT_NAME => \Stripe\Transfer::class,
\Stripe\TransferReversal::OBJECT_NAME => \Stripe\TransferReversal::class,
\Stripe\UsageRecord::OBJECT_NAME => \Stripe\UsageRecord::class,
\Stripe\UsageRecordSummary::OBJECT_NAME => \Stripe\UsageRecordSummary::class,
\Stripe\WebhookEndpoint::OBJECT_NAME => \Stripe\WebhookEndpoint::class,
];
if (self::isList($resp)) {
$mapped = [];
Expand All @@ -160,7 +160,7 @@ public static function convertToStripeObject($resp, $opts)
if (isset($resp['object']) && is_string($resp['object']) && isset($types[$resp['object']])) {
$class = $types[$resp['object']];
} else {
$class = 'Stripe\\StripeObject';
$class = \Stripe\StripeObject::class;
}
return $class::constructFrom($resp, $opts);
} else {
Expand Down
2 changes: 1 addition & 1 deletion tests/Stripe/AccountLinkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ public function testIsCreatable()
"success_url" => "https://stripe.com/success",
"type" => "custom_account_verification",
]);
$this->assertInstanceOf("Stripe\\AccountLink", $resource);
$this->assertInstanceOf(\Stripe\AccountLink::class, $resource);
}
}
32 changes: 16 additions & 16 deletions tests/Stripe/AccountTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function testIsListable()
);
$resources = Account::all();
$this->assertTrue(is_array($resources->data));
$this->assertInstanceOf("Stripe\\Account", $resources->data[0]);
$this->assertInstanceOf(\Stripe\Account::class, $resources->data[0]);
}

public function testIsRetrievable()
Expand All @@ -27,7 +27,7 @@ public function testIsRetrievable()
'/v1/accounts/' . self::TEST_RESOURCE_ID
);
$resource = Account::retrieve(self::TEST_RESOURCE_ID);
$this->assertInstanceOf("Stripe\\Account", $resource);
$this->assertInstanceOf(\Stripe\Account::class, $resource);
}

public function testIsRetrievableWithoutId()
Expand All @@ -37,7 +37,7 @@ public function testIsRetrievableWithoutId()
'/v1/account'
);
$resource = Account::retrieve();
$this->assertInstanceOf("Stripe\\Account", $resource);
$this->assertInstanceOf(\Stripe\Account::class, $resource);
}

public function testIsCreatable()
Expand All @@ -47,7 +47,7 @@ public function testIsCreatable()
'/v1/accounts'
);
$resource = Account::create(["type" => "custom"]);
$this->assertInstanceOf("Stripe\\Account", $resource);
$this->assertInstanceOf(\Stripe\Account::class, $resource);
}

public function testIsSaveable()
Expand All @@ -59,7 +59,7 @@ public function testIsSaveable()
'/v1/accounts/' . $resource->id
);
$resource->save();
$this->assertInstanceOf("Stripe\\Account", $resource);
$this->assertInstanceOf(\Stripe\Account::class, $resource);
}

public function testIsUpdatable()
Expand All @@ -71,7 +71,7 @@ public function testIsUpdatable()
$resource = Account::update(self::TEST_RESOURCE_ID, [
"metadata" => ["key" => "value"],
]);
$this->assertInstanceOf("Stripe\\Account", $resource);
$this->assertInstanceOf(\Stripe\Account::class, $resource);
}

public function testIsDeletable()
Expand All @@ -82,7 +82,7 @@ public function testIsDeletable()
'/v1/accounts/' . $resource->id
);
$resource->delete();
$this->assertInstanceOf("Stripe\\Account", $resource);
$this->assertInstanceOf(\Stripe\Account::class, $resource);
}

public function testIsRejectable()
Expand All @@ -93,7 +93,7 @@ public function testIsRejectable()
'/v1/accounts/' . $account->id . '/reject'
);
$resource = $account->reject(["reason" => "fraud"]);
$this->assertInstanceOf("Stripe\\Account", $resource);
$this->assertInstanceOf(\Stripe\Account::class, $resource);
$this->assertSame($resource, $account);
}

Expand Down Expand Up @@ -127,7 +127,7 @@ public function testPersons()
);
$persons = $account->persons();
$this->assertTrue(is_array($persons->data));
$this->assertInstanceOf("Stripe\\Person", $persons->data[0]);
$this->assertInstanceOf(\Stripe\Person::class, $persons->data[0]);
}

public function testCanRetrieveCapability()
Expand Down Expand Up @@ -171,7 +171,7 @@ public function testCanCreateExternalAccount()
$resource = Account::createExternalAccount(self::TEST_RESOURCE_ID, [
"external_account" => "btok_123",
]);
$this->assertInstanceOf("Stripe\\BankAccount", $resource);
$this->assertInstanceOf(\Stripe\BankAccount::class, $resource);
}

public function testCanRetrieveExternalAccount()
Expand All @@ -181,7 +181,7 @@ public function testCanRetrieveExternalAccount()
'/v1/accounts/' . self::TEST_RESOURCE_ID . '/external_accounts/' . self::TEST_EXTERNALACCOUNT_ID
);
$resource = Account::retrieveExternalAccount(self::TEST_RESOURCE_ID, self::TEST_EXTERNALACCOUNT_ID);
$this->assertInstanceOf("Stripe\\BankAccount", $resource);
$this->assertInstanceOf(\Stripe\BankAccount::class, $resource);
}

public function testCanUpdateExternalAccount()
Expand All @@ -193,7 +193,7 @@ public function testCanUpdateExternalAccount()
$resource = Account::updateExternalAccount(self::TEST_RESOURCE_ID, self::TEST_EXTERNALACCOUNT_ID, [
"name" => "name",
]);
$this->assertInstanceOf("Stripe\\BankAccount", $resource);
$this->assertInstanceOf(\Stripe\BankAccount::class, $resource);
}

public function testCanDeleteExternalAccount()
Expand Down Expand Up @@ -223,7 +223,7 @@ public function testCanCreateLoginLink()
'/v1/accounts/' . self::TEST_RESOURCE_ID . '/login_links'
);
$resource = Account::createLoginLink(self::TEST_RESOURCE_ID);
$this->assertInstanceOf("Stripe\\LoginLink", $resource);
$this->assertInstanceOf(\Stripe\LoginLink::class, $resource);
}

public function testCanCreatePerson()
Expand All @@ -239,7 +239,7 @@ public function testCanCreatePerson()
"year" => 1980
]
]);
$this->assertInstanceOf("Stripe\\Person", $resource);
$this->assertInstanceOf(\Stripe\Person::class, $resource);
}

public function testCanRetrievePerson()
Expand All @@ -249,7 +249,7 @@ public function testCanRetrievePerson()
'/v1/accounts/' . self::TEST_RESOURCE_ID . '/persons/' . self::TEST_PERSON_ID
);
$resource = Account::retrievePerson(self::TEST_RESOURCE_ID, self::TEST_PERSON_ID);
$this->assertInstanceOf("Stripe\\Person", $resource);
$this->assertInstanceOf(\Stripe\Person::class, $resource);
}

public function testCanUpdatePerson()
Expand All @@ -261,7 +261,7 @@ public function testCanUpdatePerson()
$resource = Account::updatePerson(self::TEST_RESOURCE_ID, self::TEST_PERSON_ID, [
"first_name" => "First name",
]);
$this->assertInstanceOf("Stripe\\Person", $resource);
$this->assertInstanceOf(\Stripe\Person::class, $resource);
}

public function testCanDeletePerson()
Expand Down
Loading

0 comments on commit e76eff7

Please sign in to comment.