Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion app/Address/AddressServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,28 @@ public function register(): void
)
);

$container->addShared(
'Dutch_' . StreetSuggester::class,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Service registration not added to getProvidedServiceNames()

The new 'Dutch_' . StreetSuggester::class service is registered but not declared in the getProvidedServiceNames() method (lines 17-23). This could cause issues with service discovery or dependency management depending on how the container is configured.

fn () => new CachedStreetSuggester(
new BPostStreetSuggester(
new Client(),
$container->get('config')['bpost']['doman'],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: "doman" should be "domain"

This typo will cause a configuration lookup failure. Line 34 correctly uses 'domain', but this line has 'doman'.

$container->get('config')['bpost']['stage'],
$container->get('config')['bpost']['token'],
),
CacheFactory::create(
$container->get('app_cache'),
'dutch_streets',
86400
)
)
);

$container->addShared(
GetStreetRequestHandler::class,
fn () => new GetStreetRequestHandler(
$container->get(StreetSuggester::class)
$container->get(StreetSuggester::class),
$container->get('Dutch_' . StreetSuggester::class)
)
);
}
Expand Down
17 changes: 15 additions & 2 deletions src/Http/Address/GetStreetRequestHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@ final class GetStreetRequestHandler implements RequestHandlerInterface
{
private StreetSuggester $belgiumStreetSuggester;

public function __construct(StreetSuggester $belgiumStreetSuggester)
private StreetSuggester $dutchStreetSuggester;

public function __construct(StreetSuggester $belgiumStreetSuggester, StreetSuggester $duchtStreetSuggester)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: "duchtStreetSuggester" should be "dutchStreetSuggester"

Parameter name has a typo ("ducht" instead of "dutch"). While this technically works, it's inconsistent with the property name on line 19 and reduces code readability.

{
$this->belgiumStreetSuggester = $belgiumStreetSuggester;
$this->dutchStreetSuggester = $duchtStreetSuggester;
}

public function handle(ServerRequestInterface $request): ResponseInterface
Expand Down Expand Up @@ -46,10 +49,20 @@ public function handle(ServerRequestInterface $request): ResponseInterface
return new JsonResponse($content);
}

if ($countryCode === 'NL') {
$content = $this->dutchStreetSuggester->suggest(
$postalCode,
$locality,
$query,
$limit
);
return new JsonResponse($content);
}

throw ApiProblem::queryParameterInvalidValue(
'country',
$countryCode,
['BE']
['BE', 'NLD']
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistency: Error message uses 'NLD' but code checks for 'NL'

Line 52 checks if ($countryCode === 'NL'), but the error message on line 65 lists ['BE', 'NLD'] as valid values. This creates confusion - should the Netherlands country code be 'NL' or 'NLD'?

The check should match the error message. Since ISO 3166-1 alpha-2 country code for Netherlands is 'NL', the error message should be ['BE', 'NL'] instead of ['BE', 'NLD'].

);
}
}
9 changes: 6 additions & 3 deletions tests/Http/Address/GetStreetRequestHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,15 @@ final class GetStreetRequestHandlerTest extends TestCase

private StreetSuggester&MockObject $streetSuggester;

private StreetSuggester&MockObject $steetSuggester2;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: "steetSuggester2" should be "streetSuggester2"

Property name has a typo ("steet" instead of "street"). Consider using a more descriptive name like $dutchStreetSuggester to match the actual purpose and the naming in the handler.


private GetStreetRequestHandler $getStreetRequestHandler;

protected function setUp(): void
{
$this->streetSuggester = $this->createMock(StreetSuggester::class);
$this->getStreetRequestHandler = new GetStreetRequestHandler($this->streetSuggester);
$this->steetSuggester2 = $this->createMock(StreetSuggester::class);
$this->getStreetRequestHandler = new GetStreetRequestHandler($this->streetSuggester, $this->steetSuggester2);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing test coverage for NL country code

The PR adds support for Dutch street suggestions (country code 'NL'), but there's no test case verifying this new functionality works correctly. You should add a test similar to it_can_handle_a_get_street_request() but for NL addresses to ensure the Dutch suggester is called properly.

}

/**
Expand Down Expand Up @@ -98,14 +101,14 @@ public function it_supports_limits(): void
public function it_will_throw_on_unsupported_countries(): void
{
$request = (new Psr7RequestBuilder())
->withUriFromString('streets?country=NL&postalCode=1012AB&locality=Amsterdam&query=Maria')
->withUriFromString('streets?country=DK&postalCode=1012AB&locality=Amsterdam&query=Maria')
->build('GET');

$this->streetSuggester->expects($this->never())
->method('suggest');

$this->assertCallableThrowsApiProblem(
ApiProblem::queryParameterInvalidValue('country', 'NL', ['BE']),
ApiProblem::queryParameterInvalidValue('country', 'DK', ['BE', 'NLD']),
fn () => $this->getStreetRequestHandler->handle($request)
);
}
Expand Down