Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IBX-5135: Added LocationDepth and IsMainLocation criterion parsers #50

Open
wants to merge 7 commits into
base: 4.5
Choose a base branch
from
Open
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
80 changes: 0 additions & 80 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -285,11 +285,6 @@ parameters:
count: 1
path: src/contracts/Input/Handler.php

-
message: "#^Method Ibexa\\\\Contracts\\\\Rest\\\\Input\\\\Parser\\:\\:parse\\(\\) has parameter \\$data with no value type specified in iterable type array\\.$#"
count: 1
path: src/contracts/Input/Parser.php

-
message: "#^Cannot access offset mixed on Ibexa\\\\Contracts\\\\Rest\\\\Input\\\\Parser\\.$#"
count: 2
Expand Down Expand Up @@ -2165,31 +2160,16 @@ parameters:
count: 1
path: src/lib/Server/Input/Parser/Aggregation/AbstractRangeAggregationParser.php

-
message: "#^Method Ibexa\\\\Rest\\\\Server\\\\Input\\\\Parser\\\\Aggregation\\\\AbstractRangeAggregationParser\\:\\:parse\\(\\) has parameter \\$data with no value type specified in iterable type array\\.$#"
count: 1
path: src/lib/Server/Input/Parser/Aggregation/AbstractRangeAggregationParser.php

-
message: "#^Method Ibexa\\\\Rest\\\\Server\\\\Input\\\\Parser\\\\Aggregation\\\\AbstractRangeAggregationParser\\:\\:parseAggregation\\(\\) has parameter \\$data with no value type specified in iterable type array\\.$#"
count: 1
path: src/lib/Server/Input/Parser/Aggregation/AbstractRangeAggregationParser.php

-
message: "#^Method Ibexa\\\\Rest\\\\Server\\\\Input\\\\Parser\\\\Aggregation\\\\AbstractStatsAggregationParser\\:\\:parse\\(\\) has parameter \\$data with no value type specified in iterable type array\\.$#"
count: 1
path: src/lib/Server/Input/Parser/Aggregation/AbstractStatsAggregationParser.php

-
message: "#^Method Ibexa\\\\Rest\\\\Server\\\\Input\\\\Parser\\\\Aggregation\\\\AbstractStatsAggregationParser\\:\\:parseAggregation\\(\\) has parameter \\$data with no value type specified in iterable type array\\.$#"
count: 1
path: src/lib/Server/Input/Parser/Aggregation/AbstractStatsAggregationParser.php

-
message: "#^Method Ibexa\\\\Rest\\\\Server\\\\Input\\\\Parser\\\\Aggregation\\\\AbstractTermAggregationParser\\:\\:parse\\(\\) has parameter \\$data with no value type specified in iterable type array\\.$#"
count: 1
path: src/lib/Server/Input/Parser/Aggregation/AbstractTermAggregationParser.php

-
message: "#^Method Ibexa\\\\Rest\\\\Server\\\\Input\\\\Parser\\\\Aggregation\\\\AbstractTermAggregationParser\\:\\:parseAggregation\\(\\) has parameter \\$data with no value type specified in iterable type array\\.$#"
count: 1
Expand Down Expand Up @@ -2290,11 +2270,6 @@ parameters:
count: 1
path: src/lib/Server/Input/Parser/Aggregation/ObjectStateTermAggregationParser.php

-
message: "#^Method Ibexa\\\\Rest\\\\Server\\\\Input\\\\Parser\\\\Aggregation\\\\Range\\\\AbstractRangeParser\\:\\:parse\\(\\) has parameter \\$data with no value type specified in iterable type array\\.$#"
count: 1
path: src/lib/Server/Input/Parser/Aggregation/Range/AbstractRangeParser.php

-
message: "#^Method Ibexa\\\\Rest\\\\Server\\\\Input\\\\Parser\\\\Aggregation\\\\Range\\\\AbstractRangeParser\\:\\:visitRangeValue\\(\\) has no return type specified\\.$#"
count: 1
Expand Down Expand Up @@ -2465,16 +2440,6 @@ parameters:
count: 1
path: src/lib/Server/Input/Parser/Criterion/FullText.php

-
message: "#^Method Ibexa\\\\Rest\\\\Server\\\\Input\\\\Parser\\\\Criterion\\\\IsUserBased\\:\\:parse\\(\\) has parameter \\$data with no value type specified in iterable type array\\.$#"
count: 1
path: src/lib/Server/Input/Parser/Criterion/IsUserBased.php

-
message: "#^Method Ibexa\\\\Rest\\\\Server\\\\Input\\\\Parser\\\\Criterion\\\\IsUserEnabled\\:\\:parse\\(\\) has parameter \\$data with no value type specified in iterable type array\\.$#"
count: 1
path: src/lib/Server/Input/Parser/Criterion/IsUserEnabled.php

-
message: "#^Method Ibexa\\\\Rest\\\\Server\\\\Input\\\\Parser\\\\Criterion\\\\LanguageCode\\:\\:parse\\(\\) has parameter \\$data with no value type specified in iterable type array\\.$#"
count: 1
Expand Down Expand Up @@ -2545,11 +2510,6 @@ parameters:
count: 1
path: src/lib/Server/Input/Parser/Criterion/ObjectStateId.php

