callgraph

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 13, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CallEdge

type CallEdge struct {
	From     NodeID
	To       NodeID
	Type     CallType
	Label    string // human-readable label for the edge
	FileLine string // "file.php:42" where the call occurs
}

CallEdge represents a directed edge in the call graph.

type CallGraph

type CallGraph struct {
	Nodes map[NodeID]*CallNode
	Edges []*CallEdge

	// Index: from node → list of edges.
	OutEdges map[NodeID][]*CallEdge
	InEdges  map[NodeID][]*CallEdge
}

CallGraph is the internal call graph data structure.

func BuildCallGraph

func BuildCallGraph(
	results []*phpparse.ParseResult,
	symbols *phpparse.SymbolTable,
	typeMappings map[string]string,
	resolveTypes bool,
	showFunctions bool,
) *CallGraph

BuildCallGraph constructs the call graph from all parsed files.

func NewCallGraph

func NewCallGraph() *CallGraph

NewCallGraph creates an empty call graph.

func (*CallGraph) AddEdge

func (cg *CallGraph) AddEdge(edge *CallEdge)

AddEdge adds a directed edge and ensures both nodes exist.

func (*CallGraph) AddNode

func (cg *CallGraph) AddNode(node *CallNode)

AddNode adds a node if it doesn't already exist.

func (*CallGraph) CollapseToClassLevel

func (cg *CallGraph) CollapseToClassLevel() *CallGraph

CollapseToClassLevel merges all methods of each class into a single node, producing a class→class dependency graph.

func (*CallGraph) ExcludeMethods

func (cg *CallGraph) ExcludeMethods(methods []string) *CallGraph

ExcludeMethods removes edges pointing to methods in the exclude list.

func (*CallGraph) FilterByClasses

func (cg *CallGraph) FilterByClasses(includes, excludes []string) *CallGraph

FilterByClasses returns a new graph keeping only nodes whose ClassFQN or short ClassName matches the include/exclude lists.

func (*CallGraph) FilterByEntryPoints

func (cg *CallGraph) FilterByEntryPoints(entryPoints []NodeID, maxDepth int) *CallGraph

FilterByEntryPoints returns a new graph containing only nodes reachable from the given entry points within maxDepth steps (0 = unlimited).

func (*CallGraph) FilterByNamespaces

func (cg *CallGraph) FilterByNamespaces(includes, excludes []string) *CallGraph

FilterByNamespaces returns a new graph keeping only nodes whose ClassFQN matches at least one include pattern and none of the exclude patterns.

func (*CallGraph) Stats

func (cg *CallGraph) Stats() string

Stats returns a human-readable summary of the graph.

type CallNode

type CallNode struct {
	ID        NodeID
	Label     string // short display label, e.g. "getUser"
	ClassFQN  string // "" for standalone functions
	ClassName string // short class name for display
	Method    string // method/function name
	IsStatic  bool
	Kind      string // "class", "interface", "trait", "enum", "function"
	File      string
}

CallNode represents a node in the call graph (a method or function).

type CallType

type CallType int

CallType describes the kind of a method/function call.

const (
	CallInstance   CallType = iota // $obj->method()
	CallNullsafe                   // $obj?->method()
	CallStatic                     // Class::method()
	CallFunction                   // functionName()
	CallNew                        // new ClassName()
	CallUnresolved                 // could not resolve receiver type
	CallDynamic                    // $obj->$method() — dynamic name
)

func (CallType) String

func (ct CallType) String() string

type NodeID

type NodeID string

NodeID uniquely identifies a graph node (a method or function).

func MakeFunctionID

func MakeFunctionID(functionFQN string) NodeID

MakeFunctionID creates a NodeID for a standalone function.

func MakeMethodID

func MakeMethodID(classFQN, method string) NodeID

MakeMethodID creates a NodeID for a class method.

type TypeResolver

type TypeResolver struct {
	// contains filtered or unexported fields
}

TypeResolver provides heuristic type resolution for PHP variables. It tracks:

  • $this → current class
  • $var = new ClassName() → $var is ClassName
  • Type-hinted parameters: function foo(UserRepo $repo) → $repo is UserRepo
  • Type-hinted properties: private UserRepo $repo → $this->repo is UserRepo
  • Manual overrides from config.yaml type_mappings

func NewTypeResolver

func NewTypeResolver(
	symbols *phpparse.SymbolTable,
	resolvedNames map[ast.Vertex]string,
	typeMappings map[string]string,
) *TypeResolver

NewTypeResolver creates a resolver with the given context.

func (*TypeResolver) EnterClass

func (tr *TypeResolver) EnterClass(fqn string)

EnterClass sets the current class context.

func (*TypeResolver) EnterMethod

func (tr *TypeResolver) EnterMethod(params []phpparse.ParamInfo)

EnterMethod resets the variable scope and seeds it with parameter types.

func (*TypeResolver) LeaveClass

func (tr *TypeResolver) LeaveClass()

LeaveClass clears the current class context.

func (*TypeResolver) ResolveNewExprType

func (tr *TypeResolver) ResolveNewExprType(classNode ast.Vertex) string

ResolveNewExprType resolves the type for a `new ClassName()` expression.

func (*TypeResolver) ResolveParent

func (tr *TypeResolver) ResolveParent() string

ResolveParent resolves "parent" to the parent class FQN.

func (*TypeResolver) ResolvePropertyFetch

func (tr *TypeResolver) ResolvePropertyFetch(receiverVar string, propName string) string

ResolvePropertyFetch resolves $this->prop to the property type.

func (*TypeResolver) ResolveSelf

func (tr *TypeResolver) ResolveSelf() string

ResolveSelf resolves "self" to the current class FQN.

func (*TypeResolver) ResolveStaticKeyword

func (tr *TypeResolver) ResolveStaticKeyword() string

ResolveStaticKeyword resolves the "static" keyword. Since this is late static binding, we return the current class but mark it as potentially polymorphic.

func (*TypeResolver) ResolveVariable

func (tr *TypeResolver) ResolveVariable(varName string) string

ResolveVariable tries to determine the FQN type of a variable.

func (*TypeResolver) TrackAssignment

func (tr *TypeResolver) TrackAssignment(varName string, exprTypeFQN string)

TrackAssignment records a variable assignment like $var = new ClassName().

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL