ineersa/call-graph

PHPStan extension and DOT visualizer for application call graphs

Maintainers

Package info

github.com/ineersa/call-graph

Type:phpstan-extension

pkg:composer/ineersa/call-graph

Statistics

Installs: 3

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v0.1.2 2026-04-08 03:15 UTC

This package is auto-updated.

Last update: 2026-04-08 03:17:32 UTC


README

call-graph is a PHPStan extension plus a rendering script for extracting and visualizing call graphs.

It generates callgraph.json during PHPStan analysis and can render a Graphviz DOT (and optionally SVG) call graph.

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.
  • Renders DOT/SVG graphs 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

Generate DOT:

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

Generate DOT and SVG (requires Graphviz 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 view (recommended):

./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.