-
message: "#^Method Ibexa\\\\Rest\\\\Server\\\\Input\\\\Parser\\\\Criterion\\\\ObjectStateIdentifier\\:\\:parse\\(\\) has parameter \\$data with no value type specified in iterable type array\\.$#"
count: 1
path: src/lib/Server/Input/Parser/Criterion/ObjectStateIdentifier.php

-
message: "#^Method Ibexa\\\\Rest\\\\Server\\\\Input\\\\Parser\\\\Criterion\\\\Operator\\:\\:parse\\(\\) has parameter \\$data with no value type specified in iterable type array\\.$#"
count: 1
Expand All @@ -2575,41 +2535,16 @@ parameters:
count: 1
path: src/lib/Server/Input/Parser/Criterion/SectionId.php

-
message: "#^Method Ibexa\\\\Rest\\\\Server\\\\Input\\\\Parser\\\\Criterion\\\\SectionIdentifier\\:\\:parse\\(\\) has parameter \\$data with no value type specified in iterable type array\\.$#"
count: 1
path: src/lib/Server/Input/Parser/Criterion/SectionIdentifier.php

-
message: "#^Method Ibexa\\\\Rest\\\\Server\\\\Input\\\\Parser\\\\Criterion\\\\Sibling\\:\\:parse\\(\\) has parameter \\$data with no value type specified in iterable type array\\.$#"
count: 1
path: src/lib/Server/Input/Parser/Criterion/Sibling.php

-
message: "#^Method Ibexa\\\\Rest\\\\Server\\\\Input\\\\Parser\\\\Criterion\\\\Subtree\\:\\:parse\\(\\) has parameter \\$data with no value type specified in iterable type array\\.$#"
count: 1
path: src/lib/Server/Input/Parser/Criterion/Subtree.php

-
message: "#^Method Ibexa\\\\Rest\\\\Server\\\\Input\\\\Parser\\\\Criterion\\\\UserEmail\\:\\:parse\\(\\) has parameter \\$data with no value type specified in iterable type array\\.$#"
count: 1
path: src/lib/Server/Input/Parser/Criterion/UserEmail.php

-
message: "#^Method Ibexa\\\\Rest\\\\Server\\\\Input\\\\Parser\\\\Criterion\\\\UserId\\:\\:parse\\(\\) has parameter \\$data with no value type specified in iterable type array\\.$#"
count: 1
path: src/lib/Server/Input/Parser/Criterion/UserId.php

-
message: "#^Parameter \\#1 \\$value of class Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Values\\\\Content\\\\Query\\\\Criterion\\\\UserId constructor expects array\\<int\\>\\|int, array\\<int, string\\> given\\.$#"
count: 1
path: src/lib/Server/Input/Parser/Criterion/UserId.php

-
message: "#^Method Ibexa\\\\Rest\\\\Server\\\\Input\\\\Parser\\\\Criterion\\\\UserLogin\\:\\:parse\\(\\) has parameter \\$data with no value type specified in iterable type array\\.$#"
count: 1
path: src/lib/Server/Input/Parser/Criterion/UserLogin.php

-
message: "#^Method Ibexa\\\\Rest\\\\Server\\\\Input\\\\Parser\\\\Criterion\\\\UserMetadata\\:\\:parse\\(\\) has parameter \\$data with no value type specified in iterable type array\\.$#"
count: 1
Expand Down Expand Up @@ -2680,11 +2615,6 @@ parameters:
count: 1
path: src/lib/Server/Input/Parser/FieldDefinitionUpdate.php

-
message: "#^Method Ibexa\\\\Rest\\\\Server\\\\Input\\\\Parser\\\\JWTInput\\:\\:parse\\(\\) has parameter \\$data with no value type specified in iterable type array\\.$#"
count: 1
path: src/lib/Server/Input/Parser/JWTInput.php

-
message: "#^Method Ibexa\\\\Rest\\\\Server\\\\Input\\\\Parser\\\\Limitation\\\\PathStringRouteBasedLimitationParser\\:\\:parseIdFromHref\\(\\) has parameter \\$limitationValue with no type specified\\.$#"
count: 1
Expand Down Expand Up @@ -6675,16 +6605,6 @@ parameters:
count: 2
path: tests/bundle/Functional/UserTest.php

-
message: "#^Method Ibexa\\\\Tests\\\\Bundle\\\\Rest\\\\Functional\\\\ViewTest\\:\\:testViewRequestWithAndStatement\\(\\) has no return type specified\\.$#"
count: 1
path: tests/bundle/Functional/ViewTest.php

-
message: "#^Method Ibexa\\\\Tests\\\\Bundle\\\\Rest\\\\Functional\\\\ViewTest\\:\\:testViewRequestWithOrStatement\\(\\) has no return type specified\\.$#"
count: 1
path: tests/bundle/Functional/ViewTest.php

