Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TASK] Streamline logging #115

Merged
merged 1 commit into from
Oct 20, 2023
Merged
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
23 changes: 19 additions & 4 deletions src/Visitor/CommonVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ protected function processChildren(?DOMNode $domNode, Behavior\Tag $tag): ?DOMNo
) {
$this->log('Found unexpected children for {nodeName}', [
'behavior' => $this->behavior->getName(),
'nodeType' => $domNode->nodeType,
'nodeName' => $domNode->nodeName,
]);
// reverse processing of children,
Expand All @@ -183,6 +184,7 @@ protected function processAttribute(DOMElement $domNode, Behavior\Tag $tag, DOMA
if ($attr === null || !$attr->matchesValue($attribute->value)) {
$this->log('Found invalid attribute {nodeName}.{attrName}', [
'behavior' => $this->behavior->getName(),
'nodeType' => $domNode->nodeType,
'nodeName' => $domNode->nodeName,
'attrName' => $attribute->nodeName,
]);
Expand All @@ -199,6 +201,7 @@ protected function handleMandatoryAttributes(?DOMNode $domNode, Behavior\Tag $ta
if ($attr->isMandatory() && !$domNode->hasAttribute($attr->getName())) {
$this->log('Missing mandatory attribute {nodeName}.{attrName}', [
'behavior' => $this->behavior->getName(),
'nodeType' => $domNode->nodeType,
'nodeName' => $domNode->nodeName,
'attrName' => $attr->getName(),
]);
Expand All @@ -210,29 +213,41 @@ protected function handleMandatoryAttributes(?DOMNode $domNode, Behavior\Tag $ta

protected function handleInvalidNode(DOMNode $domNode): ?DOMNode
{
if ($domNode instanceof DOMComment && $this->behavior->shallEncodeInvalidComment()) {
return $this->convertToText($domNode);
}
if ($domNode instanceof DOMCdataSection && $this->behavior->shallEncodeInvalidCdataSection()) {
if (
($domNode instanceof DOMComment && $this->behavior->shallEncodeInvalidComment())
|| ($domNode instanceof DOMCdataSection && $this->behavior->shallEncodeInvalidCdataSection())
) {
$this->log('Found unexpected node {nodeName}', [
'behavior' => $this->behavior->getName(),
'nodeType' => $domNode->nodeType,
'nodeName' => $domNode->nodeName,
]);
return $this->convertToText($domNode);
}
if ($domNode instanceof DOMElement) {
// pass custom elements, in case it has been declared
if ($this->behavior->shallAllowCustomElements() && $this->isCustomElement($domNode)) {
$this->log('Allowed custom element {nodeName}', [
'behavior' => $this->behavior->getName(),
'nodeType' => $domNode->nodeType,
'nodeName' => $domNode->nodeName,
]);
return $domNode;
}
$this->log('Found unexpected tag {nodeName}', [
'behavior' => $this->behavior->getName(),
'nodeType' => $domNode->nodeType,
'nodeName' => $domNode->nodeName,
]);
if ($this->behavior->shallEncodeInvalidTag()) {
return $this->convertToText($domNode);
}
}
$this->log('Removed unexpected node {nodeName}', [
'behavior' => $this->behavior->getName(),
'nodeType' => $domNode->nodeType,
'nodeName' => $domNode->nodeName,
]);
return null;
}

Expand Down