Skip to content

Commit 4065cab

Browse files
committed
Move to namespace
1 parent 5f96805 commit 4065cab

10 files changed

Lines changed: 48 additions & 44 deletions

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@ composer install peso/cnb-service php-http/discovery guzzlehttp/guzzle symfony/c
3838
<?php
3939

4040
use Peso\Peso\CurrencyConverter;
41-
use Peso\Services\CzechNationalBankService;
41+
use Peso\Services\CzechNationalBank\CentralBankFixingService;
4242
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
4343
use Symfony\Component\Cache\Psr16Cache;
4444

4545
require __DIR__ . '/vendor/autoload.php';
4646

4747
$cache = new Psr16Cache(new FilesystemAdapter(directory: __DIR__ . '/cache'));
48-
$service = new CzechNationalBankService($cache);
48+
$service = new CentralBankFixingService($cache);
4949
$converter = new CurrencyConverter($service);
5050
```
5151

src/CzechNationalBankService.php renamed to src/CzechNationalBank/CentralBankFixingService.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace Peso\Services;
5+
namespace Peso\Services\CzechNationalBank;
66

77
use Arokettu\Date\Calendar;
88
use Arokettu\Date\Date;
@@ -14,11 +14,13 @@
1414
use Peso\Core\Responses\ExchangeRateResponse;
1515
use Peso\Core\Services\PesoServiceInterface;
1616
use Peso\Core\Types\Decimal;
17-
use Peso\Services\CzechNationalBankService\CNBCommon;
1817

19-
final readonly class CzechNationalBankService implements PesoServiceInterface
18+
/**
19+
* Official CNB daily rates
20+
*/
21+
final readonly class CentralBankFixingService implements PesoServiceInterface
2022
{
21-
use CNBCommon;
23+
use Common;
2224

2325
// phpcs:disable Generic.Files.LineLength.TooLong
2426
private const ENDPOINT = 'https://www.cnb.cz/en/financial-markets/foreign-exchange-market/central-bank-exchange-rate-fixing/central-bank-exchange-rate-fixing/daily.txt';

src/CzechNationalBankService/CNBCommon.php renamed to src/CzechNationalBank/Common.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace Peso\Services\CzechNationalBankService;
5+
namespace Peso\Services\CzechNationalBank;
66

77
use Arokettu\Clock\SystemClock;
88
use Arokettu\Date\Calendar;
@@ -22,7 +22,7 @@
2222
use Psr\Http\Message\RequestFactoryInterface;
2323
use Psr\SimpleCache\CacheInterface;
2424

25-
trait CNBCommon
25+
trait Common
2626
{
2727
public function __construct(
2828
private readonly CacheInterface $cache = new NullCache(),

src/CzechNationalBankOtherCurrenciesService.php renamed to src/CzechNationalBank/OtherCurrenciesService.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace Peso\Services;
5+
namespace Peso\Services\CzechNationalBank;
66

77
use Arokettu\Date\Calendar;
88
use Arokettu\Date\Date;
@@ -14,11 +14,13 @@
1414
use Peso\Core\Responses\ExchangeRateResponse;
1515
use Peso\Core\Services\PesoServiceInterface;
1616
use Peso\Core\Types\Decimal;
17-
use Peso\Services\CzechNationalBankService\CNBCommon;
1817

19-
final readonly class CzechNationalBankOtherCurrenciesService implements PesoServiceInterface
18+
/**
19+
* Misc currencies monthly rates
20+
*/
21+
final readonly class OtherCurrenciesService implements PesoServiceInterface
2022
{
21-
use CNBCommon;
23+
use Common;
2224

2325
// phpcs:disable Generic.Files.LineLength.TooLong
2426
private const ENDPOINT = 'https://www.cnb.cz/en/financial-markets/foreign-exchange-market/fx-rates-of-other-currencies/fx-rates-of-other-currencies/fx_rates.txt';

tests/CentralBankFixingRequestTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use Peso\Core\Requests\HistoricalExchangeRateRequest;
1212
use Peso\Core\Responses\ErrorResponse;
1313
use Peso\Core\Responses\ExchangeRateResponse;
14-
use Peso\Services\CzechNationalBankService;
14+
use Peso\Services\CzechNationalBank\CentralBankFixingService;
1515
use Peso\Services\Tests\Helpers\MockClient;
1616
use PHPUnit\Framework\TestCase;
1717
use Symfony\Component\Cache\Adapter\ArrayAdapter;
@@ -24,7 +24,7 @@ public function testCurrentRate(): void
2424
$cache = new Psr16Cache(new ArrayAdapter());
2525
$http = MockClient::get();
2626

27-
$service = new CzechNationalBankService(cache: $cache, httpClient: $http);
27+
$service = new CentralBankFixingService(cache: $cache, httpClient: $http);
2828

2929
$response = $service->send(new CurrentExchangeRateRequest('EUR', 'CZK'));
3030
self::assertInstanceOf(ExchangeRateResponse::class, $response);
@@ -53,7 +53,7 @@ public function testHistoricalRate(): void
5353
$http = MockClient::get();
5454
$clock = StaticClock::fromDateString('2025-06-20');
5555

56-
$service = new CzechNationalBankService(cache: $cache, httpClient: $http, clock: $clock);
56+
$service = new CentralBankFixingService(cache: $cache, httpClient: $http, clock: $clock);
5757

5858
$date = Calendar::parse('2025-06-13');
5959

@@ -80,7 +80,7 @@ public function testHistoricalRate(): void
8080

8181
public function testCzkOnly(): void
8282
{
83-
$service = new CzechNationalBankService();
83+
$service = new CentralBankFixingService();
8484

8585
$response = $service->send(new CurrentExchangeRateRequest('PHP', 'USD'));
8686
self::assertInstanceOf(ErrorResponse::class, $response);
@@ -98,7 +98,7 @@ public function testCzkOnly(): void
9898

9999
public function testAfter1991Only(): void
100100
{
101-
$service = new CzechNationalBankService();
101+
$service = new CentralBankFixingService();
102102

103103
$response = $service->send(new HistoricalExchangeRateRequest('PHP', 'CZK', Calendar::parse('1990-12-31')));
104104
self::assertInstanceOf(ErrorResponse::class, $response);

tests/EdgeCasesTest.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@
1515
use Peso\Core\Requests\HistoricalExchangeRateRequest;
1616
use Peso\Core\Responses\ErrorResponse;
1717
use Peso\Core\Services\SDK\Exceptions\HttpFailureException;
18-
use Peso\Services\CzechNationalBankOtherCurrenciesService;
19-
use Peso\Services\CzechNationalBankService;
18+
use Peso\Services\CzechNationalBank\OtherCurrenciesService;
19+
use Peso\Services\CzechNationalBank\CentralBankFixingService;
2020
use PHPUnit\Framework\TestCase;
2121
use stdClass;
2222

2323
final class EdgeCasesTest extends TestCase
2424
{
2525
public function testInvalidRequest(): void
2626
{
27-
$service = new CzechNationalBankService();
27+
$service = new CentralBankFixingService();
2828

2929
$response = $service->send(new stdClass());
3030
self::assertInstanceOf(ErrorResponse::class, $response);
@@ -34,7 +34,7 @@ public function testInvalidRequest(): void
3434

3535
public function testInvalidRequestOther(): void
3636
{
37-
$service = new CzechNationalBankOtherCurrenciesService();
37+
$service = new OtherCurrenciesService();
3838

3939
$response = $service->send(new stdClass());
4040
self::assertInstanceOf(ErrorResponse::class, $response);
@@ -47,7 +47,7 @@ public function testFutureDate(): void
4747
$clock = StaticClock::fromDateString('2025-06-18'); // 'now'
4848
$future = Calendar::parse('2025-06-19');
4949

50-
$service = new CzechNationalBankService(clock: $clock);
50+
$service = new CentralBankFixingService(clock: $clock);
5151

5252
$response = $service->send(new HistoricalExchangeRateRequest('EUR', 'CZK', $future));
5353
self::assertInstanceOf(ErrorResponse::class, $response);
@@ -60,7 +60,7 @@ public function testFutureDateOther(): void
6060
$clock = StaticClock::fromDateString('2025-06-18'); // 'now'
6161
$future = Calendar::parse('2025-06-19');
6262

63-
$service = new CzechNationalBankOtherCurrenciesService(clock: $clock);
63+
$service = new OtherCurrenciesService(clock: $clock);
6464

6565
$response = $service->send(new HistoricalExchangeRateRequest('EUR', 'CZK', $future));
6666
self::assertInstanceOf(ErrorResponse::class, $response);
@@ -73,7 +73,7 @@ public function testHttpFailure(): void
7373
$http = new Client();
7474
$http->setDefaultResponse(new Response(500, body: 'Server error or something'));
7575

76-
$service = new CzechNationalBankService(httpClient: $http);
76+
$service = new CentralBankFixingService(httpClient: $http);
7777

7878
self::expectException(HttpFailureException::class);
7979
self::expectExceptionMessage('HTTP error 500. Response is "Server error or something"');
@@ -85,7 +85,7 @@ public function testHttpFailureOther(): void
8585
$http = new Client();
8686
$http->setDefaultResponse(new Response(500, body: 'Server error or something'));
8787

88-
$service = new CzechNationalBankOtherCurrenciesService(httpClient: $http);
88+
$service = new OtherCurrenciesService(httpClient: $http);
8989

9090
self::expectException(HttpFailureException::class);
9191
self::expectExceptionMessage('HTTP error 500. Response is "Server error or something"');
@@ -97,7 +97,7 @@ public function testInvalidDateInResponse(): void
9797
$http = new Client();
9898
$http->setDefaultResponse(new Response(body: 'Not a date'));
9999

100-
$service = new CzechNationalBankService(httpClient: $http);
100+
$service = new CentralBankFixingService(httpClient: $http);
101101

102102
self::expectException(Error::class);
103103
self::expectExceptionMessage('Invalid date. Format change?');
@@ -113,7 +113,7 @@ public function testInvalidHeaderInResponse(): void
113113
Val1|1|1000
114114
BODY));
115115

116-
$service = new CzechNationalBankService(httpClient: $http);
116+
$service = new CentralBankFixingService(httpClient: $http);
117117

118118
self::expectException(Error::class);
119119
self::expectExceptionMessage('Invalid header. Format change?');

tests/OtherCurrenciesRequestTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use Peso\Core\Requests\HistoricalExchangeRateRequest;
1212
use Peso\Core\Responses\ErrorResponse;
1313
use Peso\Core\Responses\ExchangeRateResponse;
14-
use Peso\Services\CzechNationalBankOtherCurrenciesService;
14+
use Peso\Services\CzechNationalBank\OtherCurrenciesService;
1515
use Peso\Services\Tests\Helpers\MockClient;
1616
use PHPUnit\Framework\TestCase;
1717
use Symfony\Component\Cache\Adapter\ArrayAdapter;
@@ -24,7 +24,7 @@ public function testCurrentRate(): void
2424
$cache = new Psr16Cache(new ArrayAdapter());
2525
$http = MockClient::get();
2626

27-
$service = new CzechNationalBankOtherCurrenciesService(cache: $cache, httpClient: $http);
27+
$service = new OtherCurrenciesService(cache: $cache, httpClient: $http);
2828

2929
$response = $service->send(new CurrentExchangeRateRequest('RSD', 'CZK'));
3030
self::assertInstanceOf(ExchangeRateResponse::class, $response);
@@ -53,7 +53,7 @@ public function testHistoricalRate(): void
5353
$http = MockClient::get();
5454
$clock = StaticClock::fromDateString('2025-06-20');
5555

56-
$service = new CzechNationalBankOtherCurrenciesService(cache: $cache, httpClient: $http, clock: $clock);
56+
$service = new OtherCurrenciesService(cache: $cache, httpClient: $http, clock: $clock);
5757

5858
$date = Calendar::parse('2025-06-13');
5959

@@ -84,7 +84,7 @@ public function testHistoricalRollOverRate(): void
8484
$http = MockClient::get();
8585
$clock = StaticClock::fromDateString('2025-06-20');
8686

87-
$service = new CzechNationalBankOtherCurrenciesService(cache: $cache, httpClient: $http, clock: $clock);
87+
$service = new OtherCurrenciesService(cache: $cache, httpClient: $http, clock: $clock);
8888

8989
$date = Calendar::parse('2015-01-12'); // this should request data for Dec 2014
9090

@@ -111,7 +111,7 @@ public function testHistoricalRollOverRate(): void
111111

112112
public function testCzkOnly(): void
113113
{
114-
$service = new CzechNationalBankOtherCurrenciesService();
114+
$service = new OtherCurrenciesService();
115115

116116
$response = $service->send(new CurrentExchangeRateRequest('PHP', 'USD'));
117117
self::assertInstanceOf(ErrorResponse::class, $response);
@@ -129,7 +129,7 @@ public function testCzkOnly(): void
129129

130130
public function testAfter2004Only(): void
131131
{
132-
$service = new CzechNationalBankOtherCurrenciesService();
132+
$service = new OtherCurrenciesService();
133133

134134
$response = $service->send(new HistoricalExchangeRateRequest('PHP', 'CZK', Calendar::parse('1990-12-31')));
135135
self::assertInstanceOf(ErrorResponse::class, $response);
@@ -142,7 +142,7 @@ public function testAfter2004Only(): void
142142

143143
public function testAfterJuneOnly(): void
144144
{
145-
$service = new CzechNationalBankOtherCurrenciesService();
145+
$service = new OtherCurrenciesService();
146146

147147
$response = $service->send(new HistoricalExchangeRateRequest('PHP', 'CZK', Calendar::parse('2004-05-31')));
148148
self::assertInstanceOf(ErrorResponse::class, $response);

tests/SupportTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@
88
use Arokettu\Date\Date;
99
use Peso\Core\Requests\CurrentExchangeRateRequest;
1010
use Peso\Core\Requests\HistoricalExchangeRateRequest;
11-
use Peso\Services\CzechNationalBankOtherCurrenciesService;
12-
use Peso\Services\CzechNationalBankService;
11+
use Peso\Services\CzechNationalBank\OtherCurrenciesService;
12+
use Peso\Services\CzechNationalBank\CentralBankFixingService;
1313
use PHPUnit\Framework\TestCase;
1414
use stdClass;
1515

1616
final class SupportTest extends TestCase
1717
{
1818
public function testRequests(): void
1919
{
20-
$service = new CzechNationalBankService();
20+
$service = new CentralBankFixingService();
2121

2222
self::assertTrue($service->supports(new CurrentExchangeRateRequest('EUR', 'CZK')));
2323
self::assertTrue($service->supports(new HistoricalExchangeRateRequest('EUR', 'CZK', Date::today())));
@@ -31,7 +31,7 @@ public function testRequests(): void
3131

3232
public function testRequestsOther(): void
3333
{
34-
$service = new CzechNationalBankOtherCurrenciesService();
34+
$service = new OtherCurrenciesService();
3535

3636
self::assertTrue($service->supports(new CurrentExchangeRateRequest('EUR', 'CZK')));
3737
self::assertTrue($service->supports(new HistoricalExchangeRateRequest('EUR', 'CZK', Date::today())));

tests/UserAgentTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use Composer\InstalledVersions;
88
use Http\Discovery\Psr17Factory;
99
use Peso\Core\Requests\CurrentExchangeRateRequest;
10-
use Peso\Services\CzechNationalBankService;
10+
use Peso\Services\CzechNationalBank\CentralBankFixingService;
1111
use Peso\Services\Tests\Helpers\MockClient;
1212
use PHPUnit\Framework\TestCase;
1313
use Psr\Http\Message\RequestFactoryInterface;
@@ -22,7 +22,7 @@ public function testUserAgent(): void
2222
$cache = new Psr16Cache(new ArrayAdapter());
2323
$http = MockClient::get();
2424

25-
$service = new CzechNationalBankService(cache: $cache, httpClient: $http);
25+
$service = new CentralBankFixingService(cache: $cache, httpClient: $http);
2626

2727
$pesoVersion = InstalledVersions::getPrettyVersion('peso/core');
2828
$clientVersion = InstalledVersions::getPrettyVersion('peso/cnb-service');
@@ -56,7 +56,7 @@ public function createRequest(string $method, mixed $uri): RequestInterface
5656
}
5757
};
5858

59-
$service = new CzechNationalBankService(cache: $cache, httpClient: $http, requestFactory: $requestFactory);
59+
$service = new CentralBankFixingService(cache: $cache, httpClient: $http, requestFactory: $requestFactory);
6060

6161
$pesoVersion = InstalledVersions::getPrettyVersion('peso/core');
6262
$clientVersion = InstalledVersions::getPrettyVersion('peso/cnb-service');

tests/WrappedServicesTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
use Peso\Core\Requests\CurrentExchangeRateRequest;
99
use Peso\Core\Responses\ErrorResponse;
1010
use Peso\Core\Responses\ExchangeRateResponse;
11-
use Peso\Services\CzechNationalBankService;
11+
use Peso\Services\CzechNationalBank\CentralBankFixingService;
1212
use Peso\Services\Tests\Helpers\MockClient;
1313
use PHPUnit\Framework\TestCase;
1414

@@ -18,8 +18,8 @@ public function testReversible(): void
1818
{
1919
$http = MockClient::get();
2020

21-
$baseService = new CzechNationalBankService(httpClient: $http);
22-
$service = CzechNationalBankService::reversible(httpClient: $http);
21+
$baseService = new CentralBankFixingService(httpClient: $http);
22+
$service = CentralBankFixingService::reversible(httpClient: $http);
2323

2424
$request = new CurrentExchangeRateRequest('CZK', 'USD');
2525

0 commit comments

Comments
 (0)