Skip to content

Commit

Permalink
Remove dependencies to old Xml generator
Browse files Browse the repository at this point in the history
  • Loading branch information
barw4 committed Oct 15, 2024
1 parent d781e88 commit d7db4db
Show file tree
Hide file tree
Showing 22 changed files with 119 additions and 282 deletions.
215 changes: 10 additions & 205 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -720,156 +720,6 @@ parameters:
count: 1
path: src/lib/Output/Generator/Json/FieldTypeHashGenerator.php

-
message: "#^Method Ibexa\\\\Rest\\\\Output\\\\Generator\\\\Xml\\:\\:endAttribute\\(\\) has no return type specified\\.$#"
count: 1
path: src/lib/Output/Generator/Xml.php

-
message: "#^Method Ibexa\\\\Rest\\\\Output\\\\Generator\\\\Xml\\:\\:endHashElement\\(\\) has no return type specified\\.$#"
count: 1
path: src/lib/Output/Generator/Xml.php

-
message: "#^Method Ibexa\\\\Rest\\\\Output\\\\Generator\\\\Xml\\:\\:endList\\(\\) has no return type specified\\.$#"
count: 1
path: src/lib/Output/Generator/Xml.php

-
message: "#^Method Ibexa\\\\Rest\\\\Output\\\\Generator\\\\Xml\\:\\:endObjectElement\\(\\) has no return type specified\\.$#"
count: 1
path: src/lib/Output/Generator/Xml.php

-
message: "#^Method Ibexa\\\\Rest\\\\Output\\\\Generator\\\\Xml\\:\\:endValueElement\\(\\) has no return type specified\\.$#"
count: 1
path: src/lib/Output/Generator/Xml.php

-
message: "#^Method Ibexa\\\\Rest\\\\Output\\\\Generator\\\\Xml\\:\\:generateFieldTypeHash\\(\\) has no return type specified\\.$#"
count: 1
path: src/lib/Output/Generator/Xml.php

-
message: "#^Method Ibexa\\\\Rest\\\\Output\\\\Generator\\\\Xml\\:\\:startAttribute\\(\\) has no return type specified\\.$#"
count: 1
path: src/lib/Output/Generator/Xml.php

-
message: "#^Method Ibexa\\\\Rest\\\\Output\\\\Generator\\\\Xml\\:\\:startDocument\\(\\) has no return type specified\\.$#"
count: 1
path: src/lib/Output/Generator/Xml.php

-
message: "#^Method Ibexa\\\\Rest\\\\Output\\\\Generator\\\\Xml\\:\\:startHashElement\\(\\) has no return type specified\\.$#"
count: 1
path: src/lib/Output/Generator/Xml.php

-
message: "#^Method Ibexa\\\\Rest\\\\Output\\\\Generator\\\\Xml\\:\\:startList\\(\\) has no return type specified\\.$#"
count: 1
path: src/lib/Output/Generator/Xml.php

-
message: "#^Method Ibexa\\\\Rest\\\\Output\\\\Generator\\\\Xml\\:\\:startObjectElement\\(\\) has no return type specified\\.$#"
count: 1
path: src/lib/Output/Generator/Xml.php

-
message: "#^Method Ibexa\\\\Rest\\\\Output\\\\Generator\\\\Xml\\:\\:toArray\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: src/lib/Output/Generator/Xml.php

-
message: "#^Parameter \\#1 \\$content of method XMLWriter\\:\\:text\\(\\) expects string, bool\\|float\\|int\\|string\\|null given\\.$#"
count: 1
path: src/lib/Output/Generator/Xml.php

-
message: "#^Cannot call method error\\(\\) on Psr\\\\Log\\\\LoggerInterface\\|null\\.$#"
count: 1
path: src/lib/Output/Generator/Xml/FieldTypeHashGenerator.php

-
message: "#^Method Ibexa\\\\Rest\\\\Output\\\\Generator\\\\Xml\\\\FieldTypeHashGenerator\\:\\:generateArrayValue\\(\\) has no return type specified\\.$#"
count: 1
path: src/lib/Output/Generator/Xml/FieldTypeHashGenerator.php

