Files
crewli/api/database/factories/PersonIdentityMatchFactory.php
bert.hausmans eb1a0ac666 feat: complete person identity matching system with fuzzy detection, revert, and manual link
Implements the full identity matching engine: email matching (HIGH confidence),
fuzzy name matching with Levenshtein distance (MEDIUM confidence, upgradable to
HIGH with DOB tiebreaker), manual link/unlink, revert confirmed matches, and
automatic detection via PersonObserver. Includes 33 comprehensive tests, frontend
integration with confirm/dismiss/unlink UI, and match indicators in the persons list.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-14 08:44:24 +02:00

78 lines
2.3 KiB
PHP

<?php
declare(strict_types=1);
namespace Database\Factories;
use App\Enums\IdentityMatchConfidence;
use App\Enums\IdentityMatchMethod;
use App\Enums\IdentityMatchStatus;
use App\Models\Person;
use App\Models\PersonIdentityMatch;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;
/** @extends Factory<PersonIdentityMatch> */
final class PersonIdentityMatchFactory extends Factory
{
protected $model = PersonIdentityMatch::class;
/** @return array<string, mixed> */
public function definition(): array
{
return [
'person_id' => Person::factory(),
'matched_user_id' => User::factory(),
'matched_on' => IdentityMatchMethod::EMAIL,
'confidence' => IdentityMatchConfidence::HIGH,
'status' => IdentityMatchStatus::PENDING,
'match_details' => null,
'resolved_by_user_id' => null,
'resolved_at' => null,
];
}
public function confirmed(): static
{
return $this->state(fn () => [
'status' => IdentityMatchStatus::CONFIRMED,
'confirmed_by_user_id' => User::factory(),
'confirmed_at' => now(),
'resolved_by_user_id' => User::factory(),
'resolved_at' => now(),
]);
}
public function dismissed(): static
{
return $this->state(fn () => [
'status' => IdentityMatchStatus::DISMISSED,
'dismissed_by_user_id' => User::factory(),
'dismissed_at' => now(),
'resolved_by_user_id' => User::factory(),
'resolved_at' => now(),
]);
}
public function fuzzyName(): static
{
return $this->state(fn () => [
'matched_on' => IdentityMatchMethod::NAME_FUZZY,
'confidence' => IdentityMatchConfidence::MEDIUM,
]);
}
public function manual(): static
{
return $this->state(fn () => [
'matched_on' => IdentityMatchMethod::MANUAL,
'confidence' => IdentityMatchConfidence::HIGH,
'status' => IdentityMatchStatus::CONFIRMED,
'confirmed_by_user_id' => User::factory(),
'confirmed_at' => now(),
'resolved_by_user_id' => User::factory(),
'resolved_at' => now(),
]);
}
}