Skip to content

Commit 6f4d111

Browse files
ondrejmirtesclaude
andcommitted
Exclude phpstorm-stubs test suite from function metadata generation
The Finder in bin/generate-function-metadata.php scanned every PHP file in vendor/jetbrains/phpstorm-stubs, including the package's own tests/ directory. The latest stubs master added anonymous classes with methods there, and NameResolver does not assign namespacedName to anonymous classes, so the script died with "Call to a member function toString() on null" and the "Update PhpStorm stubs" workflow failed. Exclude tests/ from the scan and skip methods of anonymous classes. Regenerating drops four bogus StubTests\* entries that had leaked into resources/functionMetadata.php, and the generator now writes the trailing newline that .editorconfig requires. ob_get_level() was flipped to hasSideEffects => false by hand in #5909 (its level is tracked in the scope, so the call result must stay narrowable) without teaching the generator, so any regeneration would have reverted it. Add it to the list of scope-managed functions and align bin/functionMetadata_original.php, so the generated file is stable. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RM7vts9eefx5pyNFj7jRKY
1 parent 767a56f commit 6f4d111

3 files changed

Lines changed: 8 additions & 7 deletions

File tree

‎bin/functionMetadata_original.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@
257257
'ob_get_clean' => ['hasSideEffects' => true],
258258
'ob_get_contents' => ['hasSideEffects' => true],
259259
'ob_get_length' => ['hasSideEffects' => true],
260-
'ob_get_level' => ['hasSideEffects' => true],
260+
'ob_get_level' => ['hasSideEffects' => false],
261261
'ob_get_status' => ['hasSideEffects' => true],
262262
'ob_list_handlers' => ['hasSideEffects' => true],
263263
'output_add_rewrite_var' => ['hasSideEffects' => true],

‎bin/generate-function-metadata.php‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
$parser = (new ParserFactory())->createForNewestSupportedVersion();
2020
$finder = new Finder();
21-
$finder->in(__DIR__ . '/../vendor/jetbrains/phpstorm-stubs')->files()->name('*.php');
21+
$finder->in(__DIR__ . '/../vendor/jetbrains/phpstorm-stubs')->exclude('tests')->files()->name('*.php');
2222

2323
$visitor = new class() extends NodeVisitorAbstract {
2424

@@ -69,6 +69,7 @@ public function enterNode(Node $node)
6969
'function_exists',
7070
'json_last_error',
7171
'json_last_error_msg',
72+
'ob_get_level',
7273
], true)) {
7374
$this->functions[] = $functionName;
7475
break 2;
@@ -91,6 +92,10 @@ public function enterNode(Node $node)
9192
if (!$class instanceof Node\Stmt\ClassLike) {
9293
throw new ShouldNotHappenException($node->name->toString());
9394
}
95+
if (!isset($class->namespacedName)) {
96+
// anonymous class
97+
return null;
98+
}
9499
$className = $class->namespacedName->toString();
95100
foreach ($node->attrGroups as $attrGroup) {
96101
foreach ($attrGroup->attrs as $attr) {
@@ -229,5 +234,5 @@ public function enterNode(Node $node)
229234
);
230235
}
231236

232-
FileWriter::write(__DIR__ . '/../resources/functionMetadata.php', sprintf($template, $content));
237+
FileWriter::write(__DIR__ . '/../resources/functionMetadata.php', sprintf($template, $content) . "\n");
233238
})();

‎resources/functionMetadata.php‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -676,10 +676,6 @@
676676
'Spoofchecker::__construct' => ['hasSideEffects' => false],
677677
'StringBackedEnum::from' => ['hasSideEffects' => false],
678678
'StringBackedEnum::tryFrom' => ['hasSideEffects' => false],
679-
'StubTests\\CodeStyle\\BracesOneLineFixer::getDefinition' => ['hasSideEffects' => false],
680-
'StubTests\\Parsers\\ExpectedFunctionArgumentsInfo::__toString' => ['hasSideEffects' => false],
681-
'StubTests\\StubsMetaExpectedArgumentsTest::getClassMemberFqn' => ['hasSideEffects' => false],
682-
'StubTests\\StubsParameterNamesTest::printParameters' => ['hasSideEffects' => false],
683679
'Transliterator::createInverse' => ['hasSideEffects' => false],
684680
'Transliterator::getErrorCode' => ['hasSideEffects' => false],
685681
'Transliterator::getErrorMessage' => ['hasSideEffects' => false],

0 commit comments

Comments
 (0)