Files
fewo-stommer/app/Process/Modules/Guest/AddressCheck.php
T

72 lines
2.5 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
namespace App\Process\Modules\Guest;
use App\Enums\ActivityState;
use App\Process\Activity;
use App\Process\CaseContext;
use App\Process\Modules\Dependency;
use App\Process\Modules\Module;
use App\Process\Modules\ModuleDefinition;
use App\Process\Modules\StepState;
/**
* V2.1 case H (docs/Prozessarchitektur/V2.1/ABNAHME_V2_1.md): an optional plausibility check of the guest's address, added
* at the extension point „after the guest is identified“ without touching any other model. It only informs – the result
* never holds back an offer or a booking (the address gate of v0.11 stays the only rule). Tester only until released.
*/
final class AddressCheck extends Module
{
public static function key(): string
{
return 'guest.address_check';
}
public static function definition(): ModuleDefinition
{
return new ModuleDefinition(
label: 'Anschrift auf Plausibilität prüfen',
purpose: 'Prüft, ob die Anschrift des Gastes plausibel aussieht (Postleitzahl, Ort). Es ist ein Hinweis; nichts wird dadurch aufgehalten.',
phase: 'P01',
requires: [Dependency::hard('guest.details')],
triggers: ['facts.applied'],
toggle: ModuleDefinition::TOGGLE_OPTIONAL,
events: ['facts'],
points: ['after_guest_identified'],
availability: ModuleDefinition::AVAILABILITY_TESTER_ONLY,
);
}
/**
* @return list<string> what looks implausible (empty: plausible)
*/
public function findings(CaseContext $case): array
{
$guest = $case->booking->guest;
$findings = [];
if (blank($guest?->street)) {
$findings[] = 'Straße fehlt';
}
if (blank($guest?->city)) {
$findings[] = 'Ort fehlt';
}
if (in_array(mb_strtoupper((string) $guest?->country), ['', 'DE', 'DEUTSCHLAND'], true) && ! preg_match('/^\d{5}$/', trim((string) $guest?->postal_code))) {
$findings[] = 'Postleitzahl hat nicht fünf Ziffern';
}
return $findings;
}
public function activities(CaseContext $case): array
{
$findings = $this->findings($case);
return [new Activity('address_check', 'Anschrift auf Plausibilität prüfen', ActivityState::Done, $findings === [] ? 'Anschrift wirkt plausibel' : 'Hinweis: '.implode(', ', $findings))];
}
public function state(CaseContext $case): ?StepState
{
return StepState::Done;
}
}