From a4d6ed888350bb8e691c5f6fdcb805470149f359 Mon Sep 17 00:00:00 2001 From: Norbert Orzechowicz Date: Wed, 6 Sep 2023 12:58:45 +0200 Subject: [PATCH] adjustments after code review --- .../Adapter/XML/XMLReaderExtractorTest.php | 23 ++++++++--------- .../ETL/Row/Reference/Expression/Cast.php | 3 +-- .../Expression/Cast/XMLConverter.php | 8 ++---- src/core/etl/src/Flow/ETL/Rows.php | 25 ------------------- 4 files changed, 13 insertions(+), 46 deletions(-) diff --git a/src/adapter/etl-adapter-xml/tests/Flow/ETL/Tests/Integration/Adapter/XML/XMLReaderExtractorTest.php b/src/adapter/etl-adapter-xml/tests/Flow/ETL/Tests/Integration/Adapter/XML/XMLReaderExtractorTest.php index 513a4ef65..4da95a772 100644 --- a/src/adapter/etl-adapter-xml/tests/Flow/ETL/Tests/Integration/Adapter/XML/XMLReaderExtractorTest.php +++ b/src/adapter/etl-adapter-xml/tests/Flow/ETL/Tests/Integration/Adapter/XML/XMLReaderExtractorTest.php @@ -18,12 +18,11 @@ public function test_reading_xml() : void $xml = new \DOMDocument(); $xml->load(__DIR__ . '/xml/simple_items.xml'); - $this->assertTrue( - (new Rows(Row::create(Entry::xml('row', $xml))))->equals( - (new Flow()) - ->read(XML::from(__DIR__ . '/xml/simple_items.xml')) - ->fetch() - ) + $this->assertEquals( + (new Rows(Row::create(Entry::xml('row', $xml)))), + (new Flow()) + ->read(XML::from(__DIR__ . '/xml/simple_items.xml')) + ->fetch() ); } @@ -67,13 +66,11 @@ public function test_reading_xml_from_path() : void XML); - $this->assertTrue( - (new Rows(Row::create(Entry::xml('row', $xml)))) - ->equals( - (new Flow()) - ->read(XML::from(__DIR__ . '/xml/simple_items.xml', 'root/items')) - ->fetch() - ) + $this->assertEquals( + new Rows(Row::create(Entry::xml('row', $xml))), + (new Flow()) + ->read(XML::from(__DIR__ . '/xml/simple_items.xml', 'root/items')) + ->fetch() ); } } diff --git a/src/core/etl/src/Flow/ETL/Row/Reference/Expression/Cast.php b/src/core/etl/src/Flow/ETL/Row/Reference/Expression/Cast.php index 6a183419b..a62b85206 100644 --- a/src/core/etl/src/Flow/ETL/Row/Reference/Expression/Cast.php +++ b/src/core/etl/src/Flow/ETL/Row/Reference/Expression/Cast.php @@ -69,9 +69,8 @@ private function toXML(mixed $value) : \DOMDocument { if (\is_string($value)) { $doc = new \DOMDocument(); - $loaded = @$doc->load($value); - if (!$loaded) { + if (!@$doc->load($value)) { throw new InvalidArgumentException('Invalid XML string given: ' . $value); } diff --git a/src/core/etl/src/Flow/ETL/Row/Reference/Expression/Cast/XMLConverter.php b/src/core/etl/src/Flow/ETL/Row/Reference/Expression/Cast/XMLConverter.php index 0aebc7dbf..5bfcd3453 100644 --- a/src/core/etl/src/Flow/ETL/Row/Reference/Expression/Cast/XMLConverter.php +++ b/src/core/etl/src/Flow/ETL/Row/Reference/Expression/Cast/XMLConverter.php @@ -14,9 +14,7 @@ public function toArray(\DOMDocument $document) : array $xmlArray = []; if ($document->hasChildNodes()) { - $children = $document->childNodes; - - foreach ($children as $child) { + foreach ($document->childNodes as $child) { /** @psalm-suppress ArgumentTypeCoercion */ $xmlArray[$child->nodeName] = $this->convertDOMElement($child); } @@ -30,8 +28,6 @@ public function toArray(\DOMDocument $document) : array * @psalm-suppress PossiblyNullArgument * @psalm-suppress UnnecessaryVarAnnotation * @psalm-suppress PossiblyNullIterator - * - * @return array */ private function convertDOMElement(\DOMElement|\DOMNode $element) : array { @@ -83,7 +79,7 @@ private function isElementCollection(\DOMElement|\DOMNode $element) : bool } } - if (!\count($nodeNames) || \count($nodeNames) === 1) { + if (\count($nodeNames) <= 1) { return false; } diff --git a/src/core/etl/src/Flow/ETL/Rows.php b/src/core/etl/src/Flow/ETL/Rows.php index da4cc85c8..03da3c5ff 100644 --- a/src/core/etl/src/Flow/ETL/Rows.php +++ b/src/core/etl/src/Flow/ETL/Rows.php @@ -177,31 +177,6 @@ public function entries() : array return $entries; } - public function equals(self $rows, Comparator $comparator = new NativeComparator()) : bool - { - if ($this->count() !== $rows->count()) { - return false; - } - - foreach ($this->rows as $row) { - $found = false; - - foreach ($rows->rows as $otherRow) { - if ($comparator->equals($row, $otherRow)) { - $found = true; - - break; - } - } - - if (!$found) { - return false; - } - } - - return true; - } - /** * @param callable(Row) : bool $callable */