File tree Expand file tree Collapse file tree 4 files changed +56
-0
lines changed Expand file tree Collapse file tree 4 files changed +56
-0
lines changed Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments