Optimized filter_var checks

This commit is contained in:
Bernd Bestel 2020-12-28 22:14:59 +01:00
parent 6263715c53
commit b6139a6991
No known key found for this signature in database
GPG Key ID: 71BD34C0D4891300
2 changed files with 4 additions and 4 deletions

View File

@ -585,7 +585,7 @@ class StockApiController extends BaseApiController
public function ProductStockEntries(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args) public function ProductStockEntries(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{ {
$allowSubproductSubstitution = false; $allowSubproductSubstitution = false;
if (isset($request->getQueryParams()['include_sub_products']) && filter_var($request->getQueryParams()['include_sub_products'], FILTER_VALIDATE_BOOLEAN)) if (isset($request->getQueryParams()['include_sub_products']) && filter_var($request->getQueryParams()['include_sub_products'], FILTER_VALIDATE_BOOLEAN) !== false)
{ {
$allowSubproductSubstitution = true; $allowSubproductSubstitution = true;
} }
@ -596,7 +596,7 @@ class StockApiController extends BaseApiController
public function ProductStockLocations(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args) public function ProductStockLocations(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{ {
$allowSubproductSubstitution = false; $allowSubproductSubstitution = false;
if (isset($request->getQueryParams()['include_sub_products']) && filter_var($request->getQueryParams()['include_sub_products'], FILTER_VALIDATE_BOOLEAN)) if (isset($request->getQueryParams()['include_sub_products']) && filter_var($request->getQueryParams()['include_sub_products'], FILTER_VALIDATE_BOOLEAN) !== false)
{ {
$allowSubproductSubstitution = true; $allowSubproductSubstitution = true;
} }
@ -781,7 +781,7 @@ class StockApiController extends BaseApiController
try try
{ {
if (!filter_var($args['productIdToKeep'], FILTER_VALIDATE_INT) || !filter_var($args['productIdToRemove'], FILTER_VALIDATE_INT)) if (filter_var($args['productIdToKeep'], FILTER_VALIDATE_INT) === false || filter_var($args['productIdToRemove'], FILTER_VALIDATE_INT) === false)
{ {
throw new \Exception('Provided {productIdToKeep} or {productIdToRemove} is not a valid integer'); throw new \Exception('Provided {productIdToKeep} or {productIdToRemove} is not a valid integer');
} }

View File

@ -51,7 +51,7 @@ class SystemApiController extends BaseApiController
$params = $request->getQueryParams(); $params = $request->getQueryParams();
if (isset($params['offset'])) if (isset($params['offset']))
{ {
if (!filter_var($params['offset'], FILTER_VALIDATE_INT)) if (filter_var($params['offset'], FILTER_VALIDATE_INT) === false)
{ {
throw new \Exception('Query parameter "offset" is not a valid integer'); throw new \Exception('Query parameter "offset" is not a valid integer');
} }