-
message: "#^Method Ibexa\\\\Rest\\\\Output\\\\Generator\\\\Xml\\\\FieldTypeHashGenerator\\:\\:generateArrayValue\\(\\) has parameter \\$value with no value type specified in iterable type array\\.$#"
count: 1
path: src/lib/Output/Generator/Xml/FieldTypeHashGenerator.php

-
message: "#^Method Ibexa\\\\Rest\\\\Output\\\\Generator\\\\Xml\\\\FieldTypeHashGenerator\\:\\:generateBooleanValue\\(\\) has no return type specified\\.$#"
count: 1
path: src/lib/Output/Generator/Xml/FieldTypeHashGenerator.php

-
message: "#^Method Ibexa\\\\Rest\\\\Output\\\\Generator\\\\Xml\\\\FieldTypeHashGenerator\\:\\:generateFloatValue\\(\\) has no return type specified\\.$#"
count: 1
path: src/lib/Output/Generator/Xml/FieldTypeHashGenerator.php

-
message: "#^Method Ibexa\\\\Rest\\\\Output\\\\Generator\\\\Xml\\\\FieldTypeHashGenerator\\:\\:generateHashArray\\(\\) has no return type specified\\.$#"
count: 1
path: src/lib/Output/Generator/Xml/FieldTypeHashGenerator.php

-
message: "#^Method Ibexa\\\\Rest\\\\Output\\\\Generator\\\\Xml\\\\FieldTypeHashGenerator\\:\\:generateHashArray\\(\\) has parameter \\$value with no value type specified in iterable type array\\.$#"
count: 1
path: src/lib/Output/Generator/Xml/FieldTypeHashGenerator.php

-
message: "#^Method Ibexa\\\\Rest\\\\Output\\\\Generator\\\\Xml\\\\FieldTypeHashGenerator\\:\\:generateHashValue\\(\\) has no return type specified\\.$#"
count: 1
path: src/lib/Output/Generator/Xml/FieldTypeHashGenerator.php

-
message: "#^Method Ibexa\\\\Rest\\\\Output\\\\Generator\\\\Xml\\\\FieldTypeHashGenerator\\:\\:generateIntegerValue\\(\\) has no return type specified\\.$#"
count: 1
path: src/lib/Output/Generator/Xml/FieldTypeHashGenerator.php

-
message: "#^Method Ibexa\\\\Rest\\\\Output\\\\Generator\\\\Xml\\\\FieldTypeHashGenerator\\:\\:generateKeyAttribute\\(\\) has no return type specified\\.$#"
count: 1
path: src/lib/Output/Generator/Xml/FieldTypeHashGenerator.php

-
message: "#^Method Ibexa\\\\Rest\\\\Output\\\\Generator\\\\Xml\\\\FieldTypeHashGenerator\\:\\:generateListArray\\(\\) has no return type specified\\.$#"
count: 1
path: src/lib/Output/Generator/Xml/FieldTypeHashGenerator.php

-
message: "#^Method Ibexa\\\\Rest\\\\Output\\\\Generator\\\\Xml\\\\FieldTypeHashGenerator\\:\\:generateListArray\\(\\) has parameter \\$value with no value type specified in iterable type array\\.$#"
count: 1
path: src/lib/Output/Generator/Xml/FieldTypeHashGenerator.php

-
message: "#^Method Ibexa\\\\Rest\\\\Output\\\\Generator\\\\Xml\\\\FieldTypeHashGenerator\\:\\:generateNullValue\\(\\) has no return type specified\\.$#"
count: 1
path: src/lib/Output/Generator/Xml/FieldTypeHashGenerator.php

-
message: "#^Method Ibexa\\\\Rest\\\\Output\\\\Generator\\\\Xml\\\\FieldTypeHashGenerator\\:\\:generateStringValue\\(\\) has no return type specified\\.$#"
count: 1
path: src/lib/Output/Generator/Xml/FieldTypeHashGenerator.php

-
message: "#^Method Ibexa\\\\Rest\\\\Output\\\\Generator\\\\Xml\\\\FieldTypeHashGenerator\\:\\:generateValue\\(\\) has no return type specified\\.$#"
count: 1
path: src/lib/Output/Generator/Xml/FieldTypeHashGenerator.php

