Puli\Manager\Conflict\ModuleConflictDetector::detectConflicts PHP Method

detectConflicts() public method

If no tokens are passed, all tokens are checked. A conflict is returned for every token that is claimed by two modules that are not connected by an edge in the override graph. In other words, if two modules A and B claim the same token, an edge must exist from A to B (A is overridden by B) or from B to A (B is overridden by A). Otherwise a conflict is returned.
public detectConflicts ( array $tokens = null ) : Puli\Manager\Conflict\ModuleConflict[]
$tokens array The tokens to check. If `null`, all claimed tokens are checked for conflicts. You are advised to pass tokens if possible to improve the performance of the conflict detection.
return Puli\Manager\Conflict\ModuleConflict[] The detected conflicts.
    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;
    }

Usage Example

Ejemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function execute()
 {
     if (!$this->repositoryPaths) {
         // Check all paths if none are passed
         $this->repositoryPaths = $this->conflicts->getRepositoryPaths();
     }
     // Mark all as resolved
     foreach ($this->repositoryPaths as $repositoryPath) {
         if ($this->conflicts->has($repositoryPath)) {
             $conflict = $this->conflicts->get($repositoryPath);
             $this->conflicts->remove($repositoryPath);
             $this->removedConflicts[$repositoryPath] = $conflict->getMappings();
             $conflict->resolve();
         }
     }
     $moduleConflicts = $this->conflictDetector->detectConflicts($this->repositoryPaths);
     $this->deduplicateModuleConflicts($moduleConflicts);
     foreach ($moduleConflicts as $moduleConflict) {
         $repositoryPath = $moduleConflict->getConflictingToken();
         $conflict = new PathConflict($repositoryPath);
         foreach ($moduleConflict->getModuleNames() as $moduleName) {
             $conflict->addMapping($this->mappingsByResource->get($repositoryPath, $moduleName));
         }
         $this->conflicts->add($conflict);
         $this->addedConflicts[] = $repositoryPath;
     }
 }