Skip to content

Commit

Permalink
Merge pull request #158 from deanblackborough/v2.04.1
Browse files Browse the repository at this point in the history
v2.04.1
  • Loading branch information
deanblackborough authored Dec 12, 2019
2 parents cbd6ed0 + d9dd759 commit 5e4a4ed
Show file tree
Hide file tree
Showing 8 changed files with 613 additions and 454 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ DB_PASSWORD=
DB_ROOT_PASSWORD=

BROADCAST_DRIVER=log
CACHE_DRIVER=file
CACHE_DRIVER=database
SESSION_DRIVER=file
SESSION_LIFETIME=120
QUEUE_DRIVER=sync
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

The complete changelog for the Costs to Expect REST API, follows the format defined at https://keepachangelog.com/en/1.0.0/

## [v2.04.1] - 2019-12-12
### Changed
- We have switched to database caching.
- We have updated the parameters helper, it now throws away more invalid requests.
- Dependencies updated.
- We have updated the landing page content.

## [v2.04.0] - 2019-11-11
### Added
- We have added a GitHub callout to the top right corner of the API landing page, courtesy of https://github.com/tholman/github-corners.
Expand Down
42 changes: 26 additions & 16 deletions app/Validators/Request/Parameters.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,12 @@ private static function validate(?int $resource_type_id, ?int $resource_id)
break;

case 'month':
if (array_key_exists($key, self::$parameters) === true) {
if (intval(self::$parameters[$key]) < 1 ||
if (array_key_exists($key, self::$parameters) === true &&
intval(self::$parameters[$key] > 0)) {

self::$parameters[$key] = intval(self::$parameters[$key]);

if (self::$parameters[$key] < 1 ||
self::$parameters[$key] > 12) {
unset(self::$parameters[$key]);
}
Expand Down Expand Up @@ -126,26 +130,32 @@ private static function validate(?int $resource_type_id, ?int $resource_id)
break;

case 'year':
$min_year_limit = intval(Date('Y'));
$max_year_limit = intval(Date('Y'));
if (array_key_exists($key, self::$parameters) === true &&
intval(self::$parameters[$key] > 0)) {

if ($resource_type_id !== null && $resource_id === null) {
$item_interface = ItemInterfaceFactory::resourceTypeItem($resource_type_id);
$min_year_limit = $item_interface->conditionalParameterMinYear($resource_type_id);
$max_year_limit = $item_interface->conditionalParameterMaxYear($resource_type_id);
}
self::$parameters[$key] = intval(self::$parameters[$key]);

if ($resource_type_id !== null && $resource_id !== null) {
$item_interface = ItemInterfaceFactory::item($resource_type_id);
$min_year_limit = $item_interface->conditionalParameterMinYear($resource_id);
$max_year_limit = $item_interface->conditionalParameterMaxYear($resource_id);
}
$min_year_limit = intval(Date('Y'));
$max_year_limit = intval(Date('Y'));

if (array_key_exists($key, self::$parameters) === true) {
if (intval(self::$parameters[$key]) < $min_year_limit ||
if ($resource_type_id !== null && $resource_id === null) {
$item_interface = ItemInterfaceFactory::resourceTypeItem($resource_type_id);
$min_year_limit = $item_interface->conditionalParameterMinYear($resource_type_id);
$max_year_limit = $item_interface->conditionalParameterMaxYear($resource_type_id);
}

if ($resource_type_id !== null && $resource_id !== null) {
$item_interface = ItemInterfaceFactory::item($resource_type_id);
$min_year_limit = $item_interface->conditionalParameterMinYear($resource_id);
$max_year_limit = $item_interface->conditionalParameterMaxYear($resource_id);
}

if (self::$parameters[$key] < $min_year_limit ||
self::$parameters[$key] > $max_year_limit + 1) {
unset(self::$parameters[$key]);
}
} else {
unset(self::$parameters[$key]);
}
break;

Expand Down
Loading

0 comments on commit 5e4a4ed

Please sign in to comment.