Skip to content

Commit

Permalink
Drop CurrencyProvider interface
Browse files Browse the repository at this point in the history
Multiple implementations made sense only when methods accepting a currency code provided support for non-ISO currencies.
This support has been dropped as it required a global configuration for currency providers.
ISOCurrencyProvider is now the only provider available, hence moved to the base namespace.
  • Loading branch information
BenMorel committed Sep 27, 2017
1 parent c6861d9 commit 197c7e5
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 41 deletions.
2 changes: 1 addition & 1 deletion src/Currency.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Brick\Money;

use Brick\Money\CurrencyProvider\ISOCurrencyProvider;
use Brick\Money\ISOCurrencyProvider;
use Brick\Money\Exception\UnknownCurrencyException;

/**
Expand Down
29 changes: 0 additions & 29 deletions src/CurrencyProvider.php

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
<?php

namespace Brick\Money\CurrencyProvider;
namespace Brick\Money;

use Brick\Money\Currency;
use Brick\Money\CurrencyProvider;
use Brick\Money\Exception\UnknownCurrencyException;

/**
* Built-in provider for ISO currencies.
* Provides ISO 4217 currencies.
*/
class ISOCurrencyProvider implements CurrencyProvider
class ISOCurrencyProvider
{
/**
* @var ISOCurrencyProvider|null
Expand Down Expand Up @@ -53,7 +51,7 @@ class ISOCurrencyProvider implements CurrencyProvider
*/
private function __construct()
{
$this->currencyData = require __DIR__ . '/../../data/iso-currencies.php';
$this->currencyData = require __DIR__ . '/../data/iso-currencies.php';
}

/**
Expand All @@ -71,7 +69,13 @@ public static function getInstance()
}

/**
* {@inheritdoc}
* Returns the currency matching the given currency code.
*
* @param string $currencyCode The ISO 4217 currency code.
*
* @return Currency The currency.
*
* @throws UnknownCurrencyException If the currency code is not known.
*/
public function getCurrency($currencyCode)
{
Expand All @@ -89,7 +93,9 @@ public function getCurrency($currencyCode)
}

/**
* {@inheritdoc}
* Returns all the available currencies.
*
* @return Currency[] The currencies, indexed by currency code.
*/
public function getAvailableCurrencies()
{
Expand All @@ -100,6 +106,8 @@ public function getAvailableCurrencies()
}
}

ksort($this->currencies);

$this->isPartial = false;
}

Expand Down Expand Up @@ -150,7 +158,7 @@ public function getCurrencyForCountry($countryCode)
public function getCurrenciesForCountry($countryCode)
{
if ($this->countryToCurrency === null) {
$this->countryToCurrency = require __DIR__ . '/../../data/country-to-currency.php';
$this->countryToCurrency = require __DIR__ . '/../data/country-to-currency.php';
}

$result = [];
Expand Down
1 change: 0 additions & 1 deletion tests/AbstractTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Brick\Money\Context;
use Brick\Money\Currency;
use Brick\Money\CurrencyProvider;
use Brick\Money\Money;
use Brick\Money\MoneyBag;
use Brick\Money\RationalMoney;
Expand Down
2 changes: 1 addition & 1 deletion tests/CurrencyProvider/ISOCurrencyProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Brick\Money\Tests\CurrencyProvider;

use Brick\Money\Currency;
use Brick\Money\CurrencyProvider\ISOCurrencyProvider;
use Brick\Money\ISOCurrencyProvider;
use Brick\Money\Tests\AbstractTestCase;

/**
Expand Down

0 comments on commit 197c7e5

Please sign in to comment.