public function detectConflicts(array $tokens = null)
{
$tokens = null === $tokens ? array_keys($this->tokens) : $tokens;
$conflicts = array();
foreach ($tokens as $token) {
// Claim was released
if (!isset($this->tokens[$token])) {
continue;
}
$moduleNames = array_keys($this->tokens[$token]);
// Token claimed by only one module
if (1 === count($moduleNames)) {
continue;
}
$sortedNames = $this->dependencyGraph->getSortedModuleNames($moduleNames);
$conflictingNames = array();
// An edge must exist between each module pair in the sorted set,
// otherwise the dependencies are not sufficiently defined
for ($i = 1, $l = count($sortedNames); $i < $l; ++$i) {
// Exclude recursive dependencies
if (!$this->dependencyGraph->hasDependency($sortedNames[$i], $sortedNames[$i - 1], false)) {
$conflictingNames[$sortedNames[$i - 1]] = true;
$conflictingNames[$sortedNames[$i]] = true;
}
}
if (count($conflictingNames) > 0) {
$conflicts[] = new ModuleConflict($token, array_keys($conflictingNames));
}
}
return $conflicts;
}