From 1dffb39a9ac9a50967812fb0a3189118a54aa762 Mon Sep 17 00:00:00 2001 From: Ondrej Mirtes Date: Mon, 14 Sep 2026 12:02:05 +0200 Subject: [PATCH] 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 Claude-Session: https://claude.ai/code/session_01RM7vts9eefx5pyNFj7jRKY --- bin/functionMetadata_original.php | 2 +- bin/generate-function-metadata.php | 9 +++++++-- resources/functionMetadata.php | 4 ---- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/bin/functionMetadata_original.php b/bin/functionMetadata_original.php index 8f4eb456e53..82c316f0558 100644 --- a/bin/functionMetadata_original.php +++ b/bin/functionMetadata_original.php @@ -257,7 +257,7 @@ 'ob_get_clean' => ['hasSideEffects' => true], 'ob_get_contents' => ['hasSideEffects' => true], 'ob_get_length' => ['hasSideEffects' => true], - 'ob_get_level' => ['hasSideEffects' => true], + 'ob_get_level' => ['hasSideEffects' => false], 'ob_get_status' => ['hasSideEffects' => true], 'ob_list_handlers' => ['hasSideEffects' => true], 'output_add_rewrite_var' => ['hasSideEffects' => true], diff --git a/bin/generate-function-metadata.php b/bin/generate-function-metadata.php index f5ef1c5101c..0018406d1c6 100755 --- a/bin/generate-function-metadata.php +++ b/bin/generate-function-metadata.php @@ -18,7 +18,7 @@ $parser = (new ParserFactory())->createForNewestSupportedVersion(); $finder = new Finder(); - $finder->in(__DIR__ . '/../vendor/jetbrains/phpstorm-stubs')->files()->name('*.php'); + $finder->in(__DIR__ . '/../vendor/jetbrains/phpstorm-stubs')->exclude('tests')->files()->name('*.php'); $visitor = new class() extends NodeVisitorAbstract { @@ -69,6 +69,7 @@ public function enterNode(Node $node) 'function_exists', 'json_last_error', 'json_last_error_msg', + 'ob_get_level', ], true)) { $this->functions[] = $functionName; break 2; @@ -91,6 +92,10 @@ public function enterNode(Node $node) if (!$class instanceof Node\Stmt\ClassLike) { throw new ShouldNotHappenException($node->name->toString()); } + if (!isset($class->namespacedName)) { + // anonymous class + return null; + } $className = $class->namespacedName->toString(); foreach ($node->attrGroups as $attrGroup) { foreach ($attrGroup->attrs as $attr) { @@ -229,5 +234,5 @@ public function enterNode(Node $node) ); } - FileWriter::write(__DIR__ . '/../resources/functionMetadata.php', sprintf($template, $content)); + FileWriter::write(__DIR__ . '/../resources/functionMetadata.php', sprintf($template, $content) . "\n"); })(); diff --git a/resources/functionMetadata.php b/resources/functionMetadata.php index af546d10642..addae7ff100 100644 --- a/resources/functionMetadata.php +++ b/resources/functionMetadata.php @@ -676,10 +676,6 @@ 'Spoofchecker::__construct' => ['hasSideEffects' => false], 'StringBackedEnum::from' => ['hasSideEffects' => false], 'StringBackedEnum::tryFrom' => ['hasSideEffects' => false], - 'StubTests\\CodeStyle\\BracesOneLineFixer::getDefinition' => ['hasSideEffects' => false], - 'StubTests\\Parsers\\ExpectedFunctionArgumentsInfo::__toString' => ['hasSideEffects' => false], - 'StubTests\\StubsMetaExpectedArgumentsTest::getClassMemberFqn' => ['hasSideEffects' => false], - 'StubTests\\StubsParameterNamesTest::printParameters' => ['hasSideEffects' => false], 'Transliterator::createInverse' => ['hasSideEffects' => false], 'Transliterator::getErrorCode' => ['hasSideEffects' => false], 'Transliterator::getErrorMessage' => ['hasSideEffects' => false],