Skip to content

Commit

Permalink
Folder reorganisation
Browse files Browse the repository at this point in the history
  • Loading branch information
florianv committed Aug 26, 2016
1 parent 4843f64 commit 3db5e80
Show file tree
Hide file tree
Showing 48 changed files with 596 additions and 598 deletions.
@@ -1,13 +1,13 @@
<?php

namespace Swap\Model;
namespace Swap\Contract;

/**
* Represents a currency pair.
*
* @author Florian Voutzinos <florian@voutzinos.com>
*/
interface CurrencyPairInterface
interface CurrencyPair
{
/**
* Gets the base currency.
Expand Down
4 changes: 2 additions & 2 deletions src/Model/RateInterface.php → src/Contract/ExchangeRate.php
@@ -1,13 +1,13 @@
<?php

namespace Swap\Model;
namespace Swap\Contract;

/**
* Represents a rate.
*
* @author Florian Voutzinos <florian@voutzinos.com>
*/
interface RateInterface
interface ExchangeRate
{
/**
* Gets the rate value.
Expand Down
14 changes: 6 additions & 8 deletions src/SwapInterface.php → src/Contract/ExchangeRateProvider.php
Expand Up @@ -9,23 +9,21 @@
* file that was distributed with this source code.
*/

namespace Swap;

use Swap\Model\RateInterface;
namespace Swap\Contract;

/**
* Contract for the Swap service.
* Contract for exchange rate providers.
*
* @author Florian Voutzinos <florian@voutzinos.com>
*/
interface SwapInterface
interface ExchangeRateProvider
{
/**
* Gets the exchange rate.
*
* @param ExchangeQueryInterface $exchangeQuery
* @param ExchangeRateQuery $exchangeQuery
*
* @return RateInterface
* @return ExchangeRate
*/
public function getExchangeRate(ExchangeQueryInterface $exchangeQuery);
public function getExchangeRate(ExchangeRateQuery $exchangeQuery);
}
Expand Up @@ -9,16 +9,14 @@
* file that was distributed with this source code.
*/

namespace Swap;

use Swap\Model\CurrencyPair;
namespace Swap\Contract;

/**
* Contract for exchange queries.
* Contract for exchange rate queries.
*
* @author Florian Voutzinos <florian@voutzinos.com>
*/
interface ExchangeQueryInterface
interface ExchangeRateQuery
{
/**
* Gets the currency pair.
Expand Down
38 changes: 38 additions & 0 deletions src/Contract/ExchangeRateService.php
@@ -0,0 +1,38 @@
<?php

/*
* This file is part of Swap.
*
* (c) Florian Voutzinos <florian@voutzinos.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Swap\Contract;

/**
* Contract for exchange rate service providers.
*
* @author Florian Voutzinos <florian@voutzinos.com>
*/
interface ExchangeRateService
{
/**
* Gets the exchange rate for the query.
*
* @param ExchangeRateQuery $exchangeQuery
*
* @return ExchangeRate
*/
public function get(ExchangeRateQuery $exchangeQuery);

/**
* Tells if it supports the exchange query.
*
* @param ExchangeRateQuery $exchangeQuery
*
* @return bool
*/
public function support(ExchangeRateQuery $exchangeQuery);
}
Expand Up @@ -9,14 +9,14 @@
* file that was distributed with this source code.
*/

namespace Swap;
namespace Swap\Contract;

/**
* Contract for historical exchange queries.
* Contract for historical exchange rate queries.
*
* @author Florian Voutzinos <florian@voutzinos.com>
*/
interface HistoricalExchangeQueryInterface extends ExchangeQueryInterface
interface HistoricalExchangeRateQuery extends ExchangeRateQuery
{
/**
* Gets the date.
Expand Down
8 changes: 5 additions & 3 deletions src/Model/CurrencyPair.php → src/CurrencyPair.php
Expand Up @@ -9,14 +9,16 @@
* file that was distributed with this source code.
*/

namespace Swap\Model;
namespace Swap;

use Swap\Contract\CurrencyPair as CurrencyPairContract;

/**
* Represents a currency pair.
*
* @author Florian Voutzinos <florian@voutzinos.com>
*/
final class CurrencyPair implements CurrencyPairInterface
final class CurrencyPair implements CurrencyPairContract
{
private $baseCurrency;
private $quoteCurrency;
Expand All @@ -40,7 +42,7 @@ public function __construct($baseCurrency, $quoteCurrency)
*
* @throws \InvalidArgumentException
*
* @return CurrencyPairInterface
* @return CurrencyPairContract
*/
public static function createFromString($string)
{
Expand Down
Expand Up @@ -16,7 +16,7 @@
*
* @author Florian Voutzinos <florian@voutzinos.com>
*/
class ChainProviderException extends Exception
class ChainException extends Exception
{
private $exceptions;

Expand Down
6 changes: 3 additions & 3 deletions src/Exception/UnsupportedCurrencyPairException.php
Expand Up @@ -11,7 +11,7 @@

namespace Swap\Exception;

use Swap\Model\CurrencyPairInterface;
use Swap\Contract\CurrencyPair;

/**
* Exception thrown when a currency pair is not supported by a provider.
Expand All @@ -22,7 +22,7 @@ class UnsupportedCurrencyPairException extends Exception
{
private $currencyPair;

public function __construct(CurrencyPairInterface $currencyPair)
public function __construct(CurrencyPair $currencyPair)
{
parent::__construct(sprintf('The currency pair "%s" is not supported by the provider.', $currencyPair->__toString()));
$this->currencyPair = $currencyPair;
Expand All @@ -31,7 +31,7 @@ public function __construct(CurrencyPairInterface $currencyPair)
/**
* Gets the unsupported currency pair.
*
* @return CurrencyPairInterface
* @return CurrencyPair
*/
public function getCurrencyPair()
{
Expand Down
20 changes: 12 additions & 8 deletions src/Exception/UnsupportedExchangeQueryException.php
Expand Up @@ -11,7 +11,7 @@

namespace Swap\Exception;

use Swap\ExchangeQueryInterface;
use Swap\Contract\ExchangeRateQuery;

/**
* Exception thrown when an exchange query is not supported by a provider.
Expand All @@ -20,21 +20,25 @@
*/
class UnsupportedExchangeQueryException extends Exception
{
private $exchangeQuery;
private $exchangeRateQuery;

public function __construct(ExchangeQueryInterface $exchangeQuery)
public function __construct(ExchangeRateQuery $exchangeRateQuery)
{
parent::__construct(sprintf('The exchange query "%s" is not supported by the provider.', $exchangeQuery->getCurrencyPair()->__toString()));
$this->exchangeQuery = $exchangeQuery;
parent::__construct(sprintf(
'The exchange query "%s" is not supported by the provider.',
$exchangeRateQuery->getCurrencyPair()->__toString()
));

$this->exchangeRateQuery = $exchangeRateQuery;
}

/**
* Gets the unsupported exchange query.
*
* @return ExchangeQueryInterface
* @return ExchangeRateQuery
*/
public function getExchangeQuery()
public function getExchangeRateQuery()
{
return $this->exchangeQuery;
return $this->exchangeRateQuery;
}
}
6 changes: 4 additions & 2 deletions src/Model/Rate.php → src/ExchangeRate.php
Expand Up @@ -9,14 +9,16 @@
* file that was distributed with this source code.
*/

namespace Swap\Model;
namespace Swap;

use Swap\Contract\ExchangeRate as ExchangeRateContract;

/**
* Represents a rate.
*
* @author Florian Voutzinos <florian@voutzinos.com>
*/
final class Rate implements RateInterface
final class ExchangeRate implements ExchangeRateContract
{
private $value;
private $date;
Expand Down
14 changes: 7 additions & 7 deletions src/ExchangeQuery.php → src/ExchangeRateQuery.php
Expand Up @@ -11,20 +11,20 @@

namespace Swap;

use Swap\Model\CurrencyPair;
use Swap\Model\CurrencyPairInterface;
use Swap\Contract\CurrencyPair as CurrencyPairContract;
use Swap\Contract\ExchangeRateQuery as ExchangeRateQueryContract;

/**
* Default exchange query implementation.
*
* @author Florian Voutzinos <florian@voutzinos.com>
*/
class ExchangeQuery implements ExchangeQueryInterface
class ExchangeRateQuery implements ExchangeRateQueryContract
{
/**
* The currency pair.
*
* @var CurrencyPairInterface
* @var CurrencyPairContract
*/
private $currencyPair;

Expand All @@ -43,10 +43,10 @@ class ExchangeQuery implements ExchangeQueryInterface
/**
* Creates a new query.
*
* @param CurrencyPairInterface $currencyPair
* @param array $options
* @param CurrencyPairContract $currencyPair
* @param array $options
*/
public function __construct(CurrencyPairInterface $currencyPair, array $options = [])
public function __construct(CurrencyPairContract $currencyPair, array $options = [])
{
$this->currencyPair = $currencyPair;
$this->options = $options;
Expand Down
Expand Up @@ -11,14 +11,12 @@

namespace Swap;

use Swap\Model\CurrencyPair;

/**
* Helps building exchange queries.
*
* @author Florian Voutzinos <florian@voutzinos.com>
*/
final class ExchangeQueryBuilder
final class ExchangeRateQueryBuilder
{
/**
* The currency pair.
Expand Down Expand Up @@ -121,7 +119,7 @@ public function addOption($name, $default = null)
/**
* Builds the query.
*
* @return ExchangeQueryInterface
* @return \Swap\Contract\ExchangeRateQuery
*/
public function build()
{
Expand All @@ -130,9 +128,9 @@ public function build()
}

if ($this->date) {
return new HistoricalExchangeQuery($this->currencyPair, $this->date, $this->options);
return new HistoricalExchangeRateQuery($this->currencyPair, $this->date, $this->options);
}

return new ExchangeQuery($this->currencyPair, $this->options);
return new ExchangeRateQuery($this->currencyPair, $this->options);
}
}
Expand Up @@ -11,14 +11,15 @@

namespace Swap;

use Swap\Model\CurrencyPairInterface;
use Swap\Contract\CurrencyPair as CurrencyPairContract;
use Swap\Contract\HistoricalExchangeRateQuery as HistoricalExchangeQueryContract;

/**
* Default historical exchange query implementation.
*
* @author Florian Voutzinos <florian@voutzinos.com>
*/
class HistoricalExchangeQuery extends ExchangeQuery implements HistoricalExchangeQueryInterface
class HistoricalExchangeRateQuery extends ExchangeRateQuery implements HistoricalExchangeQueryContract
{
/**
* Gets the date.
Expand All @@ -30,11 +31,11 @@ class HistoricalExchangeQuery extends ExchangeQuery implements HistoricalExchang
/**
* Creates a new query.
*
* @param CurrencyPairInterface $currencyPair
* @param \DateTimeInterface $date
* @param array $options
* @param CurrencyPairContract $currencyPair
* @param \DateTimeInterface $date
* @param array $options
*/
public function __construct(CurrencyPairInterface $currencyPair, \DateTimeInterface $date, array $options = [])
public function __construct(CurrencyPairContract $currencyPair, \DateTimeInterface $date, array $options = [])
{
parent::__construct($currencyPair, $options);

Expand Down

0 comments on commit 3db5e80

Please sign in to comment.