Skip to content

Commit

Permalink
adjustments after code review
Browse files Browse the repository at this point in the history
  • Loading branch information
norberttech committed Sep 6, 2023
1 parent ea40e29 commit a4d6ed8
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
);
}

Expand Down Expand Up @@ -67,13 +66,11 @@ public function test_reading_xml_from_path() : void
</items>

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()
);
}
}
3 changes: 1 addition & 2 deletions src/core/etl/src/Flow/ETL/Row/Reference/Expression/Cast.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -30,8 +28,6 @@ public function toArray(\DOMDocument $document) : array
* @psalm-suppress PossiblyNullArgument
* @psalm-suppress UnnecessaryVarAnnotation
* @psalm-suppress PossiblyNullIterator
*
* @return array<mixed>
*/
private function convertDOMElement(\DOMElement|\DOMNode $element) : array
{
Expand Down Expand Up @@ -83,7 +79,7 @@ private function isElementCollection(\DOMElement|\DOMNode $element) : bool
}
}

if (!\count($nodeNames) || \count($nodeNames) === 1) {
if (\count($nodeNames) <= 1) {
return false;
}

Expand Down
25 changes: 0 additions & 25 deletions src/core/etl/src/Flow/ETL/Rows.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down

0 comments on commit a4d6ed8

Please sign in to comment.