graphify-php 0.0.5__tar.gz → 0.0.6__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (132) hide show
  1. {graphify_php-0.0.5 → graphify_php-0.0.6}/.github/workflows/stage-security.yml +12 -13
  2. {graphify_php-0.0.5 → graphify_php-0.0.6}/PKG-INFO +1 -1
  3. {graphify_php-0.0.5 → graphify_php-0.0.6}/docs/configuration.md +51 -1
  4. {graphify_php-0.0.5 → graphify_php-0.0.6}/docs/install.md +1 -1
  5. {graphify_php-0.0.5 → graphify_php-0.0.6}/docs/setup.md +4 -2
  6. {graphify_php-0.0.5 → graphify_php-0.0.6}/php/README.md +20 -4
  7. {graphify_php-0.0.5 → graphify_php-0.0.6}/php/src/CallGraph/CallEdge.php +12 -2
  8. {graphify_php-0.0.5 → graphify_php-0.0.6}/php/src/CallGraph/CallEdgeRule.php +2 -2
  9. {graphify_php-0.0.5 → graphify_php-0.0.6}/php/src/CallGraph/MethodCallCollector.php +49 -3
  10. {graphify_php-0.0.5 → graphify_php-0.0.6}/src/graphify_php/__init__.py +37 -33
  11. {graphify_php-0.0.5 → graphify_php-0.0.6}/src/graphify_php/cli.py +121 -1
  12. {graphify_php-0.0.5 → graphify_php-0.0.6}/src/graphify_php/config_resolver.py +6 -33
  13. graphify_php-0.0.6/src/graphify_php/core_guard.py +297 -0
  14. {graphify_php-0.0.5 → graphify_php-0.0.6}/src/graphify_php/graph_adapter.py +447 -1
  15. {graphify_php-0.0.5 → graphify_php-0.0.6}/src/graphify_php/ports.py +112 -1
  16. graphify_php-0.0.6/src/graphify_php/resolver.py +1042 -0
  17. {graphify_php-0.0.5 → graphify_php-0.0.6}/src/graphify_php/shrink.py +260 -24
  18. {graphify_php-0.0.5 → graphify_php-0.0.6}/src/graphify_php/shrink_cli.py +14 -0
  19. {graphify_php-0.0.5 → graphify_php-0.0.6}/src/graphify_php/sources/phpstan_source.py +275 -21
  20. graphify_php-0.0.6/src/graphify_php/sources/tree_sitter_source.py +859 -0
  21. {graphify_php-0.0.5 → graphify_php-0.0.6}/src/graphify_php/status.py +50 -0
  22. {graphify_php-0.0.5 → graphify_php-0.0.6}/src/graphify_php/syntax/collectors.py +151 -0
  23. {graphify_php-0.0.5 → graphify_php-0.0.6}/src/graphify_php/syntax/facts.py +15 -0
  24. graphify_php-0.0.6/tests/test_adapter_graph.py +719 -0
  25. graphify_php-0.0.6/tests/test_cli_attribution.py +357 -0
  26. {graphify_php-0.0.5 → graphify_php-0.0.6}/tests/test_cli_gate.py +74 -1
  27. {graphify_php-0.0.5 → graphify_php-0.0.6}/tests/test_cli_shrink_gate.py +127 -2
  28. {graphify_php-0.0.5 → graphify_php-0.0.6}/tests/test_config_resolver.py +65 -1
  29. graphify_php-0.0.6/tests/test_core_guard.py +795 -0
  30. graphify_php-0.0.6/tests/test_engine_contradictions.py +404 -0
  31. graphify_php-0.0.6/tests/test_engine_extracted.py +336 -0
  32. graphify_php-0.0.6/tests/test_new_site_edges.py +285 -0
  33. {graphify_php-0.0.5 → graphify_php-0.0.6}/tests/test_phpstan_integration.py +113 -2
  34. {graphify_php-0.0.5 → graphify_php-0.0.6}/tests/test_phpstan_source.py +537 -0
  35. {graphify_php-0.0.5 → graphify_php-0.0.6}/tests/test_resolver_precedence.py +286 -0
  36. {graphify_php-0.0.5 → graphify_php-0.0.6}/tests/test_shrink.py +10 -0
  37. graphify_php-0.0.6/tests/test_shrink_attribution.py +390 -0
  38. {graphify_php-0.0.5 → graphify_php-0.0.6}/tests/test_shrink_cli.py +63 -0
  39. graphify_php-0.0.6/tests/test_status_record.py +88 -0
  40. graphify_php-0.0.6/tests/test_syntax_parameters.py +478 -0
  41. {graphify_php-0.0.5 → graphify_php-0.0.6}/tests/test_syntax_scan.py +1 -1
  42. graphify_php-0.0.6/tests/test_syntax_writes.py +172 -0
  43. {graphify_php-0.0.5 → graphify_php-0.0.6}/tests/test_tree_sitter_source.py +407 -1
  44. graphify_php-0.0.5/src/graphify_php/resolver.py +0 -519
  45. graphify_php-0.0.5/src/graphify_php/sources/tree_sitter_source.py +0 -428
  46. graphify_php-0.0.5/tests/test_adapter_graph.py +0 -337
  47. {graphify_php-0.0.5 → graphify_php-0.0.6}/.github/workflows/ci.yml +0 -0
  48. {graphify_php-0.0.5 → graphify_php-0.0.6}/.github/workflows/pages.yml +0 -0
  49. {graphify_php-0.0.5 → graphify_php-0.0.6}/.github/workflows/release.yml +0 -0
  50. {graphify_php-0.0.5 → graphify_php-0.0.6}/.github/workflows/stage-build.yml +0 -0
  51. {graphify_php-0.0.5 → graphify_php-0.0.6}/.github/workflows/stage-tests.yml +0 -0
  52. {graphify_php-0.0.5 → graphify_php-0.0.6}/.gitignore +0 -0
  53. {graphify_php-0.0.5 → graphify_php-0.0.6}/.gitleaks.toml +0 -0
  54. {graphify_php-0.0.5 → graphify_php-0.0.6}/.graphifyignore +0 -0
  55. {graphify_php-0.0.5 → graphify_php-0.0.6}/.trufflehog-exclude.txt +0 -0
  56. {graphify_php-0.0.5 → graphify_php-0.0.6}/LICENSE +0 -0
  57. {graphify_php-0.0.5 → graphify_php-0.0.6}/README.md +0 -0
  58. {graphify_php-0.0.5 → graphify_php-0.0.6}/docs/_config.yml +0 -0
  59. {graphify_php-0.0.5 → graphify_php-0.0.6}/docs/architecture.md +0 -0
  60. {graphify_php-0.0.5 → graphify_php-0.0.6}/docs/assets/css/style.scss +0 -0
  61. {graphify_php-0.0.5 → graphify_php-0.0.6}/docs/evaluation.md +0 -0
  62. {graphify_php-0.0.5 → graphify_php-0.0.6}/docs/index.md +0 -0
  63. {graphify_php-0.0.5 → graphify_php-0.0.6}/docs/phpstan.md +0 -0
  64. {graphify_php-0.0.5 → graphify_php-0.0.6}/eval/README.md +0 -0
  65. {graphify_php-0.0.5 → graphify_php-0.0.6}/eval/__init__.py +0 -0
  66. {graphify_php-0.0.5 → graphify_php-0.0.6}/eval/canaries.py +0 -0
  67. {graphify_php-0.0.5 → graphify_php-0.0.6}/eval/fixtures/chained.php +0 -0
  68. {graphify_php-0.0.5 → graphify_php-0.0.6}/eval/fixtures/ctor_body_assign.php +0 -0
  69. {graphify_php-0.0.5 → graphify_php-0.0.6}/eval/fixtures/declared_property.php +0 -0
  70. {graphify_php-0.0.5 → graphify_php-0.0.6}/eval/fixtures/dynamic.php +0 -0
  71. {graphify_php-0.0.5 → graphify_php-0.0.6}/eval/fixtures/handler_shapes.php +0 -0
  72. {graphify_php-0.0.5 → graphify_php-0.0.6}/eval/fixtures/inheritance.php +0 -0
  73. {graphify_php-0.0.5 → graphify_php-0.0.6}/eval/fixtures/interfaces.php +0 -0
  74. {graphify_php-0.0.5 → graphify_php-0.0.6}/eval/fixtures/locals_new.php +0 -0
  75. {graphify_php-0.0.5 → graphify_php-0.0.6}/eval/fixtures/mail.php +0 -0
  76. {graphify_php-0.0.5 → graphify_php-0.0.6}/eval/fixtures/nullable_union.php +0 -0
  77. {graphify_php-0.0.5 → graphify_php-0.0.6}/eval/fixtures/promoted.php +0 -0
  78. {graphify_php-0.0.5 → graphify_php-0.0.6}/eval/fixtures/same_name_traps.php +0 -0
  79. {graphify_php-0.0.5 → graphify_php-0.0.6}/eval/fixtures/secrets.php +0 -0
  80. {graphify_php-0.0.5 → graphify_php-0.0.6}/eval/fixtures/services.yaml +0 -0
  81. {graphify_php-0.0.5 → graphify_php-0.0.6}/eval/fixtures/traits.php +0 -0
  82. {graphify_php-0.0.5 → graphify_php-0.0.6}/eval/reference_set.py +0 -0
  83. {graphify_php-0.0.5 → graphify_php-0.0.6}/eval/score.py +0 -0
  84. {graphify_php-0.0.5 → graphify_php-0.0.6}/php/autoload.php +0 -0
  85. {graphify_php-0.0.5 → graphify_php-0.0.6}/php/src/CallGraph/CallEdgeWriter.php +0 -0
  86. {graphify_php-0.0.5 → graphify_php-0.0.6}/php/src/CallGraph/JsonLinesWriter.php +0 -0
  87. {graphify_php-0.0.5 → graphify_php-0.0.6}/pyproject.toml +0 -0
  88. {graphify_php-0.0.5 → graphify_php-0.0.6}/src/graphify_php/config/__init__.py +0 -0
  89. {graphify_php-0.0.5 → graphify_php-0.0.6}/src/graphify_php/config/class_lookup.py +0 -0
  90. {graphify_php-0.0.5 → graphify_php-0.0.6}/src/graphify_php/config/discovery.py +0 -0
  91. {graphify_php-0.0.5 → graphify_php-0.0.6}/src/graphify_php/config/document.py +0 -0
  92. {graphify_php-0.0.5 → graphify_php-0.0.6}/src/graphify_php/config/emit.py +0 -0
  93. {graphify_php-0.0.5 → graphify_php-0.0.6}/src/graphify_php/config/environment.py +0 -0
  94. {graphify_php-0.0.5 → graphify_php-0.0.6}/src/graphify_php/config/facts.py +0 -0
  95. {graphify_php-0.0.5 → graphify_php-0.0.6}/src/graphify_php/config/messaging.py +0 -0
  96. {graphify_php-0.0.5 → graphify_php-0.0.6}/src/graphify_php/config/ports.py +0 -0
  97. {graphify_php-0.0.5 → graphify_php-0.0.6}/src/graphify_php/config/safe_yaml.py +0 -0
  98. {graphify_php-0.0.5 → graphify_php-0.0.6}/src/graphify_php/container/__init__.py +0 -0
  99. {graphify_php-0.0.5 → graphify_php-0.0.6}/src/graphify_php/container/facts.py +0 -0
  100. {graphify_php-0.0.5 → graphify_php-0.0.6}/src/graphify_php/container/layer.py +0 -0
  101. {graphify_php-0.0.5 → graphify_php-0.0.6}/src/graphify_php/container/locator.py +0 -0
  102. {graphify_php-0.0.5 → graphify_php-0.0.6}/src/graphify_php/container/overlay.py +0 -0
  103. {graphify_php-0.0.5 → graphify_php-0.0.6}/src/graphify_php/container/ports.py +0 -0
  104. {graphify_php-0.0.5 → graphify_php-0.0.6}/src/graphify_php/container/reader.py +0 -0
  105. {graphify_php-0.0.5 → graphify_php-0.0.6}/src/graphify_php/container/reasons.py +0 -0
  106. {graphify_php-0.0.5 → graphify_php-0.0.6}/src/graphify_php/sources/route_source.py +0 -0
  107. {graphify_php-0.0.5 → graphify_php-0.0.6}/src/graphify_php/syntax/call_sites.py +0 -0
  108. {graphify_php-0.0.5 → graphify_php-0.0.6}/src/graphify_php/syntax/class_index.py +0 -0
  109. {graphify_php-0.0.5 → graphify_php-0.0.6}/src/graphify_php/syntax/file_scan.py +0 -0
  110. {graphify_php-0.0.5 → graphify_php-0.0.6}/src/graphify_php/syntax/names.py +0 -0
  111. {graphify_php-0.0.5 → graphify_php-0.0.6}/src/graphify_php/syntax/nodes.py +0 -0
  112. {graphify_php-0.0.5 → graphify_php-0.0.6}/src/graphify_php/syntax/routes.py +0 -0
  113. {graphify_php-0.0.5 → graphify_php-0.0.6}/tests/fixtures/shrink/ckeditor/new_graph.json +0 -0
  114. {graphify_php-0.0.5 → graphify_php-0.0.6}/tests/fixtures/shrink/ckeditor/new_manifest.json +0 -0
  115. {graphify_php-0.0.5 → graphify_php-0.0.6}/tests/fixtures/shrink/ckeditor/old_graph.json +0 -0
  116. {graphify_php-0.0.5 → graphify_php-0.0.6}/tests/fixtures/shrink/ckeditor/old_manifest.json +0 -0
  117. {graphify_php-0.0.5 → graphify_php-0.0.6}/tests/fixtures/shrink/ckeditor/present.txt +0 -0
  118. {graphify_php-0.0.5 → graphify_php-0.0.6}/tests/fixtures/shrink/games/new_graph.json +0 -0
  119. {graphify_php-0.0.5 → graphify_php-0.0.6}/tests/fixtures/shrink/games/new_manifest.json +0 -0
  120. {graphify_php-0.0.5 → graphify_php-0.0.6}/tests/fixtures/shrink/games/old_graph.json +0 -0
  121. {graphify_php-0.0.5 → graphify_php-0.0.6}/tests/fixtures/shrink/games/old_manifest.json +0 -0
  122. {graphify_php-0.0.5 → graphify_php-0.0.6}/tests/fixtures/shrink/games/present.txt +0 -0
  123. {graphify_php-0.0.5 → graphify_php-0.0.6}/tests/test_cli_end_to_end.py +0 -0
  124. {graphify_php-0.0.5 → graphify_php-0.0.6}/tests/test_config_readers.py +0 -0
  125. {graphify_php-0.0.5 → graphify_php-0.0.6}/tests/test_container_integration.py +0 -0
  126. {graphify_php-0.0.5 → graphify_php-0.0.6}/tests/test_container_layer.py +0 -0
  127. {graphify_php-0.0.5 → graphify_php-0.0.6}/tests/test_container_overlay.py +0 -0
  128. {graphify_php-0.0.5 → graphify_php-0.0.6}/tests/test_container_reader.py +0 -0
  129. {graphify_php-0.0.5 → graphify_php-0.0.6}/tests/test_eval_canaries.py +0 -0
  130. {graphify_php-0.0.5 → graphify_php-0.0.6}/tests/test_eval_reference_set.py +0 -0
  131. {graphify_php-0.0.5 → graphify_php-0.0.6}/tests/test_eval_score.py +0 -0
  132. {graphify_php-0.0.5 → graphify_php-0.0.6}/tests/test_syntax_routes.py +0 -0
