xml-to-array icon indicating copy to clipboard operation
xml-to-array copied to clipboard

Fixed issue with duplicate checker by using `array_count_values()` to determine if a node has the same name

Open Sammyjo20 opened this issue 4 years ago • 2 comments

Hi @vyuldashev 👋

Thank you for this great little package, it's helped me massively with a project we've had to built quickly. I ran into a small issue however which was with some of the XML I was processing. One section of the XML had the following child nodes:

<Products>
<Products>
<ProductCount>

I found an issue where the sameName variable wouldn't be true because of the last <ProductCount> child node causing the isHomogenous method to return false.

I have solved this issue by using array_count_values which will count up all of the occurrences of each of the duplicated nodes, and when it checks to see if a node already exists, we check the $sameNamesOccurrences array for duplicates.

All tests are passing fine and it seems to work for my solution too. I hope you get a chance to review and potentially accept this PR! 🤓

Have a great day. ☀️

Sammyjo20 avatar May 09 '21 15:05 Sammyjo20

Ah, I just figured out another potential bug with the keys. For example if you have two different nodes that both have child nodes, the keys aren't reset so you get the following:

Screen Shot 2021-05-09 at 17 09 56

Sammyjo20 avatar May 09 '21 16:05 Sammyjo20

With the latest commit:

Screen Shot 2021-05-09 at 17 15 31

Sammyjo20 avatar May 09 '21 16:05 Sammyjo20