code: public function getNextVersion(array $versions)
      {
          if (isset(end($versions)->number)) {
              return (int) end($versions)->number + 1;
          }
  
          throw new LocalizedException(__('Error fetching next version.'));
      }
docs: Fetch next version
  
  @param array $versions
  @return int
  @throws LocalizedException