Skip to content

Commit 94e7bf5

Browse files
committed
add currency converter classes
1 parent 54e17ac commit 94e7bf5

File tree

4 files changed

+56
-0
lines changed

4 files changed

+56
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Growthdev\DesignPatterns\Structural\Adapter;
6+
7+
interface CurrencyConverter
8+
{
9+
public function convert(float $amount): float;
10+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Growthdev\DesignPatterns\Structural\Adapter;
6+
7+
final class CurrencyConverterAdapter
8+
{
9+
private CurrencyConverter $currencyConverter;
10+
11+
public function __construct(CurrencyConverter $currencyConverter)
12+
{
13+
$this->currencyConverter = $currencyConverter;
14+
}
15+
16+
public function convert(float $amount): float
17+
{
18+
return $this->currencyConverter->convert($amount);
19+
}
20+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Growthdev\DesignPatterns\Structural\Adapter;
6+
7+
final class CurrencyToDollarConverter implements CurrencyConverter
8+
{
9+
public function convert(float $amount): float
10+
{
11+
return $amount * 5.61; // 1$ = R$ 5.61
12+
}
13+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Growthdev\DesignPatterns\Structural\Adapter;
6+
7+
final class CurrencyToEuroConverter implements CurrencyConverter
8+
{
9+
public function convert(float $amount): float
10+
{
11+
return $amount * 6.35; // 1 EUR = R$ 6.35
12+
}
13+
}

0 commit comments

Comments
 (0)