Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
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
24 changes: 0 additions & 24 deletions phpstan-baseline-7.4.neon
Original file line number Diff line number Diff line change
@@ -1,29 +1,5 @@
parameters:
ignoreErrors:
-
message: '#^Access to an undefined property DOMNode\:\:\$data\.$#'
identifier: property.notFound
count: 1
path: src/lib/Input/Handler/Xml.php

-
message: '#^Access to an undefined property DOMNode\:\:\$tagName\.$#'
identifier: property.notFound
count: 1
path: src/lib/Input/Handler/Xml.php

-
message: '#^Access to an undefined property DOMNode\:\:\$wholeText\.$#'
identifier: property.notFound
count: 1
path: src/lib/Input/Handler/Xml.php

-
message: '#^Parameter \#1 \$domElement of method Ibexa\\Rest\\Input\\Handler\\Xml\:\:parseFieldTypeHash\(\) expects DOMElement, DOMNode given\.$#'
identifier: argument.type
count: 1
path: src/lib/Input/Handler/Xml.php

-
message: '#^Parameter \#2 \$str of function explode expects string, string\|null given\.$#'
identifier: argument.type
Expand Down
36 changes: 0 additions & 36 deletions phpstan-baseline-gte-8.0.neon
Original file line number Diff line number Diff line change
@@ -1,41 +1,5 @@
parameters:
ignoreErrors:
-
message: '#^Access to an undefined property DOMNode\:\:\$data\.$#'
identifier: property.notFound
count: 2
path: src/lib/Input/Handler/Xml.php

-
message: '#^Access to an undefined property DOMNode\:\:\$tagName\.$#'
identifier: property.notFound
count: 2
path: src/lib/Input/Handler/Xml.php

-
message: '#^Access to an undefined property DOMNode\:\:\$wholeText\.$#'
identifier: property.notFound
count: 2
path: src/lib/Input/Handler/Xml.php

-
message: '#^Call to an undefined method DOMNode\:\:getAttribute\(\)\.$#'
identifier: method.notFound
count: 1
path: src/lib/Input/Handler/Xml.php

-
message: '#^Call to an undefined method DOMNode\:\:hasAttribute\(\)\.$#'
identifier: method.notFound
count: 1
path: src/lib/Input/Handler/Xml.php

-
message: '#^Parameter \#1 \$domElement of method Ibexa\\Rest\\Input\\Handler\\Xml\:\:parseFieldTypeHash\(\) expects DOMElement, DOMNode given\.$#'
identifier: argument.type
count: 1
path: src/lib/Input/Handler/Xml.php

-
message: '#^Parameter \#2 \$string of function explode expects string, string\|null given\.$#'
identifier: argument.type
Expand Down
66 changes: 0 additions & 66 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -2754,12 +2754,6 @@ parameters:
count: 1
path: src/lib/Server/Input/Parser/Criterion/LogicalOperator.php

-
message: '#^Method Ibexa\\Rest\\Server\\Input\\Parser\\Criterion\\LogicalOperator\:\:parse\(\) has Ibexa\\Contracts\\Rest\\Exceptions\\Parser in PHPDoc @throws tag but it''s not thrown\.$#'
identifier: throws.unusedType
count: 1
path: src/lib/Server/Input/Parser/Criterion/LogicalOperator.php

-
message: '#^Method Ibexa\\Rest\\Server\\Input\\Parser\\Criterion\\LogicalOperator\:\:parse\(\) has parameter \$data with no value type specified in iterable type array\.$#'
identifier: missingType.iterableValue
Expand All @@ -2772,12 +2766,6 @@ parameters:
count: 1
path: src/lib/Server/Input/Parser/Criterion/LogicalOr.php

-
message: '#^Method Ibexa\\Rest\\Server\\Input\\Parser\\Criterion\\MoreLikeThis\:\:parse\(\) has Ibexa\\Contracts\\Rest\\Exceptions\\Parser in PHPDoc @throws tag but it''s not thrown\.$#'
identifier: throws.unusedType
count: 1
path: src/lib/Server/Input/Parser/Criterion/MoreLikeThis.php

-
message: '#^Method Ibexa\\Rest\\Server\\Input\\Parser\\Criterion\\MoreLikeThis\:\:parse\(\) has parameter \$data with no value type specified in iterable type array\.$#'
identifier: missingType.iterableValue
Expand All @@ -2796,12 +2784,6 @@ parameters:
count: 1
path: src/lib/Server/Input/Parser/Criterion/ObjectStateId.php

-
message: '#^Method Ibexa\\Rest\\Server\\Input\\Parser\\Criterion\\Operator\:\:parse\(\) has Ibexa\\Contracts\\Rest\\Exceptions\\Parser in PHPDoc @throws tag but it''s not thrown\.$#'
identifier: throws.unusedType
count: 1
path: src/lib/Server/Input/Parser/Criterion/Operator.php

-
message: '#^Method Ibexa\\Rest\\Server\\Input\\Parser\\Criterion\\Operator\:\:parse\(\) has parameter \$data with no value type specified in iterable type array\.$#'
identifier: missingType.iterableValue
Expand Down Expand Up @@ -6018,12 +6000,6 @@ parameters:
count: 2
path: tests/bundle/Functional/RoleTest.php

-
message: '#^Cannot access property \$length on DOMNodeList\<DOMNode\>\|false\.$#'
identifier: property.nonObject
count: 1
path: tests/bundle/Functional/RootTest.php

-
message: '#^Method Ibexa\\Tests\\Bundle\\Rest\\Functional\\RootTest\:\:assertXMLTag\(\) has no return type specified\.$#'
identifier: missingType.return
Expand Down Expand Up @@ -6852,24 +6828,6 @@ parameters:
count: 1
path: tests/bundle/Functional/SectionTest.php

-
message: '#^Cannot access property \$length on DOMNodeList\<DOMNode\>\|false\.$#'
identifier: property.nonObject
count: 1
path: tests/bundle/Functional/SessionTest.php

-
message: '#^Cannot access property \$nodeValue on DOMNode\|null\.$#'
identifier: property.nonObject
count: 1
path: tests/bundle/Functional/SessionTest.php

-
message: '#^Cannot call method item\(\) on DOMNodeList\<DOMNode\>\|false\.$#'
identifier: method.nonObject
count: 1
path: tests/bundle/Functional/SessionTest.php

-
message: '#^Method Ibexa\\Tests\\Bundle\\Rest\\Functional\\SessionTest\:\:assertHttpResponseDeletesSessionCookie\(\) has no return type specified\.$#'
identifier: missingType.return
Expand Down Expand Up @@ -8928,12 +8886,6 @@ parameters:
count: 1
path: tests/lib/Output/ValueObjectVisitorBaseTest.php

-
message: '#^Cannot access property \$length on DOMNodeList\<DOMNode\>\|false\.$#'
identifier: property.nonObject
count: 1
path: tests/lib/Output/ValueObjectVisitorBaseTest.php

-
message: '#^Method Ibexa\\Tests\\Rest\\Output\\ValueObjectVisitorBaseTest\:\:addRouteExpectation\(\) has no return type specified\.$#'
identifier: missingType.return
Expand Down Expand Up @@ -10338,12 +10290,6 @@ parameters:
count: 1
path: tests/lib/Server/Input/Parser/ViewInputTest.php

-
message: '#^Cannot access property \$length on DOMNodeList\<DOMNode\>\|false\.$#'
identifier: property.nonObject
count: 1
path: tests/lib/Server/Output/ValueObjectVisitor/BookmarkListTest.php

-
message: '#^Method Ibexa\\Tests\\Rest\\Server\\Output\\ValueObjectVisitor\\CachedValueTest\:\:testVisit\(\) has no return type specified\.$#'
identifier: missingType.return
Expand Down Expand Up @@ -10752,18 +10698,6 @@ parameters:
count: 2
path: tests/lib/Server/Output/ValueObjectVisitor/ExceptionTest.php

-
message: '#^Cannot access property \$textContent on DOMNode\|null\.$#'
identifier: property.nonObject
count: 1
path: tests/lib/Server/Output/ValueObjectVisitor/ExceptionTest.php

-
message: '#^Cannot call method item\(\) on DOMNodeList\<DOMNode\>\|false\.$#'
identifier: method.nonObject
count: 1
path: tests/lib/Server/Output/ValueObjectVisitor/ExceptionTest.php

-
message: '#^Method Ibexa\\Tests\\Rest\\Server\\Output\\ValueObjectVisitor\\ExceptionTest\:\:testResultContainsErrorCode\(\) has no return type specified\.$#'
identifier: missingType.return
Expand Down
5 changes: 5 additions & 0 deletions src/bundle/Resources/config/criteria.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ services:
tags:
- { name: ibexa.rest.input.parser, mediaType: application/vnd.ibexa.api.internal.criterion.content_type.ContentTypeGroupId }

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

Ibexa\Rest\Server\Input\Parser\ContentType\Criterion\ContainsFieldDefinitionId:
parent: Ibexa\Rest\Server\Common\Parser
tags:
Expand Down
36 changes: 32 additions & 4 deletions src/lib/Input/Handler/Xml.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@
*/
namespace Ibexa\Rest\Input\Handler;

use DOMCharacterData;
use DOMElement;
use DOMText;
use Ibexa\Contracts\Rest\Exceptions;
use Ibexa\Contracts\Rest\Input\Handler;
use InvalidArgumentException;
use RuntimeException;

