The "Check NIE T" branch compared the control character of the TIN to the
return value of preg_match() instead of using preg_match() as the condition:
if ($num[8] == preg_match('/^[T]{1}[A-Z0-9]{8}$/', $str)) {
Since execution only reaches that branch when the string already matched the
format, preg_match() always returns 1, so the test collapsed to
$num[8] == 1. A NIE of type T therefore validated only when its last
character was literally "1", and every other one was reported as -3
(invalid control key). Out of the 36 possible control characters, 35 were
wrongly rejected.
A NIE starting with T has no control key algorithm, so matching the
documented syntax is the only check to perform.
Also fill in and enable the testIsValidTinForES() unit test that was left
commented out with empty input strings.
Co-authored-by: Claude <noreply@anthropic.com>