63 lines
3.7 KiB
PHP
63 lines
3.7 KiB
PHP
<?php
|
||
|
||
namespace App\Console\Commands;
|
||
|
||
use App\Models\Channel;
|
||
use App\Process\Modules\ContributesToPrice;
|
||
use App\Process\Modules\RunsAutomatically;
|
||
use App\Process\ProcessCatalogue;
|
||
use Illuminate\Console\Attributes\Description;
|
||
use Illuminate\Console\Attributes\Signature;
|
||
use Illuminate\Console\Command;
|
||
|
||
/**
|
||
* Change impact of a module (docs/Prozessarchitektur/Architektur/05 §2): models and variants with their case types,
|
||
* extension points, dependent modules, parameters, whether it reads frozen contract data, the number of channels that
|
||
* chose an affected model (count only) and the test groups to run.
|
||
*/
|
||
#[Signature('process:impact {module : key of the module, e.g. offer.binding}')]
|
||
#[Description('Show which models, case types, dependent modules, channels and test groups a change of a process module affects')]
|
||
class ProcessImpact extends Command
|
||
{
|
||
public function handle(ProcessCatalogue $catalogue): int
|
||
{
|
||
$key = (string) $this->argument('module');
|
||
if (! $catalogue->hasModule($key)) {
|
||
$this->error("Unbekanntes Modul {$key}. Registriert: ".implode(', ', array_keys($catalogue->modules())));
|
||
|
||
return self::FAILURE;
|
||
}
|
||
|
||
$class = $catalogue->modules()[$key];
|
||
$definition = $class::definition();
|
||
$uses = [];
|
||
foreach ($catalogue->models() as $modelKey => $model) {
|
||
foreach ($model->variants() as $variant) {
|
||
if (in_array($key, $model->modules($variant->key), true)) {
|
||
$uses[] = $modelKey.($variant->key === 'standard' ? '' : ':'.$variant->key).' ('.implode('/', array_map(fn ($type): string => strtoupper($type->value), $model::caseTypes())).')';
|
||
}
|
||
}
|
||
}
|
||
$dependents = array_keys(array_filter($catalogue->modules(), fn (string $other): bool => collect($other::definition()->requires)->contains(fn ($dependency): bool => $dependency->module === $key)));
|
||
$modelKeys = array_map(fn (string $use): string => explode(' ', explode(':', $use)[0])[0], $uses);
|
||
$channels = Channel::withoutGlobalScopes()->get(['process_overrides'])->filter(fn (Channel $channel): bool => collect((array) $channel->process_overrides)->contains(fn ($config): bool => in_array($config['model'] ?? null, $modelKeys, true)))->count();
|
||
|
||
$this->table(['', $key.' v'.$class::version()], [
|
||
['Aufgabe', $definition->purpose],
|
||
['Phase / Aktivierung', $definition->phase.' / '.$definition->toggle.' / '.$definition->availability],
|
||
['Modelle', implode(', ', $uses) ?: '–'],
|
||
['Erweiterungspunkte', implode(', ', $definition->points) ?: 'fester Platz im Modell'],
|
||
['Benötigt', implode(', ', array_map(fn ($dependency): string => $dependency->module.($dependency->hard ? ' (hart)' : ' (weich)'), $definition->requires)) ?: '–'],
|
||
['Benötigt von', implode(', ', $dependents) ?: '–'],
|
||
['Läuft automatisch', is_subclass_of($class, RunsAutomatically::class) ? 'ja, Auslöser: '.implode(', ', $definition->triggers) : 'nein'],
|
||
['Preisbeitrag', is_subclass_of($class, ContributesToPrice::class) ? 'ja (CasePricing, nur vor Verbindlichkeit)' : 'nein'],
|
||
['Wertet Vertragsdaten aus', $definition->readsContractData ? 'ja – Bestandsfall-Test Pflicht (--group=ongoing)' : 'nein'],
|
||
['Parameter', implode(', ', array_map(fn ($parameter): string => is_string($parameter) ? $parameter : $parameter->value, $definition->parameters)) ?: '–'],
|
||
['Kanäle mit gewähltem Modell', (string) $channels],
|
||
['Tests', "--group=module:{$key} --group=golden --group=ongoing --group=runner"],
|
||
]);
|
||
|
||
return self::SUCCESS;
|
||
}
|
||
}
|