This is the code to get a sitemap index check:
$sitemapSource = new SitemapXmlSource($client);
$sitemapData = $sitemapSource->fetch($sitemap);
if ($sitemapSource->isSitemapIndex()) {
echo 'This is an index file';
}
It is possible to run isSitemapIndex() without first running fetch, at which point the check would return false (the default value). We therefore either need to throw an exception or implicitly run fetch(). As running code implicitly is a little suspect and the sitemap data returned still needs to be parsed, it might be better to throw an exception.