@@ -17,19 +17,18 @@ jobs:
17
17
  fetch-depth: 0
18
18
 
19
19
  - name: gitleaks — scan git history for hardcoded secrets
20
- # Plain OSS gitleaks CLI, not gitleaks/gitleaks-action: that Action now
21
- # requires a paid GITLEAKS_LICENSE for GitHub Organizations. The CLI
22
- # itself stays free/open-source.
23
- # The sha256 below is pinned from the official release checksums file:
24
- # https://github.com/gitleaks/gitleaks/releases/download/v8.30.1/gitleaks_8.30.1_checksums.txt
25
- # .gitleaks.toml at the repository root extends the default rules with
26
- # a path allowlist for the planted canaries (see that file).
27
- run: |
28
- curl -sSfL -o gitleaks_8.30.1_linux_x64.tar.gz \
29
- https://github.com/gitleaks/gitleaks/releases/download/v8.30.1/gitleaks_8.30.1_linux_x64.tar.gz
30
- echo "551f6fc83ea457d62a0d98237cbad105af8d557003051f41f3e7ca7b3f2470eb gitleaks_8.30.1_linux_x64.tar.gz" | sha256sum -c -
31
- tar -xzf gitleaks_8.30.1_linux_x64.tar.gz gitleaks
32
- ./gitleaks detect --source . --no-banner --redact
20
+ # gitleaks-action needs a GITLEAKS_LICENSE only for repositories owned
21
+ # by a GitHub Organization; OxCom is a personal account, so none is set.
22
+ # A push scans the pushed commits; the nightly schedule and a manual
23
+ # dispatch scan the full history. The action runs `gitleaks detect
24
+ # --redact` and picks up .gitleaks.toml at the repository root, which
25
+ # allowlists the planted canaries (see that file).
26
+ uses: gitleaks/gitleaks-action@e0c47f4f8be36e29cdc102c57e68cb5cbf0e8d1e # v3.0.0
27
+ env:
28
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
29
+ GITLEAKS_VERSION: "8.30.1"
30
+ # PR comments need pull-requests: write; this job keeps contents: read.
31
+ GITLEAKS_ENABLE_COMMENTS: "false"
33
32
 