-
message: "#^Method Ibexa\\\\Rest\\\\Output\\\\Generator\\\\Xml\\\\FieldTypeHashGenerator\\:\\:isNumericArray\\(\\) has parameter \\$value with no value type specified in iterable type array\\.$#"
count: 1
path: src/lib/Output/Generator/Xml/FieldTypeHashGenerator.php

-
message: "#^Parameter \\#1 \\$content of method XMLWriter\\:\\:text\\(\\) expects string, int given\\.$#"
count: 1
path: src/lib/Output/Generator/Xml/FieldTypeHashGenerator.php

-
message: "#^Method Ibexa\\\\Rest\\\\Output\\\\ValueObjectVisitor\\\\ContentObjectStates\\:\\:visit\\(\\) has no return type specified\\.$#"
count: 1
Expand Down Expand Up @@ -6171,74 +6021,29 @@ parameters:
path: tests/lib/Output/Generator/JsonTest.php

-
message: "#^Method Ibexa\\\\Tests\\\\Rest\\\\Output\\\\Generator\\\\XmlTest\\:\\:testGeneratorAttribute\\(\\) has no return type specified\\.$#"
count: 1
path: tests/lib/Output/Generator/XmlTest.php

-
message: "#^Method Ibexa\\\\Tests\\\\Rest\\\\Output\\\\Generator\\\\XmlTest\\:\\:testGeneratorDocument\\(\\) has no return type specified\\.$#"
count: 1
path: tests/lib/Output/Generator/XmlTest.php

-
message: "#^Method Ibexa\\\\Tests\\\\Rest\\\\Output\\\\Generator\\\\XmlTest\\:\\:testGeneratorElement\\(\\) has no return type specified\\.$#"
message: "#^Call to method setFormatOutput\\(\\) on an unknown class Ibexa\\\\Rest\\\\Output\\\\Generator\\\\Xml\\.$#"
count: 1
path: tests/lib/Output/Generator/XmlTest.php
path: tests/lib/Output/Generator/Xml/FieldTypeHashGeneratorTest.php

-
message: "#^Method Ibexa\\\\Tests\\\\Rest\\\\Output\\\\Generator\\\\XmlTest\\:\\:testGeneratorElementList\\(\\) has no return type specified\\.$#"
message: "#^Instantiated class Ibexa\\\\Rest\\\\Output\\\\Generator\\\\Xml not found\\.$#"
count: 1
path: tests/lib/Output/Generator/XmlTest.php
path: tests/lib/Output/Generator/Xml/FieldTypeHashGeneratorTest.php

-
message: "#^Method Ibexa\\\\Tests\\\\Rest\\\\Output\\\\Generator\\\\XmlTest\\:\\:testGeneratorElementMediaTypeOverwrite\\(\\) has no return type specified\\.$#"
message: "#^Instantiated class Ibexa\\\\Rest\\\\Output\\\\Generator\\\\Xml\\\\FieldTypeHashGenerator not found\\.$#"
count: 1
path: tests/lib/Output/Generator/XmlTest.php
path: tests/lib/Output/Generator/Xml/FieldTypeHashGeneratorTest.php

-
message: "#^Method Ibexa\\\\Tests\\\\Rest\\\\Output\\\\Generator\\\\XmlTest\\:\\:testGeneratorHashElement\\(\\) has no return type specified\\.$#"
message: "#^Method Ibexa\\\\Tests\\\\Rest\\\\Output\\\\Generator\\\\Xml\\\\FieldTypeHashGeneratorTest\\:\\:initializeFieldTypeHashGenerator\\(\\) has invalid return type Ibexa\\\\Rest\\\\Output\\\\Generator\\\\Xml\\\\FieldTypeHashGenerator\\.$#"
count: 1
path: tests/lib/Output/Generator/XmlTest.php
path: tests/lib/Output/Generator/Xml/FieldTypeHashGeneratorTest.php

-
message: "#^Method Ibexa\\\\Tests\\\\Rest\\\\Output\\\\Generator\\\\XmlTest\\:\\:testGeneratorMultipleAttributes\\(\\) has no return type specified\\.$#"
message: "#^Method Ibexa\\\\Tests\\\\Rest\\\\Output\\\\Generator\\\\Xml\\\\FieldTypeHashGeneratorTest\\:\\:initializeGenerator\\(\\) has invalid return type Ibexa\\\\Rest\\\\Output\\\\Generator\\\\Xml\\.$#"
count: 1
path: tests/lib/Output/Generator/XmlTest.php

