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

Method parseMethods

internal/extgen/classparser.go:204–273  ·  view source on GitHub ↗
(filename string)

Source from the content-addressed store, hash-verified

202}
203
204func (cp *classParser) parseMethods(filename string) ([]phpClassMethod, error) {
205 src, err := os.ReadFile(filename)
206 if err != nil {
207 return nil, err
208 }
209
210 fset := token.NewFileSet()
211 file, err := parser.ParseFile(fset, filename, src, parser.ParseComments)
212 if err != nil {
213 return nil, fmt.Errorf("parsing file: %w", err)
214 }
215
216 validator := Validator{}
217 var methods []phpClassMethod
218 consumed := make(map[int]bool)
219
220 for _, decl := range file.Decls {
221 funcDecl, ok := decl.(*ast.FuncDecl)
222 if !ok {
223 continue
224 }
225
226 directive, directiveLine := findDirective(funcDecl.Doc, fset, phpMethodRegex)
227 if directive == "" {
228 continue
229 }
230 rawMatch := phpMethodRegex.FindStringSubmatch(findMatchingComment(funcDecl.Doc, phpMethodRegex))
231 if len(rawMatch) != 3 {
232 continue
233 }
234 className := strings.TrimSpace(rawMatch[1])
235 signature := strings.TrimSpace(rawMatch[2])
236 consumed[directiveLine] = true
237
238 method, err := cp.parseMethodSignature(className, signature)
239 if err != nil {
240 fmt.Fprintf(os.Stderr, "Warning: Error parsing method signature %q: %v\n", signature, err)
241 continue
242 }
243
244 phpFunc := phpFunction{
245 Name: method.Name,
246 Signature: method.Signature,
247 Params: method.Params,
248 ReturnType: method.ReturnType,
249 IsReturnNullable: method.isReturnNullable,
250 }
251 if err := validator.validateTypes(phpFunc); err != nil {
252 fmt.Fprintf(os.Stderr, "Warning: Method \"%s::%s\" uses unsupported types: %v\n", className, method.Name, err)
253 continue
254 }
255
256 method.lineNumber = directiveLine
257 method.GoFunction = extractNodeSource(src, fset, funcDecl)
258
259 phpFunc.GoFunction = method.GoFunction
260 if err := validator.validateGoFunctionSignatureWithOptions(phpFunc, true); err != nil {
261 fmt.Fprintf(os.Stderr, "Warning: Go method signature mismatch for '%s::%s': %v\n", method.ClassName, method.Name, err)

Callers 1

parseMethod · 0.95

Calls 7

parseMethodSignatureMethod · 0.95
validateTypesMethod · 0.95
findDirectiveFunction · 0.85
findMatchingCommentFunction · 0.85
extractNodeSourceFunction · 0.85
checkOrphanDirectivesFunction · 0.85

Tested by

no test coverage detected