34
33
  trufflehog:
35
34
  runs-on: ubuntu-latest
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: graphify-php
3
- Version: 0.0.5
3
+ Version: 0.0.6
4
4
  Summary: PHP member-call resolution for graphify: binds $this->service->method() to the method node it calls.
5
5
  Author: Andrii Afanasiev
6
6
  License-Expression: Apache-2.0
@@ -52,7 +52,7 @@ shared namespace would break when graphify adds a flag the wrapper already uses.
52
52
  | Flag | Default | Meaning |
53
53
  |---|---|---|
54
54
  | `--graph PATH` | `$GRAPHIFY_OUT/graph.json` | Graph artifact to protect |
55
- | `--expect RESOLVER` | `php_member_calls`, `php_routes`, `php_symfony_config` | Resolver that must report. Repeatable. Any `--expect` replaces the whole default list |
55
+ | `--expect RESOLVER` | `php_member_calls`, `php_routes`, `php_symfony_config`, `php_core_guard` | Resolver that must report. Repeatable. Any `--expect` replaces the whole default list |
56
56
  | `-h`, `--help` | | Print help. Works without graphify installed |
57
57
 
58
58
  ## Exit codes
@@ -92,7 +92,57 @@ the second of three resolvers still leaves the first two on disk. An entry holds
92
92
  Counters always carry the denominator. "Resolved 400 calls" means nothing without "out of how