-
message: "#^Method Ibexa\\\\Tests\\\\Rest\\\\Output\\\\Generator\\\\XmlTest\\:\\:testGeneratorStackedElement\\(\\) has no return type specified\\.$#"
count: 1
path: tests/lib/Output/Generator/XmlTest.php

-
message: "#^Method Ibexa\\\\Tests\\\\Rest\\\\Output\\\\Generator\\\\XmlTest\\:\\:testGeneratorStartEndAttribute\\(\\) has no return type specified\\.$#"
count: 1
path: tests/lib/Output/Generator/XmlTest.php

-
message: "#^Method Ibexa\\\\Tests\\\\Rest\\\\Output\\\\Generator\\\\XmlTest\\:\\:testGeneratorStartEndValueElement\\(\\) has no return type specified\\.$#"
count: 1
path: tests/lib/Output/Generator/XmlTest.php

-
message: "#^Method Ibexa\\\\Tests\\\\Rest\\\\Output\\\\Generator\\\\XmlTest\\:\\:testGeneratorValueElement\\(\\) has no return type specified\\.$#"
count: 1
path: tests/lib/Output/Generator/XmlTest.php

-
message: "#^Method Ibexa\\\\Tests\\\\Rest\\\\Output\\\\Generator\\\\XmlTest\\:\\:testGeneratorValueList\\(\\) has no return type specified\\.$#"
count: 1
path: tests/lib/Output/Generator/XmlTest.php

-
message: "#^Method Ibexa\\\\Tests\\\\Rest\\\\Output\\\\Generator\\\\XmlTest\\:\\:testGetMediaType\\(\\) has no return type specified\\.$#"
count: 1
path: tests/lib/Output/Generator/XmlTest.php

-
message: "#^Method Ibexa\\\\Tests\\\\Rest\\\\Output\\\\Generator\\\\XmlTest\\:\\:testSerializeBool\\(\\) has no return type specified\\.$#"
count: 1
path: tests/lib/Output/Generator/XmlTest.php
path: tests/lib/Output/Generator/Xml/FieldTypeHashGeneratorTest.php

-
message: "#^Parameter \\#1 \\$boolValue of method Ibexa\\\\Contracts\\\\Rest\\\\Output\\\\Generator\\:\\:serializeBool\\(\\) expects bool, string given\\.$#"
Expand Down
2 changes: 1 addition & 1 deletion src/contracts/Output/VisitorAdapterNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ private function buildContext(array $context, ?string $format): array
$context += [self::CALLED_CONTEXT => true];

if ($format === 'xml') {
$context += [self::OUTER_ELEMENT => true, 'as_collection' => true];
$context += [self::OUTER_ELEMENT => true];
}

return $context;
Expand Down
8 changes: 5 additions & 3 deletions src/lib/Output/Generator/InMemory/Xml.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function startAttribute($name, $value): void
$this->json->{'@' . $name} = $value;
}

public function serializeBool($boolValue)
public function serializeBool($boolValue): string
{
return $boolValue ? 'true' : 'false';
}
Expand Down Expand Up @@ -91,8 +91,6 @@ public function endDocument(mixed $data): string

$vars = get_object_vars($data);
$encoderContext = $this->getEncoderContext($vars);
$encoderContext['as_collection'] = true;
$encoderContext[VisitorAdapterNormalizer::OUTER_ELEMENT] = true;

$normalizers = [
new ArrayListNormalizer(),
Expand All @@ -110,6 +108,10 @@ public function getEncoderContext(array $data): array
{
return [
XmlEncoder::ROOT_NODE_NAME => array_key_first($data),
XmlEncoder::VERSION => '1.0',
XmlEncoder::ENCODING => 'UTF-8',
XmlEncoder::AS_COLLECTION => true,
VisitorAdapterNormalizer::OUTER_ELEMENT => true,
];
}
}
49 changes: 49 additions & 0 deletions src/lib/Output/Generator/InMemory/Xml/FieldTypeHashGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,60 @@

namespace Ibexa\Rest\Output\Generator\InMemory\Xml;

