{
"event": "PreToolUse",
"tool_name": "Write",
"tool_input": {
"file_path": "\/var\/www\/dev.campus.systemische-tools.de\/src\/Infrastructure\/CodeAnalysis\/ClassFunctionExtractorTrait.php",
"content": "<?php\n\ndeclare(strict_types=1);\n\nnamespace Infrastructure\\CodeAnalysis;\n\n\/\/ @responsibility: Extraktion von Klassen\/Interfaces\/Traits und Funktionen\n\n\/**\n * Trait for extracting class and function definitions from PHP token arrays.\n *\/\ntrait ClassFunctionExtractorTrait\n{\n \/**\n * Extract class\/interface\/trait\/enum definitions.\n *\n * @param array<mixed> $tokens\n * @return array<array{name: string, type: string, line: int}>\n *\/\n private function extractClasses(array $tokens): array\n {\n $classes = [];\n $count = count($tokens);\n\n for ($i = 0; $i < $count; $i++) {\n $token = $tokens[$i];\n\n if (!is_array($token)) {\n continue;\n }\n\n $type = match ($token[0]) {\n T_CLASS => 'class',\n T_INTERFACE => 'interface',\n T_TRAIT => 'trait',\n T_ENUM => 'enum',\n default => null,\n };\n\n if ($type === null) {\n continue;\n }\n\n \/\/ Skip anonymous class statements\n $prevIndex = $this->findPrevNonWhitespace($tokens, $i);\n if ($prevIndex !== null && is_array($tokens[$prevIndex]) && $tokens[$prevIndex][0] === T_NEW) {\n continue;\n }\n\n \/\/ Find class name\n for ($j = $i + 1; $j < $count; $j++) {\n if (is_array($tokens[$j]) && $tokens[$j][0] === T_STRING) {\n $classes[] = [\n 'name' => $tokens[$j][1],\n 'type' => $type,\n 'line' => $token[2],\n ];\n\n break;\n }\n }\n }\n\n return $classes;\n }\n\n \/**\n * Extract function\/method definitions.\n *\n * @param array<mixed> $tokens\n * @return array<array{name: string, visibility: string|null, line: int}>\n *\/\n private function extractFunctions(array $tokens): array\n {\n $functions = [];\n $count = count($tokens);\n $braceDepth = 0;\n $inClass = false;\n\n for ($i = 0; $i < $count; $i++) {\n $token = $tokens[$i];\n\n if (!is_array($token)) {\n if ($token === '{') {\n $braceDepth++;\n } elseif ($token === '}') {\n $braceDepth--;\n if ($braceDepth === 0) {\n $inClass = false;\n }\n }\n\n continue;\n }\n\n if (in_array($token[0], [T_CLASS, T_INTERFACE, T_TRAIT, T_ENUM], true)) {\n $inClass = true;\n }\n\n if ($token[0] !== T_FUNCTION) {\n continue;\n }\n\n $visibility = null;\n if ($inClass) {\n for ($j = $i - 1; $j >= 0; $j--) {\n if (!is_array($tokens[$j])) {\n break;\n }\n if ($tokens[$j][0] === T_PUBLIC) {\n $visibility = 'public';\n\n break;\n }\n if ($tokens[$j][0] === T_PROTECTED) {\n $visibility = 'protected';\n\n break;\n }\n if ($tokens[$j][0] === T_PRIVATE) {\n $visibility = 'private';\n\n break;\n }\n if ($tokens[$j][0] !== T_WHITESPACE && $tokens[$j][0] !== T_STATIC && $tokens[$j][0] !== T_FINAL && $tokens[$j][0] !== T_ABSTRACT) {\n break;\n }\n }\n }\n\n for ($j = $i + 1; $j < $count; $j++) {\n if (is_array($tokens[$j]) && $tokens[$j][0] === T_STRING) {\n $functions[] = [\n 'name' => $tokens[$j][1],\n 'visibility' => $visibility,\n 'line' => $token[2],\n ];\n\n break;\n }\n if ($tokens[$j] === '(') {\n break;\n }\n }\n }\n\n return $functions;\n }\n\n \/**\n * Required from TokenNavigatorTrait.\n *\n * @param array<mixed> $tokens\n *\/\n abstract private function findPrevNonWhitespace(array $tokens, int $index): ?int;\n}\n"
}
}
{
"tool_response": {
"type": "create",
"filePath": "\/var\/www\/dev.campus.systemische-tools.de\/src\/Infrastructure\/CodeAnalysis\/ClassFunctionExtractorTrait.php",
"content": "<?php\n\ndeclare(strict_types=1);\n\nnamespace Infrastructure\\CodeAnalysis;\n\n\/\/ @responsibility: Extraktion von Klassen\/Interfaces\/Traits und Funktionen\n\n\/**\n * Trait for extracting class and function definitions from PHP token arrays.\n *\/\ntrait ClassFunctionExtractorTrait\n{\n \/**\n * Extract class\/interface\/trait\/enum definitions.\n *\n * @param array<mixed> $tokens\n * @return array<array{name: string, type: string, line: int}>\n *\/\n private function extractClasses(array $tokens): array\n {\n $classes = [];\n $count = count($tokens);\n\n for ($i = 0; $i < $count; $i++) {\n $token = $tokens[$i];\n\n if (!is_array($token)) {\n continue;\n }\n\n $type = match ($token[0]) {\n T_CLASS => 'class',\n T_INTERFACE => 'interface',\n T_TRAIT => 'trait',\n T_ENUM => 'enum',\n default => null,\n };\n\n if ($type === null) {\n continue;\n }\n\n \/\/ Skip anonymous class statements\n $prevIndex = $this->findPrevNonWhitespace($tokens, $i);\n if ($prevIndex !== null && is_array($tokens[$prevIndex]) && $tokens[$prevIndex][0] === T_NEW) {\n continue;\n }\n\n \/\/ Find class name\n for ($j = $i + 1; $j < $count; $j++) {\n if (is_array($tokens[$j]) && $tokens[$j][0] === T_STRING) {\n $classes[] = [\n 'name' => $tokens[$j][1],\n 'type' => $type,\n 'line' => $token[2],\n ];\n\n break;\n }\n }\n }\n\n return $classes;\n }\n\n \/**\n * Extract function\/method definitions.\n *\n * @param array<mixed> $tokens\n * @return array<array{name: string, visibility: string|null, line: int}>\n *\/\n private function extractFunctions(array $tokens): array\n {\n $functions = [];\n $count = count($tokens);\n $braceDepth = 0;\n $inClass = false;\n\n for ($i = 0; $i < $count; $i++) {\n $token = $tokens[$i];\n\n if (!is_array($token)) {\n if ($token === '{') {\n $braceDepth++;\n } elseif ($token === '}') {\n $braceDepth--;\n if ($braceDepth === 0) {\n $inClass = false;\n }\n }\n\n continue;\n }\n\n if (in_array($token[0], [T_CLASS, T_INTERFACE, T_TRAIT, T_ENUM], true)) {\n $inClass = true;\n }\n\n if ($token[0] !== T_FUNCTION) {\n continue;\n }\n\n $visibility = null;\n if ($inClass) {\n for ($j = $i - 1; $j >= 0; $j--) {\n if (!is_array($tokens[$j])) {\n break;\n }\n if ($tokens[$j][0] === T_PUBLIC) {\n $visibility = 'public';\n\n break;\n }\n if ($tokens[$j][0] === T_PROTECTED) {\n $visibility = 'protected';\n\n break;\n }\n if ($tokens[$j][0] === T_PRIVATE) {\n $visibility = 'private';\n\n break;\n }\n if ($tokens[$j][0] !== T_WHITESPACE && $tokens[$j][0] !== T_STATIC && $tokens[$j][0] !== T_FINAL && $tokens[$j][0] !== T_ABSTRACT) {\n break;\n }\n }\n }\n\n for ($j = $i + 1; $j < $count; $j++) {\n if (is_array($tokens[$j]) && $tokens[$j][0] === T_STRING) {\n $functions[] = [\n 'name' => $tokens[$j][1],\n 'visibility' => $visibility,\n 'line' => $token[2],\n ];\n\n break;\n }\n if ($tokens[$j] === '(') {\n break;\n }\n }\n }\n\n return $functions;\n }\n\n \/**\n * Required from TokenNavigatorTrait.\n *\n * @param array<mixed> $tokens\n *\/\n abstract private function findPrevNonWhitespace(array $tokens, int $index): ?int;\n}\n",
"structuredPatch": [],
"originalFile": null
}
}