Skip to content
This repository has been archived by the owner on Jan 22, 2018. It is now read-only.

Commit

Permalink
📝 Add some docblocks
Browse files Browse the repository at this point in the history
  • Loading branch information
ivank committed Jun 10, 2014
1 parent 64251f7 commit 2c00591
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 2 deletions.
25 changes: 25 additions & 0 deletions src/Converter.php
Expand Up @@ -13,13 +13,23 @@
*/
class Converter
{
/**
* @var Converter
*/
private static $instance;

/**
* Create a new Converter object that you can later get through "::get()"
* @param SourceInterface $source
*/
public static function initialize(SourceInterface $source)
{
self::$instance = new static($source);
}

/**
* @return Converter
*/
public static function get()
{
if (! self::$instance) {
Expand All @@ -29,23 +39,38 @@ public static function get()
return self::$instance;
}

/**
* Clear the object, returned through "::get"
*/
public static function clear()
{
self::$instance = null;
}

/**
* @var SourceInterface
*/
private $source;

public function __construct(SourceInterface $source)
{
$this->source = $source;
}

/**
* @return SourceInterface
*/
public function getSource()
{
return $this->source;
}

/**
* @param Money $money
* @param Currency $to
* @param int $roundingMode
* @return Money
*/
public function convert(Money $money, Currency $to, $roundingMode = PHP_ROUND_HALF_UP)
{
$new = new Money($money->getAmount(), $to);
Expand Down
34 changes: 33 additions & 1 deletion src/ECBSource.php
Expand Up @@ -15,9 +15,20 @@
*/
class ECBSource implements SourceInterface
{
private $rates = array();
/**
* @var array
*/
private $rates;

/**
* @var CachedRemoteData
*/
private $cachedRemoteData;

/**
* @param CacheItemPoolInterface $cachePool
* @param string $key
*/
public function __construct(CacheItemPoolInterface $cachePool, $key = 'ECBSource')
{
$this->cachedRemoteData = new CachedRemoteData(
Expand All @@ -27,16 +38,27 @@ public function __construct(CacheItemPoolInterface $cachePool, $key = 'ECBSource
);
}

/**
* @return CachedRemoteData
*/
public function getCachedRemoteData()
{
return $this->cachedRemoteData;
}

/**
* @return string
* @throws Exception If error retrieving remote data
*/
public function getData()
{
return $this->cachedRemoteData->get();
}

/**
* @return array
* @throws Exception If error retrieving remote data
*/
public function getRates()
{
if (! $this->rates) {
Expand All @@ -58,6 +80,11 @@ public function getRates()
return $this->rates;
}

/**
* @param Currency $currency
* @return float
* @throws Exception If error retrieving remote data
*/
public function getRate(Currency $currency)
{
$rates = $this->getRates();
Expand All @@ -72,6 +99,11 @@ public function getRate(Currency $currency)
return (float) $rates[$code];
}

/**
* @param Currency $from
* @param Currency $to
* @return float
*/
public function getRateBetween(Currency $from, Currency $to)
{
$from = $this->getRate($from);
Expand Down
7 changes: 6 additions & 1 deletion src/NullSource.php
Expand Up @@ -11,8 +11,13 @@
*/
class NullSource implements SourceInterface
{
/**
* @param Currency $from
* @param Currency $to
* @return float
*/
public function getRateBetween(Currency $from, Currency $to)
{
return 1;
return 1.0;
}
}
5 changes: 5 additions & 0 deletions src/SourceInterface.php
Expand Up @@ -11,5 +11,10 @@
*/
interface SourceInterface
{
/**
* @param Currency $from
* @param Currency $to
* @return float
*/
public function getRateBetween(Currency $from, Currency $to);
}

0 comments on commit 2c00591

Please sign in to comment.