use Ibexa\Rest\Output\Generator\Data\ArrayList;
use Ibexa\Rest\Output\Generator\Json\FieldTypeHashGenerator as JsonFieldTypeHashGenerator;
use Ibexa\Rest\Output\Generator\Json\JsonObject;

final class FieldTypeHashGenerator extends JsonFieldTypeHashGenerator
{
protected function generateValue($parent, $value): mixed
{
if ($value === null) {
return null;
} elseif (is_bool($value)) {
return $value ? 'true' : 'false';
} elseif (is_float($value)) {
return sprintf('%F', $value);
} elseif (is_array($value)) {
return $this->generateArrayValue($parent, $value);
} else {
return $value;
}
}

/**
* Generates an array value from $value.
*
* @param array $value
* @param string|null $key
*/
protected function generateArrayValue($parent, $value)

Check failure on line 38 in src/lib/Output/Generator/InMemory/Xml/FieldTypeHashGenerator.php

View workflow job for this annotation

GitHub Actions / Unit & integration tests (8.3)

Method Ibexa\Rest\Output\Generator\InMemory\Xml\FieldTypeHashGenerator::generateArrayValue() has parameter $value with no value type specified in iterable type array.

Check failure on line 38 in src/lib/Output/Generator/InMemory/Xml/FieldTypeHashGenerator.php

View workflow job for this annotation

GitHub Actions / Unit & integration tests (8.3)

PHPDoc tag @param references unknown parameter: $key
{
if ($this->isNumericArray($value)) {
return $this->generateListArray($parent, $value);
} else {
return $this->generateHashArray($parent, $value);
}
}

/**
* Generates a JSON array from the given $hashArray with $parent.
*
* @param \Ibexa\Rest\Output\Generator\Json\ArrayObject|\Ibexa\Rest\Output\Generator\Json\JsonObject $parent
* @param array $listArray
*
* @return \Ibexa\Rest\Output\Generator\Json\ArrayObject
*/
protected function generateListArray($parent, array $listArray)

Check failure on line 55 in src/lib/Output/Generator/InMemory/Xml/FieldTypeHashGenerator.php

View workflow job for this annotation

GitHub Actions / Unit & integration tests (8.3)

Method Ibexa\Rest\Output\Generator\InMemory\Xml\FieldTypeHashGenerator::generateListArray() has parameter $listArray with no value type specified in iterable type array.
{
$arrayList = new ArrayList('value', $parent);
foreach ($listArray as $listItem) {
$arrayList->append($this->generateValue($parent, $listItem));
}

return $arrayList;

Check failure on line 62 in src/lib/Output/Generator/InMemory/Xml/FieldTypeHashGenerator.php

View workflow job for this annotation

GitHub Actions / Unit & integration tests (8.3)

Method Ibexa\Rest\Output\Generator\InMemory\Xml\FieldTypeHashGenerator::generateListArray() should return Ibexa\Rest\Output\Generator\Json\ArrayObject but returns Ibexa\Rest\Output\Generator\Data\ArrayList.
}

/**
* Generates a JSON object from the given $hashArray with $parent.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ public function testGenerateEmptyStringValue()

public function testGenerateStringValueWithSpecialChars()
{
//TODO remove CData when Symfony 6.4 arrives as it has such an option
$this->getGenerator()->generateFieldTypeHash(
'fieldValue',
'<?xml version="1.0" encoding="UTF-8"?><ezxml>Sindelfingen</ezxml>'
Expand Down
4 changes: 2 additions & 2 deletions tests/lib/Output/Generator/Xml/FieldTypeHashGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

namespace Ibexa\Tests\Rest\Output\Generator\Xml;

use Ibexa\Rest\Output\Generator\Xml;
use Ibexa\Rest\Output\Generator\Xml\FieldTypeHashGenerator;
use Ibexa\Rest\Output\Generator\InMemory\Xml;
use Ibexa\Rest\Output\Generator\InMemory\Xml\FieldTypeHashGenerator;
use Ibexa\Tests\Rest\Output\Generator\FieldTypeHashGeneratorBaseTest;

final class FieldTypeHashGeneratorTest extends FieldTypeHashGeneratorBaseTest
Expand Down
Loading

0 comments on commit d7db4db

Please sign in to comment.