Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 18
0.00% covered (danger)
0.00%
0 / 9
CRAP
0.00% covered (danger)
0.00%
0 / 1
MatchResult
0.00% covered (danger)
0.00%
0 / 18
0.00% covered (danger)
0.00%
0 / 9
110
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
2
 wasMatched
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getUser
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getUserId
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
6
 getMatchType
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getConfidence
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getReason
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 isHighConfidence
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 toArray
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2/**
3 * Match Result Value Object
4 *
5 * Represents the result of a user matching operation.
6 * Used by UserMatcher to return matching outcomes.
7 *
8 * @package BuyerKiosk\Auth\Services
9 */
10
11namespace BuyerKiosk\Auth\Services;
12
13/**
14 * Result of a user matching operation
15 */
16class MatchResult
17{
18    /**
19     * @var array|null Matched user data
20     */
21    private $user;
22
23    /**
24     * @var string Match type: 'external_id', 'email', 'name', 'phone', 'none'
25     */
26    private $matchType;
27
28    /**
29     * @var int Confidence score 0-100
30     */
31    private $confidence;
32
33    /**
34     * @var string Human-readable reason
35     */
36    private $reason;
37
38    /**
39     * Constructor
40     *
41     * @param array|null $user Matched user data
42     * @param string $matchType Type of match
43     * @param int $confidence Confidence score
44     * @param string $reason Match reason
45     */
46    public function __construct(?array $user, string $matchType, int $confidence, string $reason)
47    {
48        $this->user = $user;
49        $this->matchType = $matchType;
50        $this->confidence = $confidence;
51        $this->reason = $reason;
52    }
53
54    /**
55     * Whether a match was found
56     *
57     * @return bool
58     */
59    public function wasMatched(): bool
60    {
61        return $this->user !== null;
62    }
63
64    /**
65     * Get matched user data
66     *
67     * @return array|null
68     */
69    public function getUser(): ?array
70    {
71        return $this->user;
72    }
73
74    /**
75     * Get user ID if matched
76     *
77     * @return int|null
78     */
79    public function getUserId(): ?int
80    {
81        return $this->user ? (int)$this->user['id'] : null;
82    }
83
84    /**
85     * Get match type
86     *
87     * @return string
88     */
89    public function getMatchType(): string
90    {
91        return $this->matchType;
92    }
93
94    /**
95     * Get confidence score
96     *
97     * @return int
98     */
99    public function getConfidence(): int
100    {
101        return $this->confidence;
102    }
103
104    /**
105     * Get match reason
106     *
107     * @return string
108     */
109    public function getReason(): string
110    {
111        return $this->reason;
112    }
113
114    /**
115     * Whether this is a high-confidence match (>= 90%)
116     *
117     * @return bool
118     */
119    public function isHighConfidence(): bool
120    {
121        return $this->confidence >= 90;
122    }
123
124    /**
125     * Convert to array
126     *
127     * @return array
128     */
129    public function toArray(): array
130    {
131        return [
132            'matched' => $this->wasMatched(),
133            'userId' => $this->getUserId(),
134            'matchType' => $this->matchType,
135            'confidence' => $this->confidence,
136            'reason' => $this->reason,
137        ];
138    }
139}