coerceResultLabel($dec[$k] ?? null); if ($s !== '') { return $s; } } return ''; } if ($targetType === 'disc') { $two = PdpDiscResultText::discTopTwo($dec); if ($two !== '') { return $two; } $desc = $dec['description']['type'] ?? null; if (is_string($desc) && $desc !== '') { return $desc; } $dom = $this->coerceResultLabel($dec['dominantType'] ?? null); if ($dom !== '') { return $dom; } return $this->coerceResultLabel($dec['disc'] ?? null); } if ($targetType === 'pdp') { $two = PdpDiscResultText::pdpTopTwo($dec); if ($two !== '') { return $two; } $desc = $dec['description']['type'] ?? null; if (is_string($desc) && $desc !== '') { return $desc; } $dom = $this->coerceResultLabel($dec['dominantType'] ?? null); if ($dom !== '') { return $dom; } return $this->coerceResultLabel($dec['pdp'] ?? null); } if ($targetType === 'sbti') { $code = $this->coerceResultLabel($dec['sbtiType'] ?? null); if ($code === '' && isset($dec['finalType']) && is_array($dec['finalType'])) { $code = $this->coerceResultLabel($dec['finalType']['code'] ?? null); } $cn = ''; if (!empty($dec['sbtiCn']) && is_string($dec['sbtiCn'])) { $cn = trim($dec['sbtiCn']); } elseif (isset($dec['finalType']) && is_array($dec['finalType']) && !empty($dec['finalType']['cn']) && is_string($dec['finalType']['cn'])) { $cn = trim((string) $dec['finalType']['cn']); } if ($code !== '' && $cn !== '') { return $code . '(' . $cn . ')'; } if ($code !== '') { return $code; } if ($cn !== '') { return $cn; } return $this->coerceResultLabel($dec['code'] ?? null); } $fallback = $this->coerceResultLabel($dec['type'] ?? null); if ($fallback !== '') { return $fallback; } return $this->coerceResultLabel($dec['result'] ?? null); } return ''; } private function extractFaceSubType(array $tests, string $subType): string { $target = strtolower($subType); foreach ($tests as $t) { if (strtolower($t['testType'] ?? '') !== 'face') { continue; } $result = $t['result'] ?? ''; if (!is_string($result)) { continue; } $dec = json_decode($result, true); if (!is_array($dec)) { continue; } if ($target === 'mbti') { if (!empty($dec['mbti']['type'])) { return (string) $dec['mbti']['type']; } if (!empty($dec['mbtiType'])) { return (string) $dec['mbtiType']; } } elseif ($target === 'disc') { if (!empty($dec['disc']['primary'])) { return $this->coerceResultLabel($dec['disc']['primary']); } $d = $dec['disc'] ?? null; if (is_array($d)) { $s = $this->coerceResultLabel($d); if ($s !== '') { return $s; } } } elseif ($target === 'pdp') { if (!empty($dec['pdp']['primary'])) { return $this->coerceResultLabel($dec['pdp']['primary']); } $p = $dec['pdp'] ?? null; if (is_array($p)) { $s = $this->coerceResultLabel($p); if ($s !== '') { return $s; } } } } return ''; } }