{
"event": "PreToolUse",
"tool_name": "Edit",
"tool_input": {
"file_path": "\/var\/www\/dev.campus.systemische-tools.de\/src\/Infrastructure\/CodeAnalysis\/UseStatementExtractorTrait.php",
"old_string": " $count = count($tokens);\n $baseNamespace = '';\n $currentName = '';\n $inGroup = false;\n\n for ($i = $startIndex + 1; $i < $count; $i++) {",
"new_string": " $count = count($tokens);\n $baseNamespace = '';\n $currentName = '';\n $inGroup = false;\n $i = $startIndex;\n\n for ($i = $startIndex + 1; $i < $count; $i++) {"
}
}
{
"tool_response": {
"filePath": "\/var\/www\/dev.campus.systemische-tools.de\/src\/Infrastructure\/CodeAnalysis\/UseStatementExtractorTrait.php",
"oldString": " $count = count($tokens);\n $baseNamespace = '';\n $currentName = '';\n $inGroup = false;\n\n for ($i = $startIndex + 1; $i < $count; $i++) {",
"newString": " $count = count($tokens);\n $baseNamespace = '';\n $currentName = '';\n $inGroup = false;\n $i = $startIndex;\n\n for ($i = $startIndex + 1; $i < $count; $i++) {",
"originalFile": "<?php\n\ndeclare(strict_types=1);\n\nnamespace Infrastructure\\CodeAnalysis;\n\n\/\/ @responsibility: Use-Statement-Extraktion aus PHP-Token-Arrays\n\n\/**\n * Trait for extracting use statements from PHP token arrays.\n *\n * Handles grouped imports, aliases, and distinguishes between\n * top-level use statements and trait use statements inside classes.\n *\/\ntrait UseStatementExtractorTrait\n{\n \/**\n * Extracts use statements (top-level imports only).\n *\n * @param array<mixed> $tokens\n * @return array<string>\n *\/\n private function extractUseStatements(array $tokens): array\n {\n $uses = [];\n $count = count($tokens);\n $braceDepth = 0;\n\n for ($i = 0; $i < $count; $i++) {\n $token = $tokens[$i];\n\n \/\/ Track brace depth to distinguish top-level use from trait use\n if (!is_array($token)) {\n if ($token === '{') {\n $braceDepth++;\n } elseif ($token === '}') {\n $braceDepth--;\n }\n\n continue;\n }\n\n \/\/ Only process top-level use statements\n if ($token[0] !== T_USE || $braceDepth > 0) {\n continue;\n }\n\n \/\/ Skip function\/const imports\n $nextToken = $this->findNextNonWhitespace($tokens, $i);\n if ($nextToken !== null && is_array($tokens[$nextToken])) {\n if ($tokens[$nextToken][0] === T_FUNCTION || $tokens[$nextToken][0] === T_CONST) {\n continue;\n }\n }\n\n \/\/ Extract the use statement(s)\n $useResult = $this->parseUseStatement($tokens, $i);\n foreach ($useResult['fqcns'] as $fqcn) {\n $uses[] = $fqcn;\n }\n }\n\n return array_unique($uses);\n }\n\n \/**\n * Parse a single use statement, handling grouped imports.\n *\n * @param array<mixed> $tokens\n * @return array{fqcns: array<string>, endIndex: int}\n *\/\n private function parseUseStatement(array $tokens, int $startIndex): array\n {\n $fqcns = [];\n $count = count($tokens);\n $baseNamespace = '';\n $currentName = '';\n $inGroup = false;\n\n for ($i = $startIndex + 1; $i < $count; $i++) {\n $token = $tokens[$i];\n\n if ($token === ';') {\n if ($currentName !== '') {\n $fqcns[] = $inGroup ? $baseNamespace . $currentName : $currentName;\n }\n\n break;\n }\n\n if ($token === '{') {\n $baseNamespace = $currentName;\n $currentName = '';\n $inGroup = true;\n\n continue;\n }\n\n if ($token === '}') {\n if ($currentName !== '') {\n $fqcns[] = $baseNamespace . $currentName;\n }\n\n continue;\n }\n\n if ($token === ',') {\n if ($currentName !== '') {\n $fqcns[] = $inGroup ? $baseNamespace . $currentName : $currentName;\n }\n $currentName = '';\n\n continue;\n }\n\n if (!is_array($token)) {\n continue;\n }\n\n \/\/ Skip 'as' aliases - we only care about the original FQCN\n if ($token[0] === T_AS) {\n \/\/ Skip until comma or semicolon\n for ($j = $i + 1; $j < $count; $j++) {\n if ($tokens[$j] === ',' || $tokens[$j] === ';' || $tokens[$j] === '}') {\n $i = $j - 1;\n\n break;\n }\n }\n\n continue;\n }\n\n if ($token[0] === T_NAME_QUALIFIED || $token[0] === T_NAME_FULLY_QUALIFIED) {\n $currentName .= ltrim($token[1], '\\\\');\n } elseif ($token[0] === T_STRING) {\n $currentName .= $token[1];\n } elseif ($token[0] === T_NS_SEPARATOR) {\n $currentName .= '\\\\';\n }\n }\n\n return ['fqcns' => $fqcns, 'endIndex' => $i];\n }\n\n \/**\n * Required from TokenNavigatorTrait.\n *\n * @param array<mixed> $tokens\n *\/\n abstract private function findNextNonWhitespace(array $tokens, int $index): ?int;\n}\n",
"structuredPatch": [
{
"oldStart": 76,
"oldLines": 6,
"newStart": 76,
"newLines": 7,
"lines": [
" $baseNamespace = '';",
" $currentName = '';",
" $inGroup = false;",
"+ $i = $startIndex;",
" ",
" for ($i = $startIndex + 1; $i < $count; $i++) {",
" $token = $tokens[$i];"
]
}
],
"userModified": false,
"replaceAll": false
}
}