Skip to content
This repository has been archived by the owner on Aug 13, 2019. It is now read-only.

Commit

Permalink
III-2043: Replace magic string(s) with constants
Browse files Browse the repository at this point in the history
  • Loading branch information
bertramakers committed Apr 26, 2017
1 parent 35416e5 commit dd145bd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
12 changes: 9 additions & 3 deletions src/OfferSearchController.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@

class OfferSearchController
{
/**
* Used to reset filters with default values.
* Eg., countryCode is default BE but can be reset by specifying
* ?countryCode=*
*/
const QUERY_PARAMETER_RESET_VALUE = '*';

/**
* @var OfferSearchServiceInterface
*/
Expand Down Expand Up @@ -333,9 +340,8 @@ private function getAvailabilityFromQuery(Request $request, $queryParameter)
return \DateTimeImmutable::createFromFormat('U', $request->server->get('REQUEST_TIME'));
}

if ($availability === '*') {
// A wildcard means the consumer wants to disable the filter
// completely instead of changing the default value.
if ($availability === self::QUERY_PARAMETER_RESET_VALUE) {
// Disable the filter instead of using a default or specific value.
return null;
}

Expand Down
20 changes: 10 additions & 10 deletions tests/OfferSearchControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,8 @@ public function it_uses_the_default_limit_of_30_if_a_limit_of_0_is_given()
[
'start' => 0,
'limit' => 0,
'availableFrom' => '*',
'availableTo' => '*',
'availableFrom' => OfferSearchController::QUERY_PARAMETER_RESET_VALUE,
'availableTo' => OfferSearchController::QUERY_PARAMETER_RESET_VALUE,
]
);

Expand Down Expand Up @@ -393,8 +393,8 @@ public function it_works_with_a_min_age_of_zero_and_or_a_max_age_of_zero()
[
'start' => 0,
'limit' => 0,
'availableFrom' => '*',
'availableTo' => '*',
'availableFrom' => OfferSearchController::QUERY_PARAMETER_RESET_VALUE,
'availableTo' => OfferSearchController::QUERY_PARAMETER_RESET_VALUE,
'minAge' => 0,
'maxAge' => 0,
]
Expand Down Expand Up @@ -445,8 +445,8 @@ public function it_converts_the_embed_parameter_to_a_correct_boolean_and_passes_
[
'start' => 0,
'limit' => 30,
'availableFrom' => '*',
'availableTo' => '*',
'availableFrom' => OfferSearchController::QUERY_PARAMETER_RESET_VALUE,
'availableTo' => OfferSearchController::QUERY_PARAMETER_RESET_VALUE,
'embed' => $embedParameter,
]
);
Expand Down Expand Up @@ -519,8 +519,8 @@ public function it_can_handle_a_single_string_value_for_parameters_that_are_norm
[
'start' => 30,
'limit' => 10,
'availableFrom' => '*',
'availableTo' => '*',
'availableFrom' => OfferSearchController::QUERY_PARAMETER_RESET_VALUE,
'availableTo' => OfferSearchController::QUERY_PARAMETER_RESET_VALUE,
'labels' => 'foo',
'organizerLabels' => 'bar',
'locationLabels' => 'baz',
Expand Down Expand Up @@ -585,8 +585,8 @@ public function it_transforms_the_request_address_country_to_uppercase()
'http://search.uitdatabank.be/offers/',
'GET',
[
'availableFrom' => '*',
'availableTo' => '*',
'availableFrom' => OfferSearchController::QUERY_PARAMETER_RESET_VALUE,
'availableTo' => OfferSearchController::QUERY_PARAMETER_RESET_VALUE,
'addressCountry' => 'nl'
]
);
Expand Down

0 comments on commit dd145bd

Please sign in to comment.