From 673315337ebf7d345c6341c70e8fafe1cfc9f17a Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Fri, 14 Aug 2026 09:02:34 +0400 Subject: [PATCH] Attach the deprecation version to the deprecating call `export_uses()` wrote `deprecation_version` to `$out['functions'][0]`, the first recorded function use, instead of the `_deprecated_*()` call that carries the version. That only looked correct when the deprecating call happened to be the first call in the scope, as it is in a deprecated file; whenever another call precedes it, the version was attached to that unrelated call and the deprecating call got none. Build the use record first and attach the version to it before appending. Found during the review of #262 and extracted here as a standalone change. --- lib/runner.php | 6 ++- .../phpunit/tests/export/uses/deprecated.inc | 6 +++ .../phpunit/tests/export/uses/deprecated.php | 44 +++++++++++++++++++ 3 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 tests/phpunit/tests/export/uses/deprecated.inc create mode 100644 tests/phpunit/tests/export/uses/deprecated.php diff --git a/lib/runner.php b/lib/runner.php index 1794faef..4610f374 100644 --- a/lib/runner.php +++ b/lib/runner.php @@ -1457,7 +1457,7 @@ function export_uses( array $uses ) { default: case 'functions': - $out[ $type ][] = array( + $used = array( 'name' => $name, 'line' => $element->getLineNumber(), 'end_line' => $element->getNode()->getAttribute( 'endLine' ), @@ -1475,9 +1475,11 @@ function export_uses( array $uses ) { $version = (string) $arguments[1]->value->value; } - $out[ $type ][0]['deprecation_version'] = $version; + $used['deprecation_version'] = $version; } + $out[ $type ][] = $used; + break; } } diff --git a/tests/phpunit/tests/export/uses/deprecated.inc b/tests/phpunit/tests/export/uses/deprecated.inc new file mode 100644 index 00000000..44e6a819 --- /dev/null +++ b/tests/phpunit/tests/export/uses/deprecated.inc @@ -0,0 +1,6 @@ +assertFunctionUsesFunction( + 'old_thing' + , array( + 'name' => '_deprecated_function', + 'line' => 5, + 'end_line' => 5, + 'deprecation_version' => '6.1.0', + ) + ); + } + + /** + * Test that the version isn't exported for a call preceding the deprecation. + */ + public function test_preceding_call_has_no_version() { + + $this->assertFunctionUsesFunction( + 'old_thing' + , array( + 'name' => 'do_something_first', + 'line' => 4, + 'end_line' => 4, + ) + ); + } +}