93
93
  many", and a regression that halves coverage still produces a large number.
94
94
 
95
+ The member-call record (`php_member_calls`) adds these fields:
96
+
97
+ | Field | Meaning |
98
+ |---|---|
99
+ | `unsent_calls_added` | Edges added for member calls graphify never sent. Not part of `resolved_sites` |
100
+ | `nullsafe_sites_total`, `nullsafe_calls_added` | `?->` calls a parser found, and how many got a target into the graph |
101
+ | `engine_sites_total` | Edges graphify's engine bound by bare name inside the caller's file (the denominator) |
102
+ | `engine_contradicted`, `engine_dropped`, `engine_dropped_interface` | Edges a PHPStan record contradicted, edges dropped, and drops that rested on an interface target |
103
+ | `engine_proved_added` | Proved edges added in place of the dropped ones |
104
+ | `engine_kept` | Reason to count for each edge kept. Dropped plus kept equals the total |
105
+ | `engine_dropped_edges` | One row per dropped edge: `source`, `target`, `relation`, `reason`, `proof` |
106
+ | `new_site_edges_total`, `new_site_edges_dropped`, `new_site_kept` | Edges graphify's cross-file pass bound from `new X(...)` to a method of that name, how many were dropped, and the reasons for the rest |
107
+ | `new_site_dropped_edges` | One row per dropped edge. Audit only, not in the sidecar |
108
+ | `external_stubs` | `on` or `off`, the stub decision of this build |
109
+
110
+ The engine and `new X(...)` passes remove edges only on a full build, where graphify hands over
111
+ its own edge list. On an incremental build they remove and add nothing. `unresolved` also carries
112
+ `engine:`-prefixed and `nullsafe:`-prefixed reasons for sites the passes refused.
113
+
114
+ The `php_core_guard` record adds `core_sites_total`, `suppressed_sites`, `proved_not_found`,
115
+ `suppressed_edges` (edges core's dry run would have added at proved sites),
116
+ `suppressed_edges_listed`, `suppressed_unlisted` (reason to count), `suppressed_edge_rows` and
117
+ `dry_run_seconds`.
118
+
95
119
  The unit of an `unresolved` count depends on the reason. Source reasons count sites. `probe:`
96
120
  reasons count candidate names. `scoped_method_*` reasons count scoped groups. The graph-lookup
97
121
  reasons `target_not_in_graph` and `self_call` count target records, so a two-arm site can appear
98
122
  twice.
123
+
124
+ ## Attribution sidecar
125
+
126
+ After the resolver gate passes, `graphify-php-build` writes `.graphify-php-attribution.json` next
127
+ to the status record (the same directory, so `GRAPHIFY_PHP_STATUS` moves both). It lists the edges
128
+ this package removed on purpose: core edges withheld at a proved site
129
+ (`core-suppressed-at-proved-site`) and engine edges a proof contradicts
130
+ (`engine-contradicts-proof`). Each row has `source`, `target`, `relation`, `reason` and the proof
131
+ edge. It also records `external_stubs`. The schema is in the `src/graphify_php/shrink.py`
132
+ docstring. A sidecar left by an earlier build is deleted before the build starts. A write that
133
+ fails is reported on stderr and never fails the build.
134
+
135
+ The shrink guard counts a lost edge as attributed only when the new graph confirms the proof edge,
136
+ and caps each reason at its count. A missing or malformed sidecar attributes nothing, so the
137
+ guard is stricter, not looser.
138
+
139
+ ## Shrink check
140
+
141
+ ```bash
142
+ graphify-shrink-check --old-graph P --new-graph P --old-manifest P --new-manifest P --root DIR \
143
+ [--policy NAME] [--tolerance X] [--producer-changed] [--attribution PATH]
144
+ ```
145
+
146
+ `--attribution PATH` points at the sidecar. Without it nothing is attributed. The JSON report
147
+ gains `attributed` (reason to count) and `attributed_total`, and
148
+ `lost = explained + unexplained + resolver_lost + attributed_total` for edges.
@@ -133,7 +133,7 @@ composer require --dev phpstan/phpstan
133
133
  ```
134
134
 
135
135
  Exit code `0` means every expected resolver reported. The record lists `php_member_calls`,
136
- `php_routes` and `php_symfony_config`. Each has a `state` of `completed`, or `skipped` with a
136
+ `php_routes`, `php_symfony_config` and `php_core_guard`. Each has a `state` of `completed`, or `skipped` with a
137
137
  `reason`. Under `php_member_calls`, `resolved_sites` out of `eligible_sites` is the coverage
138
138
  figure.
139
139
 
@@ -30,8 +30,10 @@ graphify_php.register()
30
30
  ```
31
31
 
32
32
  `register()` adds three resolvers to graphify's resolver registry: `php_member_calls`,
33
- `php_routes` and `php_symfony_config`. It is idempotent by name. It imports graphify lazily, so
34
- importing the package never requires graphify.
33
+ `php_routes` and `php_symfony_config`. It also replaces graphify core's own `php_member_calls`
34
+ entry with a filter that withholds the call sites graphify-php proved and reports as
35
+ `php_core_guard`. It is idempotent. It imports graphify lazily, so importing the package never
36
+ requires graphify.
35
37
 
36
38
  `graphify-php-build` calls `register()` for you. Call it yourself only when you drive graphify
37
39
  from your own Python code.
@@ -54,9 +54,19 @@ Verified against PHPStan 2.2.8 on PHP 8.4.
54
54
  in the working directory. One JSON object per line:
55
55
 
56
56
  ```json
57
- {"callerClass":"App\\Controller","callerMethod":"run","calleeClass":"App\\Mailer","calleeMethod":"send","calleeKind":"interface","line":21,"file":"/srv/app/src/Controller.php","callPos":148,"calleeFile":"/srv/app/src/Mailer.php"}
57
+ {"callerClass":"App\\Controller","callerMethod":"run","calleeClass":"App\\Mailer","calleeMethod":"send","calleeKind":"interface","line":21,"file":"/srv/app/src/Controller.php","callPos":148,"calleeFile":"/srv/app/src/Mailer.php","callerFile":"/srv/app/src/Controller.php"}
58
58
  ```
59
59
 
60
+ `file` and `line` locate the call: the file that holds the body it sits in. `callerClass` and
61
+ `callerMethod` name the method the body was analysed as, and `callerFile` is the file of
62
+ `callerClass`. The two files differ only for a trait body. PHPStan analyses a trait method once
63
+ per class using it, so one call in `src/T.php` yields one record per using class, each with
64
+ `file` `src/T.php`, `callerClass` the using class, and `callerFile` that class's file.
65
+ `callerMethod` is then the name the trait declares. An alias (`use T { run as traitRun; }`) is
66
+ mapped back to `run`, and a body whose name cannot be mapped (an alias set by an intermediate
67
+ trait) produces no record. A class that overrides the trait method never runs the trait body,
68
+ and PHPStan does not analyse it there.
69
+
60
70
  `callPos` is the token offset of the called method's name, `-1` when the parser did not record
61
71
  one. A union receiver (`Emails|Cache`) yields one record per arm with the same `callPos`; two
62
72
  calls of one method on one line yield different values, so a consumer can tell the two apart.
@@ -85,6 +95,9 @@ produce no record:
85
95
  from a typed constructor parameter: PHPStan reports `missingType.property` rather than
86
96
  inferring it. Give the property a native type or a `@var` docblock and the call resolves.
87
97
  - a dynamic method name, `$obj->$method()`;
98
+ - a call outside any class method (a function body), since there is no class to name;
99
+ - a call in a trait method reached through an alias the using class's own alias table does not
100
+ map back to the trait;
88
101
  - a receiver on a class the analysis cannot load;
89
102
  - an intersection receiver (`A&B`) whose constituents resolve to more than one declaring class
90
103
  for the method. One object, two declarations: the type does not say which body runs, so
@@ -94,9 +107,12 @@ produce no record:
94
107
  emits nothing. The parser layer is stricter there and refuses `(A&B)|C` wholesale as
95
108
  `union-type`.
96
109
 
97
- Also out of scope in this version, by omission rather than by refusal: `?->` nullsafe calls,
98
- `Foo::bar()` static calls, and `new Foo` construction edges. Each is a different node type and
99
- would be a second collector.
110
+ A nullsafe call `$x?->m()` is recorded by the same collector: PHPStan hands it a `MethodCall` for
111
+ it too. The `null` arm of `?Foo` has no class reflection, so it is dropped and `Foo` is kept.
112
+
113
+ Also out of scope in this version, by omission rather than by refusal: `Foo::bar()` static
114
+ calls and `new Foo` construction edges. Each is a different node type and would be a second
115
+ collector.
100
116
 
101
117
  ## Cost
102
118
 
@@ -27,6 +27,7 @@ final class CallEdge
27
27
  private readonly string $file,
28
28
  private readonly int $callPos,
29
29
  private readonly string $calleeFile,
30
+ private readonly string $callerFile = '',
30
31
  ) {
31
32
  }
