original_string: protected function _setAsRoot($entity)
      {
          $config = $this->getConfig();
          $edge = $this->_getMax();
          $this->_ensureFields($entity);
          $right = $entity->get($config['right']);
          $left = $entity->get($config['left']);
          $diff = $right - $left;
  
          if ($right - $left > 1) {
              //Correcting internal subtree
              $internalLeft = $left + 1;
              $internalRight = $right - 1;
              $this->_sync($edge - $diff - $left, '+', "BETWEEN {$internalLeft} AND {$internalRight}", true);
          }
  
          $this->_sync($diff + 1, '-', "BETWEEN {$right} AND {$edge}");
  
          if ($right - $left > 1) {
              $this->_unmarkInternalTree();
          }
  
          $entity->set($config['left'], $edge - $diff);
          $entity->set($config['right'], $edge);
      }
code: protected function _setAsRoot($entity)
      {
          $config = $this->getConfig();
          $edge = $this->_getMax();
          $this->_ensureFields($entity);
          $right = $entity->get($config['right']);
          $left = $entity->get($config['left']);
          $diff = $right - $left;
  
          if ($right - $left > 1) {
              //Correcting internal subtree
              $internalLeft = $left + 1;
              $internalRight = $right - 1;
              $this->_sync($edge - $diff - $left, '+', "BETWEEN {$internalLeft} AND {$internalRight}", true);
          }
  
          $this->_sync($diff + 1, '-', "BETWEEN {$right} AND {$edge}");
  
          if ($right - $left > 1) {
              $this->_unmarkInternalTree();
          }
  
          $entity->set($config['left'], $edge - $diff);
          $entity->set($config['right'], $edge);
      }
code_tokens: protected function _setAsRoot ( $ entity ) { $ config = $ this -> getConfig ( ) ; $ edge = $ this -> _getMax ( ) ; $ this -> _ensureFields ( $ entity ) ; $ right = $ entity -> get ( $ config [ 'right' ] ) ; $ left = $ entity -> get ( $ config [ 'left' ] ) ; $ diff = $ right - $ left ; if ( $ right - $ left > 1 ) { //Correcting internal subtree $ internalLeft = $ left + 1 ; $ internalRight = $ right - 1 ; $ this -> _sync ( $ edge - $ diff - $ left , '+' , "BETWEEN {$internalLeft} AND {$internalRight}" , true ) ; } $ this -> _sync ( $ diff + 1 , '-' , "BETWEEN {$right} AND {$edge}" ) ; if ( $ right - $ left > 1 ) { $ this -> _unmarkInternalTree ( ) ; } $ entity -> set ( $ config [ 'left' ] , $ edge - $ diff ) ; $ entity -> set ( $ config [ 'right' ] , $ edge ) ; }
docstring: Updates the left and right column for the passed entity so it can be set as
  a new root in the tree. It also modifies the ordering in the rest of the tree
  so the structure remains valid
  
  @param \Cake\Datasource\EntityInterface $entity The entity to set as a new root
  @return void
docstring_tokens: Updates the left and right column for the passed entity so it can be set as a new root in the tree . It also modifies the ordering in the rest of the tree so the structure remains valid