$draft * @return list, relaxed: list, remains: list, alternatives: list, suggestion: string}> */ public function of(Channel $channel, IntakeKind $intake, array $draft): array { $rows = collect($this->configuration->preview($channel, $intake, $draft)); $active = $rows->where('on', true)->pluck('module')->all(); $labels = $rows->mapWithKeys(fn (array $row): array => [$row['module'] => $row['label']])->all(); $impacts = []; foreach ($rows as $row) { $definition = $this->catalogue->modules()[$row['module']]::definition(); if (($draft['steps'][$row['module']]['on'] ?? true) !== false) { continue; } $affected = $relaxed = []; foreach ($active as $other) { foreach ($this->catalogue->modules()[$other]::definition()->requires as $dependency) { if ($dependency->module !== $row['module']) { continue; } if ($dependency->hard) { $affected[] = $labels[$other]; } else { $relaxed[] = $labels[$other]; } } } $alternatives = array_values(array_map(fn (Execution $execution): string => $execution->getLabel(), array_filter($definition->executions, fn (Execution $execution): bool => $execution !== Execution::NotRequired))); $valid = $definition->isOptional(); $impacts[] = [ 'module' => $row['module'], 'label' => $row['label'], 'valid' => $valid, 'affected' => array_values(array_unique($affected)), 'relaxed' => array_values(array_unique($relaxed)), 'remains' => $this->remains($definition, $affected, $labels), 'alternatives' => $alternatives, 'suggestion' => $this->suggestion($row['label'], $definition, $valid, $alternatives), ]; } return $impacts; } /** * The results that stay necessary although the step is off: what the steps depending on it still need. * * @param list $affected * @param array $labels * @return list */ private function remains(ModuleDefinition $definition, array $affected, array $labels): array { $remains = []; if ($affected !== []) { $remains[] = 'Weiterhin nötig, damit „'.implode('“, „', array_unique($affected)).'“ laufen kann: '.lcfirst($definition->purpose); } if ($definition->why !== null) { $remains[] = $definition->why; } return $remains; } /** * @param list $alternatives */ private function suggestion(string $label, ModuleDefinition $definition, bool $valid, array $alternatives): string { if (! $valid) { return '„'.$label.'“ ist Pflicht und kann nicht abgeschaltet werden.'.($alternatives !== [] ? ' Zulässig sind stattdessen: '.implode('; ', $alternatives).'.' : ''); } return $alternatives === [] ? '„'.$label.'“ entfällt ersatzlos; es ist nichts weiter einzustellen.' : 'Statt abzuschalten, können Sie „'.$label.'“ auch so erledigen lassen: '.implode('; ', $alternatives).'. Es wird nichts anderes automatisch geändert.'; } }