private function determineSnipLocation(array $locations, $prevCount)
{
// If we only have 1 match we don't actually do the for loop so set to the first
$startPos = (int) reset($locations);
$loccount = count($locations);
$smallestDiff = PHP_INT_MAX;
// If we only have 2, skip as it's probably equally relevant
if (count($locations) > 2) {
// skip the first as we check 1 behind
for ($i = 1; $i < $loccount; $i++) {
if ($i === $loccount - 1) {
// at the end
$diff = $locations[$i] - $locations[$i - 1];
} else {
$diff = $locations[$i + 1] - $locations[$i];
}
if ($smallestDiff > $diff) {
$smallestDiff = $diff;
$startPos = $locations[$i];
}
}
}
$startPos = $startPos > $prevCount ? $startPos - $prevCount : 0;
return $startPos;
}