original_string: public function order_bit(string $id, int $pos): ?bool
    {
      if ( 
        \bbn\str::is_uid($id) &&
        ($cf = $this->get_class_cfg()) &&
        ($cfg = $cf['arch']['user_options_bits']) &&
        ($bit = $this->get_bit($id)) &&
        ($old = (int)$bit[$cfg['num']]) &&
        !empty($pos) &&
        ($old !== $pos) &&
        ($bits = $this->get_bits($bit[$cfg['id_user_option']], $bit[$cfg['id_parent']] ?: false))
      ){    
        $past_new = false;
        $past_old = false;
        $p = 1;
        $changed = 0;
        foreach ( $bits as $ele ){
          $upd = [];
          if ( $past_old && !$past_new ){
            $upd[$cfg['num']] = $p-1;
          }
          else if ( !$past_old && $past_new ){
            $upd[$cfg['num']] = $p+1;
          }
          if ( $id === $ele['id'] ){
            $upd[$cfg['num']] = $pos;
            $past_old = 1;
          }
          else if ( $p === $pos ){
            $upd[$cfg['num']] = $p + ($pos > $old ? -1 : 1);
            $past_new = 1;
          }
          if ( !empty($upd) ){
            $changed += $this->db->update($cf['tables']['user_options_bits'], $upd, [$cfg['id'] => $ele['id']]);
          }
          if ( $past_new && $past_old ){
            break;
          }
          $p++;
        }
        return !!$changed;
      }
      return null;
    }
code: public function order_bit(string $id, int $pos): ?bool
    {
      if ( 
        \bbn\str::is_uid($id) &&
        ($cf = $this->get_class_cfg()) &&
        ($cfg = $cf['arch']['user_options_bits']) &&
        ($bit = $this->get_bit($id)) &&
        ($old = (int)$bit[$cfg['num']]) &&
        !empty($pos) &&
        ($old !== $pos) &&
        ($bits = $this->get_bits($bit[$cfg['id_user_option']], $bit[$cfg['id_parent']] ?: false))
      ){    
        $past_new = false;
        $past_old = false;
        $p = 1;
        $changed = 0;
        foreach ( $bits as $ele ){
          $upd = [];
          if ( $past_old && !$past_new ){
            $upd[$cfg['num']] = $p-1;
          }
          else if ( !$past_old && $past_new ){
            $upd[$cfg['num']] = $p+1;
          }
          if ( $id === $ele['id'] ){
            $upd[$cfg['num']] = $pos;
            $past_old = 1;
          }
          else if ( $p === $pos ){
            $upd[$cfg['num']] = $p + ($pos > $old ? -1 : 1);
            $past_new = 1;
          }
          if ( !empty($upd) ){
            $changed += $this->db->update($cf['tables']['user_options_bits'], $upd, [$cfg['id'] => $ele['id']]);
          }
          if ( $past_new && $past_old ){
            break;
          }
          $p++;
        }
        return !!$changed;
      }
      return null;
    }
code_tokens: public function order_bit ( string $ id , int $ pos ) : ? bool { if ( \ bbn \ str :: is_uid ( $ id ) && ( $ cf = $ this -> get_class_cfg ( ) ) && ( $ cfg = $ cf [ 'arch' ] [ 'user_options_bits' ] ) && ( $ bit = $ this -> get_bit ( $ id ) ) && ( $ old = ( int ) $ bit [ $ cfg [ 'num' ] ] ) && ! empty ( $ pos ) && ( $ old !== $ pos ) && ( $ bits = $ this -> get_bits ( $ bit [ $ cfg [ 'id_user_option' ] ] , $ bit [ $ cfg [ 'id_parent' ] ] ? : false ) ) ) { $ past_new = false ; $ past_old = false ; $ p = 1 ; $ changed = 0 ; foreach ( $ bits as $ ele ) { $ upd = [ ] ; if ( $ past_old && ! $ past_new ) { $ upd [ $ cfg [ 'num' ] ] = $ p - 1 ; } else if ( ! $ past_old && $ past_new ) { $ upd [ $ cfg [ 'num' ] ] = $ p + 1 ; } if ( $ id === $ ele [ 'id' ] ) { $ upd [ $ cfg [ 'num' ] ] = $ pos ; $ past_old = 1 ; } else if ( $ p === $ pos ) { $ upd [ $ cfg [ 'num' ] ] = $ p + ( $ pos > $ old ? - 1 : 1 ) ; $ past_new = 1 ; } if ( ! empty ( $ upd ) ) { $ changed += $ this -> db -> update ( $ cf [ 'tables' ] [ 'user_options_bits' ] , $ upd , [ $ cfg [ 'id' ] => $ ele [ 'id' ] ] ) ; } if ( $ past_new && $ past_old ) { break ; } $ p ++ ; } return ! ! $ changed ; } return null ; }
docstring: Orders a bit.
  
  @param string $id The bit's ID
  @param int $pos The new position
  @return bool|null
docstring_tokens: Orders a bit .