32
33
 
@@ -50,10 +51,15 @@ final class CallEdge
50
51
  }
51
52
 
52
53
  /**
54
+ * `$contextFile` is the file the analyser was in. It is the body's file too, except for a
55
+ * trait body: the collector then names the trait's file, and the class's file is kept apart.
56
+ *
53
57
  * @param array<string, mixed> $raw
54
58
  */
55
- public static function fromArray(array $raw, string $file): self
59
+ public static function fromArray(array $raw, string $contextFile): self
56
60
  {
61
+ $file = (string) ($raw['file'] ?? '');
62
+
57
63
  return new self(
58
64
  (string) ($raw['callerClass'] ?? ''),
59
65
  (string) ($raw['callerMethod'] ?? ''),
@@ -61,9 +67,10 @@ final class CallEdge
61
67
  (string) ($raw['calleeMethod'] ?? ''),
62
68
  (string) ($raw['calleeKind'] ?? self::RECEIVER_CLASS),
63
69
  (int) ($raw['line'] ?? 0),
64
- $file,
70
+ $file !== '' ? $file : $contextFile,
65
71
  (int) ($raw['callPos'] ?? -1),
66
72
  (string) ($raw['calleeFile'] ?? ''),
73
+ $contextFile,
67
74
  );
68
75
  }
69
76
 
@@ -86,6 +93,9 @@ final class CallEdge
86
93
  // Where the declaring class lives, '' for a built-in. The consumer tells a vendor
87
94
  // class from a project class by this path, never by guessing from the namespace.
88
95
  'calleeFile' => $this->calleeFile,
96
+ // The file of the class the body was analysed in. Equal to `file` except for a trait
97
+ // body, which is analysed once per using class; a consumer must not place it there.
98
+ 'callerFile' => $this->callerFile,
89
99
  ];
90
100
  }
91
101
  }
