Skip to content

Commit

Permalink
fix code style
Browse files Browse the repository at this point in the history
  • Loading branch information
igor-chepurnoi committed Nov 22, 2016
1 parent ea8f72f commit b24d2e7
Show file tree
Hide file tree
Showing 17 changed files with 141 additions and 54 deletions.
23 changes: 23 additions & 0 deletions .php_cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

$finder = Symfony\CS\Finder::create()
->exclude('vendor')
->in([__DIR__]);

$config = Symfony\CS\Config::create()
->fixers([
'-phpdoc_params',
'-phpdoc_short_description',
'-phpdoc_inline_tag',
'-pre_increment',
'-heredoc_to_nowdoc',
'-spaces_cast',
'-include',
'-phpdoc_no_package',
'concat_with_spaces',
'ordered_use',
'short_array_syntax',
])
->finder($finder);

return $config;
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ sudo: false
cache:
directories:
- $HOME/.composer/cache
- vendor

install:
- travis_retry composer self-update && composer --version
Expand All @@ -20,4 +21,5 @@ install:
- travis_retry composer install --prefer-dist --no-interaction

script:
- phpunit --verbose $PHPUNIT_FLAGS
- vendor/friendsofphp/php-cs-fixer/php-cs-fixer fix --dry-run --diff
- phpunit --verbose $PHPUNIT_FLAGS
27 changes: 22 additions & 5 deletions Billable.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

/**
* Class Billable
*
* @package yii2mod\cashier
*/
trait Billable
Expand All @@ -35,6 +36,7 @@ trait Billable
*
* @param int $amount
* @param array $options
*
* @return \Stripe\Charge
*
* @throws \Stripe\Error\Card
Expand Down Expand Up @@ -63,11 +65,13 @@ public function charge($amount, array $options = [])
*
* @param $charge
* @param array $options
*
* @return StripeRefund
*/
public function refund($charge, array $options = [])
{
$options['charge'] = $charge;

return StripeRefund::create($options, ['api_key' => $this->getStripeKey()]);
}

Expand All @@ -87,6 +91,7 @@ public function hasCardOnFile()
* @param string $description
* @param int $amount
* @param array $options
*
* @return bool
*
* @throws \Stripe\Error\Card
Expand Down Expand Up @@ -116,6 +121,7 @@ public function invoiceFor($description, $amount, array $options = [])
*
* @param string $subscription
* @param string $plan
*
* @return SubscriptionBuilder
*/
public function newSubscription($subscription, $plan)
Expand All @@ -128,6 +134,7 @@ public function newSubscription($subscription, $plan)
*
* @param string $subscription
* @param string|null $plan
*
* @return bool
*/
public function onTrial($subscription = 'default', $plan = null)
Expand Down Expand Up @@ -159,6 +166,7 @@ public function onGenericTrial()
*
* @param string $subscription
* @param string|null $plan
*
* @return bool
*/
public function subscribed($subscription = 'default', $plan = null)
Expand All @@ -170,6 +178,7 @@ public function subscribed($subscription = 'default', $plan = null)
if (is_null($plan)) {
return $subscription->valid();
}

return $subscription->valid() &&
$subscription->stripePlan === $plan;
}
Expand All @@ -178,6 +187,7 @@ public function subscribed($subscription = 'default', $plan = null)
* Get a subscription instance by name.
*
* @param string $subscription
*
* @return SubscriptionModel|null
*/
public function subscription($subscription = 'default')
Expand Down Expand Up @@ -225,30 +235,31 @@ public function upcomingInvoice()

return new Invoice($this, $stripeInvoice);
} catch (InvalidRequest $e) {
//
}
}

/**
* Find an invoice by ID.
*
* @param string $id
*
* @return Invoice|null
*/
public function findInvoice($id)
{
try {
return new Invoice($this, StripeInvoice::retrieve($id, $this->getStripeKey()));
} catch (Exception $e) {

}
}

/**
* Find an invoice or throw a 404 error.
*
* @param string $id
*
* @return Invoice
*
* @throws NotFoundHttpException
*/
public function findInvoiceOrFail($id)
Expand All @@ -267,6 +278,7 @@ public function findInvoiceOrFail($id)
*
* @param string $id
* @param array $data
*
* @return Response
*/
public function downloadInvoice($id, array $data)
Expand All @@ -279,6 +291,7 @@ public function downloadInvoice($id, array $data)
*
* @param bool $includePending
* @param array $parameters
*
* @return array
*/
public function invoices($includePending = false, $parameters = [])
Expand Down Expand Up @@ -307,6 +320,7 @@ public function invoices($includePending = false, $parameters = [])
* Get an array of the entity's invoices.
*
* @param array $parameters
*
* @return array
*/
public function invoicesIncludingPending(array $parameters = [])
Expand All @@ -318,7 +332,6 @@ public function invoicesIncludingPending(array $parameters = [])
* Update customer's credit card.
*
* @param string $token
* @return void
*/
public function updateCard($token)
{
Expand Down Expand Up @@ -367,13 +380,15 @@ public function updateCardFromStripe()
$this->cardLastFour = null;
$this->update(false);
}

return $this;
}

/**
* Fills the user's properties with the source from Stripe.
*
* @param \Stripe\Card|null $card
*
* @return $this
*/
protected function fillCardDetails($card)
Expand All @@ -382,14 +397,14 @@ protected function fillCardDetails($card)
$this->cardBrand = $card->brand;
$this->cardLastFour = $card->last4;
}

return $this;
}

/**
* Apply a coupon to the billable entity.
*
* @param string $coupon
* @return void
*/
public function applyCoupon($coupon)
{
Expand All @@ -405,6 +420,7 @@ public function applyCoupon($coupon)
*
* @param array|string $plans
* @param string $subscription
*
* @return bool
*/
public function subscribedToPlan($plans, $subscription = 'default')
Expand All @@ -428,6 +444,7 @@ public function subscribedToPlan($plans, $subscription = 'default')
* Determine if the entity is on the given plan.
*
* @param string $plan
*
* @return bool
*/
public function onPlan($plan)
Expand All @@ -452,6 +469,7 @@ public function hasStripeId()
*
* @param string $token
* @param array $options
*
* @return Customer
*/
public function createAsStripeCustomer($token, array $options = [])
Expand Down Expand Up @@ -522,7 +540,6 @@ public static function getStripeKey()
* Set the Stripe API key.
*
* @param string $key
* @return void
*/
public static function setStripeKey($key)
{
Expand Down
17 changes: 9 additions & 8 deletions Cashier.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

/**
* Class Cashier
*
* @package yii2mod\cashier
*/
class Cashier
Expand All @@ -17,14 +18,14 @@ class Cashier
* @var string
*/
protected static $currency = 'usd';

/**
* The current currency symbol.
*
* @var string
*/
protected static $currencySymbol = '$';

/**
* The custom currency formatter.
*
Expand All @@ -37,7 +38,6 @@ class Cashier
*
* @param string $currency
* @param string|null $symbol
* @return void
*/
public static function useCurrency($currency, $symbol = null)
{
Expand All @@ -49,7 +49,9 @@ public static function useCurrency($currency, $symbol = null)
* Guess the currency symbol for the given currency.
*
* @param string $currency
*
* @return string
*
* @throws Exception
*/
protected static function guessCurrencySymbol($currency)
Expand All @@ -64,7 +66,7 @@ protected static function guessCurrencySymbol($currency)
case 'gbp':
return '£';
default:
throw new Exception("Unable to guess symbol for currency. Please explicitly specify it.");
throw new Exception('Unable to guess symbol for currency. Please explicitly specify it.');
}
}

Expand All @@ -82,7 +84,6 @@ public static function usesCurrency()
* Set the currency symbol to be used when formatting currency.
*
* @param string $symbol
* @return void
*/
public static function useCurrencySymbol($symbol)
{
Expand All @@ -103,7 +104,6 @@ public static function usesCurrencySymbol()
* Set the custom currency formatter.
*
* @param callable $callback
* @return void
*/
public static function formatCurrencyUsing(callable $callback)
{
Expand All @@ -114,6 +114,7 @@ public static function formatCurrencyUsing(callable $callback)
* Format the given amount into a displayable currency.
*
* @param int $amount
*
* @return string
*/
public static function formatAmount($amount)
Expand All @@ -125,7 +126,7 @@ public static function formatAmount($amount)
if (StringHelper::startsWith($amount, '-')) {
return '-' . static::usesCurrencySymbol() . ltrim($amount, '-');
}

return static::usesCurrencySymbol() . $amount;
}

}
}
Loading

0 comments on commit b24d2e7

Please sign in to comment.