File tree 1 file changed +31
-3
lines changed
1 file changed +31
-3
lines changed Original file line number Diff line number Diff line change @@ -57,7 +57,7 @@ public function export(NodeInterface $node): string
57
57
*/
58
58
private function doExportAsArray (NodeInterface $ node ): array
59
59
{
60
- if (!($ node instanceof ValueNodeInterface )) {
60
+ if (!$ this -> isValidNode ($ node )) {
61
61
throw new \InvalidArgumentException ('Must implements ValueNodeInterface ' );
62
62
}
63
63
@@ -68,7 +68,35 @@ private function doExportAsArray(NodeInterface $node): array
68
68
}
69
69
70
70
return [] === $ children ?
71
- [$ node ->getValue ()] :
72
- [$ node ->getValue (), $ children ];
71
+ [$ this ->getNodeRepresentation ($ node )] :
72
+ [$ this ->getNodeRepresentation ($ node ), $ children ];
73
+ }
74
+
75
+ /**
76
+ * Check if a node is valid for being exported.
77
+ *
78
+ * @param \drupol\phptree\Node\NodeInterface $node
79
+ * The node.
80
+ *
81
+ * @return bool
82
+ * True if it's valid, false otherwise.
83
+ */
84
+ protected function isValidNode (NodeInterface $ node ): bool
85
+ {
86
+ return $ node instanceof ValueNodeInterface;
87
+ }
88
+
89
+ /**
90
+ * Get a string representation of the node.
91
+ *
92
+ * @param \drupol\phptree\Node\NodeInterface $node
93
+ * The node.
94
+ *
95
+ * @return string
96
+ * The node representation.
97
+ */
98
+ protected function getNodeRepresentation (NodeInterface $ node ): string
99
+ {
100
+ return $ node ->getValue ();
73
101
}
74
102
}
You can’t perform that action at this time.
0 commit comments