Add PHP typehints for $this and $_category
Refactored phpdoc blocks a little
Use $category->getId() instead of $category->getID()
Replace deprecated htmlEscape with escapeHtml
Initialize $childrenCount variable so the IDE doesn't complain :)
Refactored _isCurrentCategory for better readability
Refactored toLinearArray for speed to not iterate over all items in the array/collection