Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
damijanc committed Apr 10, 2024
1 parent 2d0ed3d commit 5d49b07
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 89 deletions.
147 changes: 74 additions & 73 deletions src/XmlDOM.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,79 +16,6 @@
*/
class XmlDOM extends DOMDocument
{
private function isValidClass(mixed $x): bool
{
// not an object, not an instance
if (!is_object($x)) {
return false;
}

return ($x = get_class($x)) && $x !== 'stdClass';
}

/**
* @param array $propertyAttributes
* @param DOMElement|null $parentElement
* @return void
*/
public function handleClassAttributes(array $propertyAttributes, ?DOMElement $parentElement): void
{
if (count($propertyAttributes) === 0) {
return;
}

$this->handlePropertyAttribute($propertyAttributes[0]->newInstance(), $parentElement);
}

/**
* @param array $propertyAttributes
* @param DOMElement|null $parentElement
* @return void
*/
public function handlePropertyAttributes(array $propertyAttributes, ?DOMElement $parentElement, $value): void
{
if (count($propertyAttributes) === 0) {
return;
}

$propertyAttribute = $propertyAttributes[0]->newInstance();
$this->appendAttribute([$propertyAttribute->key => $value], $parentElement);
}

/**
* @param array $commentAttributes
* @param DOMElement|null $parentElement
* @return void
*/
public function handleCommentAttributes(array $commentAttributes, ?DOMElement $parentElement): void
{
if (count($commentAttributes) === 0) {
return;
}

$commentAttribute = $commentAttributes[0]->newInstance();
$this->appendComment($commentAttribute->comment, $parentElement);

}

private function handleNodeAttributes(array $nodeAttributes, ?DOMElement &$parentElement, DOMElement &$domElement = null): void
{
if (count($nodeAttributes) === 0) {
return;
}

$this->handleNodeAttribute($nodeAttributes[0]->newInstance(), $parentElement, $domElement);
}

private function handlePropertyAttribute(Property $propertyAttribute, ?DOMElement $parentElement): void
{
$this->appendAttribute([$propertyAttribute->key => $propertyAttribute->value], $parentElement);
}

private function handleNodeAttribute(Node $nodeAttribute, ?DOMElement &$parentNode, DOMElement &$currentNode = null): void
{
$this->makeElement($nodeAttribute->name, $parentNode, $currentNode);
}

public function buildDOM(object $mixed, DOMElement &$parentElement = null): void
{
Expand Down Expand Up @@ -160,6 +87,80 @@ public function buildDOM(object $mixed, DOMElement &$parentElement = null): void
}
}

private function isValidClass(mixed $x): bool
{
// not an object, not an instance
if (!is_object($x)) {
return false;
}

return ($x = get_class($x)) && $x !== 'stdClass';
}

/**
* @param array $propertyAttributes
* @param DOMElement|null $parentElement
* @return void
*/
private function handleClassAttributes(array $propertyAttributes, ?DOMElement $parentElement): void
{
if (count($propertyAttributes) === 0) {
return;
}

$this->handlePropertyAttribute($propertyAttributes[0]->newInstance(), $parentElement);
}

/**
* @param array $propertyAttributes
* @param DOMElement|null $parentElement
* @return void
*/
private function handlePropertyAttributes(array $propertyAttributes, ?DOMElement $parentElement, $value): void
{
if (count($propertyAttributes) === 0) {
return;
}

$propertyAttribute = $propertyAttributes[0]->newInstance();
$this->appendAttribute([$propertyAttribute->key => $value], $parentElement);
}

/**
* @param array $commentAttributes
* @param DOMElement|null $parentElement
* @return void
*/
private function handleCommentAttributes(array $commentAttributes, ?DOMElement $parentElement): void
{
if (count($commentAttributes) === 0) {
return;
}

$commentAttribute = $commentAttributes[0]->newInstance();
$this->appendComment($commentAttribute->comment, $parentElement);

}

private function handleNodeAttributes(array $nodeAttributes, ?DOMElement &$parentElement, DOMElement &$domElement = null): void
{
if (count($nodeAttributes) === 0) {
return;
}

$this->handleNodeAttribute($nodeAttributes[0]->newInstance(), $parentElement, $domElement);
}

private function handlePropertyAttribute(Property $propertyAttribute, ?DOMElement $parentElement): void
{
$this->appendAttribute([$propertyAttribute->key => $propertyAttribute->value], $parentElement);
}

private function handleNodeAttribute(Node $nodeAttribute, ?DOMElement &$parentNode, DOMElement &$currentNode = null): void
{
$this->makeElement($nodeAttribute->name, $parentNode, $currentNode);
}

private function makeElement(string $nodeName, &$parentNode, &$currentNode)
{
if (is_null($currentNode)) { //if we have a node we do nothing
Expand Down
16 changes: 0 additions & 16 deletions tests/fixtures/1968_69_Bayern_Munich.csv

This file was deleted.

0 comments on commit 5d49b07

Please sign in to comment.