-
message: "#^Method Ibexa\\\\Tests\\\\Bundle\\\\Rest\\\\RequestParser\\\\RouterTest\\:\\:getRouterMock\\(\\) should return PHPUnit\\\\Framework\\\\MockObject\\\\MockObject&Symfony\\\\Component\\\\Routing\\\\RouterInterface but returns Symfony\\\\Component\\\\Routing\\\\RouterInterface\\.$#"
count: 1
Expand Down
10 changes: 10 additions & 0 deletions src/bundle/Resources/config/input_parsers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,16 @@ services:
tags:
- { name: ibexa.rest.input.parser, mediaType: application/vnd.ibexa.api.internal.LocationQuery }

Ibexa\Rest\Server\Input\Parser\Criterion\Location\Depth:
parent: Ibexa\Rest\Server\Common\Parser
tags:
- { name: ibexa.rest.input.parser, mediaType: application/vnd.ibexa.api.internal.criterion.LocationDepth }

Ibexa\Rest\Server\Input\Parser\Criterion\Location\IsMainLocation:
parent: Ibexa\Rest\Server\Common\Parser
tags:
- { name: ibexa.rest.input.parser, mediaType: application/vnd.ibexa.api.internal.criterion.IsMainLocation }

Ibexa\Rest\Server\Input\Parser\Criterion\Ancestor:
parent: Ibexa\Rest\Server\Common\Parser
class: Ibexa\Rest\Server\Input\Parser\Criterion\Ancestor
Expand Down
2 changes: 1 addition & 1 deletion src/contracts/Input/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ abstract class Parser
/**
* Parse input structure.
*
* @param array $data
* @param array<mixed> $data
* @param \Ibexa\Contracts\Rest\Input\ParsingDispatcher $parsingDispatcher
*
* @return \Ibexa\Contracts\Core\Repository\Values\ValueObject|object
Expand Down
84 changes: 84 additions & 0 deletions src/lib/Server/Input/Parser/Criterion/Location/Depth.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace Ibexa\Rest\Server\Input\Parser\Criterion\Location;

use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion\Location\Depth as DepthCriterion;
use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion\Operator;
use Ibexa\Contracts\Rest\Exceptions;
use Ibexa\Contracts\Rest\Input\ParsingDispatcher;
use Ibexa\Rest\Input\BaseParser;

final class Depth extends BaseParser
{
private const OPERATORS = [
'IN' => Operator::IN,
'EQ' => Operator::EQ,
'GT' => Operator::GT,
'GTE' => Operator::GTE,
'LT' => Operator::LT,
'LTE' => Operator::LTE,
'BETWEEN' => Operator::BETWEEN,
];

public function parse(array $data, ParsingDispatcher $parsingDispatcher): DepthCriterion
{
if (!array_key_exists('LocationDepth', $data)) {
throw new Exceptions\Parser('Invalid <LocationDepth> format');
}

$criterionData = $data['LocationDepth'];
if (!is_array($criterionData)) {
throw new Exceptions\Parser('Invalid <LocationDepth> format');
}

if (!isset($criterionData['Value'])) {
throw new Exceptions\Parser('Invalid <Value> format');
}

if (
is_string($criterionData['Value'])
&& is_numeric($criterionData['Value'])
&& ((int)$criterionData['Value'] == $criterionData['Value'])
) {
$criterionData['Value'] = (int)$criterionData['Value'];
}

if (!in_array(gettype($criterionData['Value']), ['integer', 'array'], true)) {
throw new Exceptions\Parser('Invalid <Value> format');
}

$value = $criterionData['Value'];

if (!isset($criterionData['Operator'])) {
throw new Exceptions\Parser('Invalid <Operator> format');
}

$operator = $this->getOperator($criterionData['Operator']);

return new DepthCriterion($operator, $value);
}

/**
* Get operator for the given literal name.
*/
private function getOperator(string $operatorName): string
{
$operatorName = strtoupper($operatorName);
if (!isset(self::OPERATORS[$operatorName])) {
throw new Exceptions\Parser(
sprintf(
'Unexpected LocationDepth operator. Expected one of: %s',
implode(', ', array_keys(self::OPERATORS))
)
);
}

return self::OPERATORS[$operatorName];
}
}
26 changes: 26 additions & 0 deletions src/lib/Server/Input/Parser/Criterion/Location/IsMainLocation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace Ibexa\Rest\Server\Input\Parser\Criterion\Location;

use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion\Location\IsMainLocation as IsMainLocationCriterion;
use Ibexa\Contracts\Rest\Exceptions;
use Ibexa\Contracts\Rest\Input\ParsingDispatcher;
use Ibexa\Rest\Input\BaseParser;

final class IsMainLocation extends BaseParser
{
public function parse(array $data, ParsingDispatcher $parsingDispatcher): IsMainLocationCriterion
{
if (!array_key_exists('IsMainLocation', $data)) {
throw new Exceptions\Parser('Invalid <IsMainLocation> format');
}

return new IsMainLocationCriterion($data['IsMainLocation']);
}
}
Loading