/**
* Input format handler base class.
Expand Down Expand Up @@ -120,16 +124,20 @@ protected function convertDom(\DOMNode $node)
$current = [];
$text = '';

if ($node instanceof \DOMElement && $node->attributes !== null) {
if ($node instanceof DOMElement && $node->attributes !== null) {
foreach ($node->attributes as $name => $attribute) {
$current["_{$name}"] = $attribute->value;
}
}

$parentTagName = $node instanceof \DOMElement ? $node->tagName : false;
$parentTagName = $node instanceof DOMElement ? $node->tagName : false;
foreach ($node->childNodes as $childNode) {
switch ($childNode->nodeType) {
case XML_ELEMENT_NODE:
if (!$childNode instanceof DOMElement) {
break;
}

$tagName = $childNode->tagName;

if (in_array($tagName, $this->fieldTypeHashElements, true)) {
Expand Down Expand Up @@ -160,10 +168,18 @@ protected function convertDom(\DOMNode $node)
break;

case XML_TEXT_NODE:
if (!$childNode instanceof DOMText) {
break;
}

$text .= $childNode->wholeText;
break;

case XML_CDATA_SECTION_NODE:
if (!$childNode instanceof DOMCharacterData) {
break;
}

$text .= $childNode->data;
break;
}
Expand All @@ -187,7 +203,7 @@ protected function convertDom(\DOMNode $node)
*
* @return array|string|null
*/
protected function parseFieldTypeHash(\DOMElement $domElement)
protected function parseFieldTypeHash(DOMElement $domElement)
{
$result = $this->parseFieldTypeValues($domElement->childNodes);

Expand All @@ -214,8 +230,12 @@ protected function parseFieldTypeValues(\DOMNodeList $valueNodes)
foreach ($valueNodes as $valueNode) {
switch ($valueNode->nodeType) {
case XML_ELEMENT_NODE:
if (!$valueNode instanceof DOMElement) {
break;
}

if ($valueNode->tagName !== 'value') {
throw new \RuntimeException(
throw new RuntimeException(
sprintf(
'Invalid value tag: <%s>.',
$valueNode->tagName
Expand All @@ -232,10 +252,18 @@ protected function parseFieldTypeValues(\DOMNodeList $valueNodes)
break;

case XML_TEXT_NODE:
if (!$valueNode instanceof DOMText) {
break;
}

$resultString .= $valueNode->wholeText;
break;

case XML_CDATA_SECTION_NODE:
if (!$valueNode instanceof DOMCharacterData) {
break;
}

$resultString .= $valueNode->data;
break;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?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\ContentType\Criterion;

use Ibexa\Contracts\Core\Repository\Values\ContentType\Query\Criterion\ContentTypeGroupName as ContentTypeGroupNameCriterion;
use Ibexa\Contracts\Rest\Exceptions;
use Ibexa\Contracts\Rest\Input\ParsingDispatcher;
use Ibexa\Rest\Input\BaseParser;

final class ContentTypeGroupName extends BaseParser implements ContentTypeCriterionInterface
{
private const GROUP_NAME = 'ContentTypeGroupNameCriterion';

/**
* @param array<mixed> $data
*
* @throws \Ibexa\Contracts\Rest\Exceptions\Parser
*/
public function parse(array $data, ParsingDispatcher $parsingDispatcher): ContentTypeGroupNameCriterion
{
if (!array_key_exists(self::GROUP_NAME, $data)) {
throw new Exceptions\Parser('Invalid <' . self::GROUP_NAME . '> format');
}

$ids = $data[self::GROUP_NAME];

return new ContentTypeGroupNameCriterion($ids);
}

public function getName(): string
{
return self::GROUP_NAME;
}
}
30 changes: 30 additions & 0 deletions tests/bundle/Functional/ContentTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,36 @@ public function testCreateView(): void
self::assertArrayHasKey('ContentTypeList', $responseData);
self::assertSame('folder', $responseData['ContentTypeList']['ContentType'][0]['identifier']);
}

public function testCreateViewWithContentTypeGroupName(): void
{
$body = <<< XML
<?xml version="1.0" encoding="UTF-8"?>
<ViewInput>
<identifier>ContentTypeView</identifier>
<ContentTypeQuery>
<Query>
<ContentTypeGroupNameCriterion>media</ContentTypeGroupNameCriterion>
</Query>
<limit>10</limit>
<offset>0</offset>
</ContentTypeQuery>
</ViewInput>
XML;
$request = $this->createHttpRequest(
'POST',
'/api/ibexa/v2/content/types/view',
'ContentTypeViewInput+xml',
'ContentTypeView+json',
$body
);

$response = $this->sendHttpRequest($request);
$responseData = json_decode($response->getBody(), true);

self::assertArrayHasKey('ContentTypeList', $responseData);
self::assertSame('image', $responseData['ContentTypeList']['ContentType'][0]['identifier']);
}
}

class_alias(ContentTypeTest::class, 'EzSystems\EzPlatformRestBundle\Tests\Functional\ContentTypeTest');
Loading
Loading