@@ -51,8 +51,8 @@ final class CallEdgeRule implements Rule
51
51
  foreach ($node->get(MethodCallCollector::class) as $file => $perNode) {
52
52
  foreach ($perNode as $records) {
53
53
  foreach ($records as $record) {
54
- // The file comes from the key rather than from the record: the analyser owns
55
- // path normalisation, and a second copy would drift from it.
54
+ // The key is the file the analyser was in. For a trait body that is the using
55
+ // class's file, not the body's, so a file set by the collector wins over it.
56
56
  yield CallEdge::fromArray($record, (string) $file);
57
57
  }
58
58
  }
@@ -27,6 +27,9 @@ use PHPStan\Type\UnionType;
27
27
  * A name-only fallback — matching `->get()` to any class owning a `get` — manufactures edges
28
28
  * that look identical to real ones, and a wrong edge is worse than a missing one.
29
29
  *
30
+ * A nullsafe `$x?->m()` needs no collector of its own: PHPStan hands this one a `MethodCall` for
31
+ * it too, with the receiver's type including `null`, whose arm has no class reflection and drops.
32
+ *
30
33
  * @implements Collector<MethodCall, list<array<string, mixed>>>
31
34
  */
32
35
  final class MethodCallCollector implements Collector
@@ -58,6 +61,21 @@ final class MethodCallCollector implements Collector
58
61
  return null;
59
62
  }
60
63
 
64
+ // A trait body is analysed once per using class, and the analyser's file is that class's
65
+ // file while the line is the trait's. The record names the trait's file and method, so
66
+ // file, line and method describe one body; the rule keeps the class's file as callerFile.
67
+ $file = '';
68
+
69
+ if ($scope->isInTrait()) {
70
+ $trait = $scope->getTraitReflection();
71
+ $callerMethod = $this->traitMethodName($callerClass, $trait, $callerMethod);
72
+ $file = (string) $trait->getFileName();
73
+
74
+ if ($callerMethod === null || $file === '') {
75
+ return null;
76
+ }
77
+ }
78
+
61
79
  $methodName = $node->name->toString();
62
80
  $receiverType = $scope->getType($node->var);
63
81
  $edges = [];
@@ -69,7 +87,7 @@ final class MethodCallCollector implements Collector
69
87
  $arms = $receiverType instanceof UnionType ? $receiverType->getTypes() : [$receiverType];
70
88
 
71
89
  foreach ($arms as $arm) {
72
- foreach ($this->armEdges($arm, $methodName, $callerClass->getName(), $callerMethod, $node, $scope) as $record) {
90
+ foreach ($this->armEdges($arm, $methodName, $callerClass->getName(), $callerMethod, $file, $node, $scope) as $record) {
73
91
  $edges[] = $record;
74
92
  }
75
93
  }
@@ -81,6 +99,32 @@ final class MethodCallCollector implements Collector
81
99
  return $edges;
82
100
  }
83
101
 
