public function getIterator()
{
$childrenExceptions = new SplObjectStorage();
$recursiveIteratorIterator = $this->getRecursiveIterator();
$exceptionIterator = $recursiveIteratorIterator->getInnerIterator();
$lastDepth = 0;
$lastDepthOriginal = 0;
$knownDepths = [];
foreach ($recursiveIteratorIterator as $childException) {
if ($childException instanceof self && $childException->getRelated()->count() > 0 && $childException->getRelated()->count() < 2) {
continue;
}
$currentDepth = $lastDepth;
$currentDepthOriginal = $recursiveIteratorIterator->getDepth() + 1;
if (isset($knownDepths[$currentDepthOriginal])) {
$currentDepth = $knownDepths[$currentDepthOriginal];
} elseif ($currentDepthOriginal > $lastDepthOriginal && ($this->hasCustomTemplate() || $exceptionIterator->count() != 1)) {
++$currentDepth;
}
if (!isset($knownDepths[$currentDepthOriginal])) {
$knownDepths[$currentDepthOriginal] = $currentDepth;
}
$lastDepth = $currentDepth;
$lastDepthOriginal = $currentDepthOriginal;
$childrenExceptions->attach($childException, ['depth' => $currentDepth, 'depth_original' => $currentDepthOriginal, 'previous_depth' => $lastDepth, 'previous_depth_original' => $lastDepthOriginal]);
}
return $childrenExceptions;
}