ineersa/call-graph 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

ineersa/call-graph

最新稳定版本:v0.1.5

Composer 安装命令:

composer require ineersa/call-graph

包简介

PHPStan extension and DOT visualizer for application call graphs

README 文档

README

call-graph is a PHPStan extension plus CLI tools for extracting and visualizing call graphs.

It writes callgraph.json during PHPStan analysis. You can open that in an interactive HTML explorer (no Graphviz required) or render Graphviz DOT/SVG for static diagrams and docs.

Call Graph Explorer: interactive graph with URL filters and node focus

Features

  • Extracts method calls ($obj->method()), static calls (Class::method()), and function calls (foo()).
  • Uses PHPStan type/reflection data to resolve declaring classes where possible.
  • Emits structured JSON with metadata (file, line, callType, unresolved).
  • Includes compatibility output (data) for existing callmap-style tooling.
  • Interactive HTML explorer (Cytoscape.js) with URL-driven filters and node focus—no Graphviz install needed.
  • Graphviz DOT/SVG output with namespace clustering and regex filtering.
  • Excludes function-involved edges by default in visualization (use --include-functions to opt in).
  • Supports coupling-oriented views with namespace mode and edge-weight filtering.

Install

composer require --dev ineersa/call-graph

Requirements: PHP 8.2+ and PHPStan 2.1+.

If you use phpstan/extension-installer, callgraph.neon is auto-registered from package metadata.

Without extension-installer, include it manually in your phpstan.neon:

includes:
    - vendor/ineersa/call-graph/callgraph.neon

Generate call graph JSON

Run PHPStan with the extension config:

./vendor/bin/phpstan analyse -c vendor/ineersa/call-graph/callgraph.neon <path/to/src>

By default this writes callgraph.json in the current working directory.

Override output location in your own config:

includes:
    - vendor/ineersa/call-graph/callgraph.neon

services:
    errorFormatter.callgraph:
        class: CallGraph\PHPStan\Formatter\CallGraphJsonFormatter
        arguments:
            outputFile: build/callgraph.json

Render visualization

Interactive HTML (recommended for exploration)

Loads the graph in the browser with pan/zoom, node focus, and shareable filter URLs. Does not require Graphviz.

./vendor/bin/callgraph-viz-html --input callgraph.json --html callgraph.html

Query parameters (changing them reloads the page):

  • mode=class|method|namespace
  • namespaceDepth=<n>
  • minEdgeWeight=<n>
  • maxNodes=<n>
  • includeFunctions=1
  • strictNamespaces=1 (when ns is set, keep only relations where both sides match)
  • ns=App\\Service,App\\Domain (comma-separated namespace prefixes)

Example:

file:///.../callgraph.html?mode=method&ns=App\Service,App\Domain&maxNodes=300

Graphviz (DOT and SVG)

For static diagrams, documentation, or pipelines that already use dot:

./vendor/bin/callgraph-viz --input callgraph.json --dot callgraph.dot
./vendor/bin/callgraph-viz --input callgraph.json --dot callgraph.dot --svg callgraph.svg

Useful filters:

./vendor/bin/callgraph-viz \
  --mode method \
  --include '/^App\\/' \
  --exclude '/\\Tests\\/' \
  --max-nodes 250

Large graph / coupling-style view:

./vendor/bin/callgraph-viz \
  --mode namespace \
  --namespace-depth 3 \
  --min-edge-weight 2 \
  --max-nodes 120 \
  --include '/^App\\/' \
  --dot coupling.dot

Include functions if needed:

./vendor/bin/callgraph-viz --include-functions --mode method

Output format

callgraph.json contains:

  • meta: generation metadata
  • edges: full graph edges with enriched metadata
  • data: callmap-compatible shape (callingClass, callingMethod, calledClass, calledMethod)

Example edge:

{
  "callerClass": "App\\Service\\UserService",
  "callerMember": "getUser",
  "callerKind": "method",
  "calleeClass": "App\\Repository\\UserRepository",
  "calleeMember": "find",
  "calleeKind": "method",
  "callType": "method",
  "file": "src/Service/UserService.php",
  "line": 41,
  "unresolved": false
}

Acknowledgements

This project follows the PHPStan pattern for extracting structured data from analysis (collectors, a CollectedDataNode rule, and a custom error formatter), as described in Using PHPStan to Extract Data About Your Codebase.

The callmap-compatible data shape and the overall idea of emitting a JSON call map from PHPStan build on prior work in stella-maris/callmap.

统计信息

  • 总下载量: 18
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 4
  • 点击次数: 4
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 4
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-04-08

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固