code: public function getNonEmptySibling($index, $direction)
      {
          while (true) {
              $index += $direction;
  
              if (!$this->offsetExists($index)) {
                  return null;
              }
  
              if (!$this->isEmptyAt($index)) {
                  return $index;
              }
          }
      }
docs: Get index for closest sibling token which is not empty.
  
  @param int $index     token index
  @param int $direction direction for looking, +1 or -1
  
  @return null|int