102
+ /**
103
+ * The name the trait itself gives the method being analysed, or null when it cannot be told.
104
+ *
105
+ * `use T { run as traitRun; }` analyses T's `run` under the name `traitRun`, which no
106
+ * declaration in the trait's file carries. An alias set by an intermediate trait is not in
107
+ * the class's alias table, so it is refused rather than guessed.
108
+ */
109
+ private function traitMethodName(ClassReflection $class, ClassReflection $trait, string $analysed): ?string
110
+ {
111
+ foreach ($class->getNativeReflection()->getTraitAliases() as $alias => $original) {
112
+ if (strcasecmp($alias, $analysed) !== 0) {
113
+ continue;
114
+ }
115
+
116
+ $parts = explode('::', $original, 2);
117
+
118
+ if (count($parts) !== 2 || strcasecmp(ltrim($parts[0], '\\'), $trait->getName()) !== 0) {
119
+ return null;
120
+ }
121
+
122
+ return $parts[1];
123
+ }
124
+
125
+ return $trait->hasNativeMethod($analysed) ? $analysed : null;
126
+ }
127
+
84
128
  /**
85
129
  * The records for one arm of the receiver type, or none when the arm is ambiguous.
86
130
  *
@@ -96,6 +140,7 @@ final class MethodCallCollector implements Collector
96
140
  string $methodName,
97
141
  string $callerClass,
98
142
  string $callerMethod,
143
+ string $file,
99
144
  MethodCall $node,
100
145
  Scope $scope,
101
146
  ): array {
@@ -103,7 +148,7 @@ final class MethodCallCollector implements Collector
103
148
  $declaringClasses = [];
104
149
 
105
150
  foreach ($arm->getObjectClassReflections() as $receiver) {
106
- $edge = $this->edgeTo($receiver, $methodName, $callerClass, $callerMethod, $node, $scope);
151
+ $edge = $this->edgeTo($receiver, $methodName, $callerClass, $callerMethod, $file, $node, $scope);
107
152
 
108
153
  if ($edge === null) {
109
154
  continue;
@@ -129,6 +174,7 @@ final class MethodCallCollector implements Collector
129
174
  string $methodName,
130
175
  string $callerClass,
131
176
  string $callerMethod,
177
+ string $file,
132
178
  MethodCall $node,
133
179
  Scope $scope,
134
180
  ): ?CallEdge {
@@ -153,7 +199,7 @@ final class MethodCallCollector implements Collector
153
199
  $methodName,
154
200
  $declaring->isInterface(),
155
201
  $node->getStartLine(),
156
- '',
202
+ $file,
157
203
  // The method name's token, not the expression's: in a chain `$a->get()->get()` every
158
204
  // link starts at `$a`, and the name is the one token each call owns alone.
159
205
  $node->name->getStartTokenPos(),
@@ -20,6 +20,7 @@ from __future__ import annotations
20
20
  from collections.abc import Sequence
21
21
  from importlib import import_module
22
22
 
23
+ from . import core_guard
23
24
  from .ports import CallTargetSource
24
25
  from .resolver import (
25
26
  PHP_SUFFIXES,
@@ -37,7 +38,9 @@ __all__ = [
37
38
  "register",
38
39
  ]
39
40
 
40
- _registered = False
41
+ # Set on every resolve callable this package registers. A marker rather than `__module__`, so
42
+ # the package imported under a second module path still recognises its own registrations.
43
+ _OWNED = core_guard.OWNED
41
44
 
42
45
 
43
46
  def default_sources(repo_root: str = ".") -> Sequence[CallTargetSource]:
@@ -103,42 +106,43 @@ def register(
103
106
  repo_root: str = ".",
104
107
  route_sources_factory=default_route_sources,
105
108
  ) -> bool:
106
- """Register the PHP resolver with graphify. Returns whether this call did the registering.
109
+ """Register the PHP passes with graphify. Returns whether this call registered any of them.
107
110
 
108
- Idempotent by name rather than by a flag alone: a process that imported this package twice
109
- under two module paths would otherwise register twice, and graphify runs the registry in
110
- order without deduplicating, so the pass would run twice and the second run would find
111
- every edge already present and report zero work.
111
+ Idempotent per pass and by ownership, not by name alone: graphify runs the registry in
112
+ order without deduplicating, so a pass registered twice runs twice and the second run finds
113
+ every edge present and reports zero work. A name is not proof the pass is ours, though:
114
+ graphify 0.9.103 registers its own `php_member_calls` when `graphify.extract` is imported.
112
115
  """
113
- global _registered
114
116
  from graphify import resolver_registry
115
117
 
116
- if _registered or any(
117
- r.name == RESOLVER_NAME for r in resolver_registry.registered_resolvers()
118
- ):
119
- _registered = True
120
- return False
121
-
122
- resolver_registry.register(
123
- resolver_registry.LanguageResolver(
124
- name=RESOLVER_NAME,
125
- suffixes=PHP_SUFFIXES,
126
- resolve=make_resolver(sources_factory, repo_root),
127
- )
118
+ from . import config_resolver
119
+
120
+ ours = {
121
+ r.name
122
+ for r in resolver_registry.registered_resolvers()
123
+ if getattr(r.resolve, _OWNED, False)
124
+ }
125
+ # Routes are a second pass rather than a stage of the first: they add nodes rather than
126
+ # connect existing ones, and a separate record is one the build gate can require. The
127
+ # Symfony configuration pass is listed here because a pass left out of here never runs.
128
+ passes = (
129
+ (RESOLVER_NAME, lambda: make_resolver(sources_factory, repo_root)),
130
+ (RESOLVER_NAME_ROUTES, lambda: make_route_resolver(route_sources_factory, repo_root)),
131
+ (config_resolver.RESOLVER_NAME, lambda: config_resolver.make_resolver(repo_root)),
128
132
  )
129
- # A second pass, not a stage of the first: routes add nodes rather than connect existing
130
- # ones, and a separate registration gives them a status record the build gate can require.
131
- resolver_registry.register(
132
- resolver_registry.LanguageResolver(
133
- name=RESOLVER_NAME_ROUTES,
134
- suffixes=PHP_SUFFIXES,
135
- resolve=make_route_resolver(route_sources_factory, repo_root),
133
+ registered = False
134
+ for name, build in passes:
135
+ if name in ours:
136
+ continue
137
+ resolve = build()
138
+ setattr(resolve, _OWNED, True)
139
+ resolver_registry.register(
140
+ resolver_registry.LanguageResolver(name=name, suffixes=PHP_SUFFIXES, resolve=resolve)
136
141
  )
137
- )
138
- # The Symfony configuration pass. Registered here because this is the one registration a
139
- # build makes; a pass left out of it never runs, however complete its own `register` is.
140
- from . import config_resolver
142
+ registered = True
141
143
 
142
- config_resolver.register(repo_root)
143
- _registered = True
144
- return True
144
+ # Imported after ours are in: a first import appends core's PHP pass behind them, and the
145
+ # guard needs it present to filter it. Core running first is caught by the guard itself.
146
+ import_module("graphify.extract")
147
+ core_guard.install(resolver_registry)
148
+ return registered
@@ -28,6 +28,7 @@ Exit codes:
28
28
  from __future__ import annotations
29
29
 
30
30
  import argparse
31
+ import json
31
32
  import os
32
33
  import shutil
33
34
  import sys
@@ -36,6 +37,7 @@ from pathlib import Path
36
37
 
37
38
  from . import shrink, shrink_cli, status
38
39
  from .config_resolver import RESOLVER_NAME as RESOLVER_NAME_CONFIG
40
+ from .core_guard import RESOLVER_NAME as RESOLVER_NAME_CORE_GUARD
39
41
  from .resolver import RESOLVER_NAME, RESOLVER_NAME_ROUTES
40
42
 
41
43
  EXIT_OK = 0
@@ -171,13 +173,34 @@ def main(
171
173
  print(version_line())
172
174
  return EXIT_OK
173
175
  opts = _parser().parse_args(ours)
174
- expected = opts.expect or [RESOLVER_NAME, RESOLVER_NAME_ROUTES, RESOLVER_NAME_CONFIG]
176
+ # The guard reports on every PHP build in every outcome, so its silence means core's PHP
177
+ # pass may have run unfiltered over sites graphify-php proved.
178
+ expected = opts.expect or [
179
+ RESOLVER_NAME,
180
+ RESOLVER_NAME_ROUTES,
181
+ RESOLVER_NAME_CONFIG,
182
+ RESOLVER_NAME_CORE_GUARD,
183
+ ]
175
184
  graph = opts.graph or default_graph_path()
176
185
 
186
+ if passthrough[:1] == ["update"] and "--force" not in passthrough:
187
+ # Incremental `update` feeds resolvers raw calls from changed files only (graphify
188
+ # extract.py: "raw_calls come solely from `paths`"), so unchanged callers keep stale
189
+ # edges. `--force` also waives graphify's shrink check; ours or graphify-mesh's judges.
190
+ passthrough = [*passthrough, "--force"]
191
+ print(
192
+ "graphify-php-build: running graphify update with --force: incremental update does "
193
+ "not re-resolve PHP calls from unchanged files",
194
+ file=sys.stderr,
195
+ )
196
+
177
197
  # A record from an earlier build would satisfy this build's gate, which is the one failure
178
198
  # the gate exists to catch. Start from nothing so silence stays visible as silence.
179
199
  record_path = status.status_path()
180
200
  record_path.unlink(missing_ok=True)
201
+ # The attribution sidecar is this build's record too: one left by an earlier build would
202
+ # explain loss this build never recorded.
203
+ shrink.attribution_path(record_path).unlink(missing_ok=True)
181
204
 
182
205
  backup = graph.with_suffix(graph.suffix + ".graphify-php-prev")
183
206
  had_previous = graph.exists()
@@ -205,6 +228,9 @@ def main(
205
228
  except Exception as exc: # a record the gate cannot read is a record that proves nothing
206
229
  code, message = EXIT_RESOLVER_MISSING, f"status record unreadable: {exc}"
207
230
  if code == EXIT_OK:
231
+ # Before the shrink gate, and so before its managed skip: graphify-mesh runs the same
232
+ # check out of process and reads this file too.
233
+ write_attribution(status.read())
208
234
  return _shrink_gate(
209
235
  graph,
210
236
  backup if had_previous else None,
@@ -231,6 +257,94 @@ def main(
231
257
  left.unlink(missing_ok=True)
232
258
 
233
259
 
260
+ # Where each removal reason's rows come from: (resolver record, its row field).
261
+ _ROW_SOURCES = (
262
+ (RESOLVER_NAME_CORE_GUARD, "suppressed_edge_rows", shrink.REASON_CORE_SUPPRESSED),
263
+ (RESOLVER_NAME, "engine_dropped_edges", shrink.REASON_ENGINE_CONTRADICTS),
264
+ )
265
+
266
+
267
+ def _row(entry: object, reason: str) -> dict | None:
268
+ """The sidecar row for a status row, or None when it cannot be attributed.
269
+
270
+ The reader ignores the whole sidecar on one malformed row, so a row is checked here: a
271
+ `proof.target` of None (the proved body has no node) can never be confirmed, and leaves.
272
+ """
273
+ if not isinstance(entry, dict) or entry.get("reason") != reason:
274
+ return None
275
+ proof = entry.get("proof")
276
+ if not isinstance(proof, dict):
277
+ return None
278
+ fields = [entry.get(k) for k in ("source", "target", "relation")]
279
+ cited = [proof.get("source"), proof.get("target")]
280
+ if not all(isinstance(v, str) and v for v in fields + cited) or cited[0] != fields[0]:
281
+ return None
282
+ source, target, relation = fields
283
+ return {
284
+ "source": source,
285
+ "target": target,
286
+ "relation": relation,
287
+ "reason": reason,
288
+ "proof": {"source": cited[0], "target": cited[1]},
289
+ }
290
+
291
+
292
+ def attribution_document(record: dict) -> dict:
293
+ """The attribution sidecar (shrink.py, schema 1) for this build's status record.
294
+
295
+ Rows come only from a resolver that `completed`. `external_stubs` is the decision the
296
+ member-call record states. A record that states none gives "on", under which the guard
297
+ attributes no stub loss.
298
+ """
299
+ resolvers = {r.get("name"): r for r in (record.get("resolvers") or []) if isinstance(r, dict)}
300
+ rows: list[dict] = []
301
+ seen: set[tuple] = set()
302
+ for name, key, reason in _ROW_SOURCES:
303
+ entry = resolvers.get(name) or {}
304
+ if entry.get("state") != "completed" or not isinstance(entry.get(key), list):
305
+ continue
306
+ for row in (_row(e, reason) for e in entry[key]):
307
+ ident = row and (row["source"], row["target"], row["relation"], reason)
308
+ if row is not None and ident not in seen:
309
+ seen.add(ident)
310
+ rows.append(row)
311
+ stubs = (resolvers.get(RESOLVER_NAME) or {}).get("external_stubs")
312
+ if stubs not in (shrink.STUBS_ON, shrink.STUBS_OFF):
313
+ stubs = shrink.STUBS_ON
314
+ return {
315
+ "schema": shrink.ATTRIBUTION_SCHEMA,
316
+ "producer": shrink.ATTRIBUTION_PRODUCER,
317
+ "external_stubs": stubs,
318
+ "removed_edges": rows,
319
+ "counts": {r: sum(row["reason"] == r for row in rows) for r in shrink.REMOVAL_REASONS},
320
+ }
321
+
322
+
323
+ def write_attribution(record: dict) -> Path | None:
324
+ """Write the sidecar next to the status record, atomically. Never fails the build.
325
+
326
+ No sidecar only makes the shrink guard stricter, so a write that fails is reported and the
327
+ build goes on to the guard.
328
+ """
329
+ path = shrink.attribution_path(status.status_path())
330
+ tmp = path.with_name(path.name + ".tmp")
331
+ try:
332
+ tmp.write_text(json.dumps(attribution_document(record), indent=2), encoding="utf-8")
333
+ os.replace(tmp, path)
334
+ return path
335
+ except Exception as exc:
336
+ try:
337
+ tmp.unlink(missing_ok=True)
338
+ except OSError:
339
+ pass
340
+ print(
341
+ f"graphify-php-build: attribution sidecar not written ({type(exc).__name__}: "
342
+ f"{exc}); the shrink guard attributes no loss",
343
+ file=sys.stderr,
344
+ )
345
+ return None
346
+
347
+
234
348
  def _restore_manifest(manifest: Path, manifest_backup: Path | None) -> None:
235
349
  """Put back the manifest that matches the graph being kept.
236
350
 
@@ -276,6 +390,9 @@ def _shrink_gate(
276
390
  policy = shrink.POLICY_COUNT
277
391
 
278
392
  try:
393
+ attribution, attribution_note = shrink.read_attribution(
394
+ shrink.attribution_path(status.status_path())
395
+ )
279
396
  report = shrink.classify_loss(
280
397
  shrink_cli.load_json(graph_backup, missing_ok=False),
281
398
  shrink_cli.load_json(graph, missing_ok=False),
@@ -284,7 +401,10 @@ def _shrink_gate(
284
401
  Path(repo_root_from(passthrough)),
285
402
  policy=policy,
286
403
  tolerance=shrink_cli.env_tolerance(),
404
+ attribution=attribution,
287
405
  )
406
+ if attribution_note:
407
+ report.reasons.append(attribution_note)
288
408
  verdict = report.verdict
289
409
  summary = (
290
410
  f"shrink guard ({policy}) refused: nodes {report.nodes['old']} -> "