@@ -161,18 +161,34 @@ private function inspectObject($object)
161
161
*/
162
162
private function isDuplicateNode ($ node , $ existingNode )
163
163
{
164
- // Access the 'id' properties using possible getter methods
165
- //Testing file
164
+ // Get node data excluding 'id' and 'parent' for comparison
165
+ $ nodeData = $ this ->getNodeData ($ node );
166
+ $ existingNodeData = $ this ->getNodeData ($ existingNode );
166
167
167
- $ nodeId = $ this ->getPrivateProperty ($ node , 'id ' );
168
- $ existingNodeId = $ this ->getPrivateProperty ($ existingNode , 'id ' );
168
+ // Compare the remaining parts of the nodes
169
+ return $ nodeData == $ existingNodeData ;
170
+ }
171
+
172
+ private function getNodeData ($ node )
173
+ {
174
+ $ data = [];
169
175
170
- // Access 'parent' properties if needed, depending on your logic
171
- $ nodeParent = $ this ->getPrivateProperty ($ node , 'parent ' );
172
- $ existingNodeParent = $ this ->getPrivateProperty ($ existingNode , 'parent ' );
176
+ // Use reflection to get accessible properties
177
+ $ reflection = new \ReflectionClass ($ node );
178
+ foreach ($ reflection ->getMethods () as $ method ) {
179
+ // Skip 'getId' and 'getParent' methods for comparison
180
+ if ($ method ->getName () === 'getId ' || $ method ->getName () === 'getParent ' ) {
181
+ continue ;
182
+ }
183
+
184
+ // Dynamically call the getter methods
185
+ if (strpos ($ method ->getName (), 'get ' ) === 0 ) {
186
+ $ propertyName = lcfirst (str_replace ('get ' , '' , $ method ->getName ()));
187
+ $ data [$ propertyName ] = $ method ->invoke ($ node );
188
+ }
189
+ }
173
190
174
- // Compare the nodes after ignoring 'id'
175
- return $ nodeParent == $ existingNodeParent ;
191
+ return $ data ;
176
192
}
177
193
178
194
/**
0 commit comments