style: Pint 포맷팅 적용

This commit is contained in:
김보곤
2026-02-25 11:45:01 +09:00
parent 68b1622a4e
commit 9a7c548246
199 changed files with 1420 additions and 1083 deletions

View File

@@ -37,19 +37,19 @@ private function callVertexAiApi(AiConfig $config, string $base64Image): array
$projectId = $config->getProjectId();
$region = $config->getRegion();
if (!$projectId) {
if (! $projectId) {
throw new \RuntimeException('Vertex AI 프로젝트 ID가 설정되지 않았습니다.');
}
$accessToken = $this->getAccessToken($config);
if (!$accessToken) {
if (! $accessToken) {
throw new \RuntimeException('Google Cloud 인증 실패');
}
$url = "https://{$region}-aiplatform.googleapis.com/v1/projects/{$projectId}/locations/{$region}/publishers/google/models/{$model}:generateContent";
return $this->callGeminiApi($url, $base64Image, [
'Authorization' => 'Bearer ' . $accessToken,
'Authorization' => 'Bearer '.$accessToken,
'Content-Type' => 'application/json',
], true);
}
@@ -122,7 +122,7 @@ private function callGeminiApi(string $url, string $base64Image, array $headers,
'status' => $response->status(),
'body' => $response->body(),
]);
throw new \RuntimeException('AI API 호출 실패: ' . $response->status());
throw new \RuntimeException('AI API 호출 실패: '.$response->status());
}
$result = $response->json();
@@ -169,14 +169,16 @@ private function getAccessToken(AiConfig $config): ?string
}
}
if (!$serviceAccountPath) {
if (! $serviceAccountPath) {
Log::error('Service account file not found', ['tried_paths' => $possiblePaths]);
return null;
}
$serviceAccount = json_decode(file_get_contents($serviceAccountPath), true);
if (!$serviceAccount) {
if (! $serviceAccount) {
Log::error('Service account JSON parse failed');
return null;
}
@@ -191,13 +193,14 @@ private function getAccessToken(AiConfig $config): ?string
]));
$privateKey = openssl_pkey_get_private($serviceAccount['private_key']);
if (!$privateKey) {
if (! $privateKey) {
Log::error('Failed to load private key');
return null;
}
openssl_sign($jwtHeader . '.' . $jwtClaim, $signature, $privateKey, OPENSSL_ALGO_SHA256);
$jwt = $jwtHeader . '.' . $jwtClaim . '.' . $this->base64UrlEncode($signature);
openssl_sign($jwtHeader.'.'.$jwtClaim, $signature, $privateKey, OPENSSL_ALGO_SHA256);
$jwt = $jwtHeader.'.'.$jwtClaim.'.'.$this->base64UrlEncode($signature);
try {
$response = Http::asForm()->post('https://oauth2.googleapis.com/token', [
@@ -207,6 +210,7 @@ private function getAccessToken(AiConfig $config): ?string
if ($response->successful()) {
$data = $response->json();
return $data['access_token'] ?? null;
}
@@ -214,9 +218,11 @@ private function getAccessToken(AiConfig $config): ?string
'status' => $response->status(),
'body' => $response->body(),
]);
return null;
} catch (\Exception $e) {
Log::error('OAuth token request exception', ['error' => $e->getMessage()]);
return null;
}
}
@@ -234,7 +240,7 @@ private function base64UrlEncode(string $data): string
*/
private function buildPrompt(): string
{
return <<<PROMPT
return <<<'PROMPT'
이 사업자등록증 이미지에서 다음 정보를 추출해주세요.
## 추출 항목
@@ -279,7 +285,7 @@ private function normalizeData(array $data): array
if (! empty($data['business_number'])) {
$digits = preg_replace('/\D/', '', $data['business_number']);
if (strlen($digits) === 10) {
$data['business_number'] = substr($digits, 0, 3) . '-' . substr($digits, 3, 2) . '-' . substr($digits, 5);
$data['business_number'] = substr($digits, 0, 3).'-'.substr($digits, 3, 2).'-'.substr($digits, 5);
}
}