MCPcopy Index your code
hub / github.com/php/frankenphp / extractVariables

Method extractVariables

internal/extgen/srcanalyzer.go:33–76  ·  view source on GitHub ↗
(content string)

Source from the content-addressed store, hash-verified

31}
32
33func (sa *SourceAnalyzer) extractVariables(content string) []string {
34 lines := strings.Split(content, "\n")
35 var (
36 variables []string
37 currentVar strings.Builder
38 inVarBlock bool
39 parenCount int
40 )
41
42 for _, line := range lines {
43 trimmedLine := strings.TrimSpace(line)
44
45 if strings.HasPrefix(trimmedLine, "var ") && !inVarBlock {
46 if strings.Contains(trimmedLine, "(") {
47 inVarBlock = true
48 parenCount = 1
49 currentVar.Reset()
50 currentVar.WriteString(line + "\n")
51 } else {
52 variables = append(variables, strings.TrimSpace(line))
53 }
54 } else if inVarBlock {
55 currentVar.WriteString(line + "\n")
56
57 for _, char := range line {
58 switch char {
59 case '(':
60 parenCount++
61 case ')':
62 parenCount--
63 }
64 }
65
66 if parenCount == 0 {
67 varContent := currentVar.String()
68 variables = append(variables, strings.TrimSpace(varContent))
69 inVarBlock = false
70 currentVar.Reset()
71 }
72 }
73 }
74
75 return variables
76}
77
78func (sa *SourceAnalyzer) extractInternalFunctions(content string) []string {
79 lines := strings.Split(content, "\n")

Callers 1

analyzeMethod · 0.95

Calls 3

ResetMethod · 0.80
WriteStringMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected