Skip to content

Commit

Permalink
Apply fixes from StyleCI
Browse files Browse the repository at this point in the history
  • Loading branch information
Lloople authored and StyleCIBot committed Oct 3, 2019
1 parent d98bff9 commit 36e6486
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 41 deletions.
2 changes: 1 addition & 1 deletion src/Contracts/CurrenciesRepositoryContract.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ public function get(string $currency): ?Currency;
public function has(string $currency): bool;

public function append(Currency $currency): void;
}
}
20 changes: 10 additions & 10 deletions src/Converter.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@

class Converter
{
/** @var Price */
/** @var Price */
private $price;

/** @var Currency */
/** @var Currency */
private $currency;

/** @var CurrenciesRepositoryContract */
/** @var CurrenciesRepositoryContract */
private $currencies;
/** @var Currency */

/** @var Currency */
private $base;

public function __construct(Currency $baseCurrency, CurrenciesRepositoryContract $currencies)
Expand All @@ -27,11 +27,11 @@ public function __construct(Currency $baseCurrency, CurrenciesRepositoryContract

public function price(): Price
{
return $this->price;
return $this->price;
}

public function currency(): ?Currency
{
public function currency(): ?Currency
{
return $this->currency;
}

Expand Down Expand Up @@ -94,8 +94,8 @@ public function convert(): Price
*/
public function convertAmount(Currency $currency)
{
$ratio = $this->currency() && $this->currency()->is($this->base()->name())
? $this->base()->ratio()/$currency->ratio()
$ratio = $this->currency() && $this->currency()->is($this->base()->name())
? $this->base()->ratio() / $currency->ratio()
: $currency->ratio();

return round($this->price()->amount() * $ratio, $currency->decimals());
Expand Down
9 changes: 4 additions & 5 deletions src/CurrenciesRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@

namespace GNAHotelSolutions\CurrencyConverter;

use GNAHotelSolutions\CurrencyConverter\Contracts\CurrenciesRepositoryContract;
use GNAHotelSolutions\CurrencyConverter\Exceptions\CurrencyNotFoundException;
use GNAHotelSolutions\CurrencyConverter\Contracts\CurrenciesRepositoryContract;

class CurrenciesRepository implements CurrenciesRepositoryContract
{

/** @var array */
/** @var array */
private $currencies;

public function __construct(array $currencies)
Expand All @@ -29,11 +28,11 @@ public function get(string $currency): ?Currency

public function append(Currency $currency): void
{
$this->currencies[$currency->name()] = $currency;
$this->currencies[$currency->name()] = $currency;
}

public function has(string $currency): bool
{
return isset($this->currencies[$currency]);
}
}
}
10 changes: 5 additions & 5 deletions src/Currency.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

class Currency
{
/** @var string */
/** @var string */
private $name;
/** @var float */

/** @var float */
private $ratio;

/** @var int */
/** @var int */
private $decimals;

public function __construct(string $name, float $ratio, int $decimals)
Expand Down Expand Up @@ -45,4 +45,4 @@ public function is(...$currencies): bool

return false;
}
}
}
3 changes: 1 addition & 2 deletions src/Exceptions/CurrencyNotFoundException.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@

class CurrencyNotFoundException extends Exception
{

public function __construct(string $currency)
{
parent::__construct("Currency {$currency} does not found.");
}
}
}
19 changes: 9 additions & 10 deletions src/Price.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@

class Price
{

/** @var float */
/** @var float */
protected $amount;

/** @var string */
/** @var string */
protected $currency;

const CURRENCY_SYMBOLS = [
Expand All @@ -25,14 +24,14 @@ public function __construct($amount, string $currency)
$this->amount = $this->parseAmount($amount);
}

public function amount(): float
{
return $this->amount;
public function amount(): float
{
return $this->amount;
}

public function currency(): string
public function currency(): string
{
return $this->currency;
return $this->currency;
}

private function parseCurrency($currency): string
Expand All @@ -46,7 +45,7 @@ private function parseCurrency($currency): string

protected function parseAmount($amount): float
{
return (float)$amount;
return (float) $amount;
}

public function formattedWith(string $currency): string
Expand All @@ -62,4 +61,4 @@ public function __toString()
{
return "{$this->getAmount()} {$this->getCurrency()}";
}
}
}
14 changes: 6 additions & 8 deletions tests/ConverterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@

namespace Tests;

use PHPUnit\Framework\TestCase;
use GNAHotelSolutions\CurrencyConverter\Price;
use GNAHotelSolutions\CurrencyConverter\Currency;
use GNAHotelSolutions\CurrencyConverter\Converter;
use GNAHotelSolutions\CurrencyConverter\CurrenciesRepository;
use GNAHotelSolutions\CurrencyConverter\Currency;
use GNAHotelSolutions\CurrencyConverter\Exceptions\CurrencyNotFoundException;
use GNAHotelSolutions\CurrencyConverter\Price;
use PHPUnit\Framework\TestCase;

class ConverterTest extends TestCase
{

/** @var Converter */
/** @var Converter */
private $converter;

protected function setUp()
Expand All @@ -24,7 +23,7 @@ protected function setUp()
$this->repository = new CurrenciesRepository([
$baseCurrency,
new Currency('USD', 0.5, 2),
new Currency('GBP', 2, 2)
new Currency('GBP', 2, 2),
]);

$this->converter = new Converter($baseCurrency, $this->repository);
Expand Down Expand Up @@ -100,7 +99,7 @@ public function currency_is_converted()
public function exception_is_thrown_if_currency_does_not_exists()
{
$this->expectException(CurrencyNotFoundException::class);

$price = $this->converter->from(new Price(500, 'USD'))->to('WWW')->convert();
}

Expand Down Expand Up @@ -136,6 +135,5 @@ public function decimals_are_displayed_depending_on_the_currency()
$this->converter->from(new Price(4, 'USD'));

$this->assertEquals(2, $this->converter->convertAmount($currency));

}
}

0 comments on commit 36e6486

Please sign in to comment.