$reference) { $map[] = '"' . $alias . '" => "' . $reference . '"'; } return "[\n" . implode("\n", $map) . "\n]"; } /** * @param string[][] $detectedCycles * * @return string */ private static function printCycles(array $detectedCycles) { return "[\n" . implode("\n", array_map([__CLASS__, 'printCycle'], $detectedCycles)) . "\n]"; } /** * @param string[] $detectedCycle * * @return string */ private static function printCycle(array $detectedCycle) { $fullCycle = array_keys($detectedCycle); $fullCycle[] = reset($fullCycle); return implode( ' => ', array_map( function ($cycle) { return '"' . $cycle . '"'; }, $fullCycle ) ); } /** * @param bool[][] $detectedCycles * * @return bool[][] de-duplicated */ private static function deDuplicateDetectedCycles(array $detectedCycles) { $detectedCyclesByHash = []; foreach ($detectedCycles as $detectedCycle) { $cycleAliases = array_keys($detectedCycle); sort($cycleAliases); $hash = serialize(array_values($cycleAliases)); $detectedCyclesByHash[$hash] = isset($detectedCyclesByHash[$hash]) ? $detectedCyclesByHash[$hash] : $detectedCycle; } return array_values($detectedCyclesByHash); } }