original_string: protected static function remove_duplicate_nodes($parent) {
          $length = count($parent->children);
          $index = 0;
          while ($index < $length) {
              $child = $parent->children[$index];
              if ($child->allow === $parent->allow) {
                  // Remove child node, but add its children to this node instead.
                  array_splice($parent->children, $index, 1);
                  $length--;
                  $index--;
                  foreach ($child->children as $grandchild) {
                      $parent->children[] = $grandchild;
                      $length++;
                  }
              } else {
                  // Keep child node, but recurse to remove its unnecessary children.
                  self::remove_duplicate_nodes($child);
              }
              $index++;
          }
      }
code: protected static function remove_duplicate_nodes($parent) {
          $length = count($parent->children);
          $index = 0;
          while ($index < $length) {
              $child = $parent->children[$index];
              if ($child->allow === $parent->allow) {
                  // Remove child node, but add its children to this node instead.
                  array_splice($parent->children, $index, 1);
                  $length--;
                  $index--;
                  foreach ($child->children as $grandchild) {
                      $parent->children[] = $grandchild;
                      $length++;
                  }
              } else {
                  // Keep child node, but recurse to remove its unnecessary children.
                  self::remove_duplicate_nodes($child);
              }
              $index++;
          }
      }
code_tokens: protected static function remove_duplicate_nodes ( $ parent ) { $ length = count ( $ parent -> children ) ; $ index = 0 ; while ( $ index < $ length ) { $ child = $ parent -> children [ $ index ] ; if ( $ child -> allow === $ parent -> allow ) { // Remove child node, but add its children to this node instead. array_splice ( $ parent -> children , $ index , 1 ) ; $ length -- ; $ index -- ; foreach ( $ child -> children as $ grandchild ) { $ parent -> children [ ] = $ grandchild ; $ length ++ ; } } else { // Keep child node, but recurse to remove its unnecessary children. self :: remove_duplicate_nodes ( $ child ) ; } $ index ++ ; } }
docstring: Removes duplicate nodes of a tree - where a child node has the same permission as its
  parent.
  
  @param \stdClass $parent Tree root node
docstring_tokens: Removes duplicate nodes of a tree - where a child node has the same permission as its parent .