Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"dealerdirect/phpcodesniffer-composer-installer": "^1.0",
"nikic/php-parser": "^5.5",
"php-stubs/generator": "^0.8.3",
"phpdocumentor/reflection-docblock": "^5.4.1",
"phpdocumentor/reflection-docblock": "^6.0",
"phpstan/phpstan": "^2.1",
"phpunit/phpunit": "^9.5",
"szepeviktor/phpcs-psr-12-neutron-hybrid-ruleset": "^1.1.1",
Expand Down
7 changes: 3 additions & 4 deletions generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@ if [ ! -d vendor ]; then
composer update
fi

# Convert non-negative-int to int<0,max> in SimplePie
sed -i -e 's# non-negative-int # int<0,max> #' source/wordpress/wp-includes/SimplePie/src/File.php
sed -i -e 's# non-negative-int # int<0,max> #' source/wordpress/wp-includes/SimplePie/src/HTTP/Parser.php

# Convert psalm-incompatible callable types in Abilities API
sed -i -e 's#callable( mixed $input= )#callable(mixed=)#g' source/wordpress/wp-includes/abilities-api/class-wp-ability.php

# Fix incorrect param type in AVIF Info class
sed -i -e 's#@param binary string \$input#@param string $input#' source/wordpress/wp-includes/class-avif-info.php

# Exclude globals.
"$(dirname "$0")/vendor/bin/generate-stubs" \
--force \
Expand Down
18 changes: 13 additions & 5 deletions src/Visitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@
use StubsGenerator\NodeVisitor;
use phpDocumentor\Reflection\DocBlockFactoryInterface;
use phpDocumentor\Reflection\DocBlockFactory;

use function assert;
use function sprintf;

// phpcs:disable SlevomatCodingStandard.Functions.FunctionLength.FunctionLength,NeutronStandard.Functions.TypeHint.NoReturnType

Expand Down Expand Up @@ -215,7 +217,7 @@ private function generateAdditionalTagsFromDoc(Doc $docComment): array
return [];
}

/** @var list<\phpDocumentor\Reflection\DocBlock\Tags\Param> $paramTags*/
/** @var list<\phpDocumentor\Reflection\DocBlock\Tags\Param|\phpDocumentor\Reflection\DocBlock\Tags\InvalidTag> $paramTags*/
$paramTags = $docblock->getTagsByName('param');

/** @var list<\phpDocumentor\Reflection\DocBlock\Tags\Return_> $returnTags */
Expand All @@ -228,6 +230,10 @@ private function generateAdditionalTagsFromDoc(Doc $docComment): array
$additions = [];

foreach ($paramTags as $paramTag) {
if (! ($paramTag instanceof Param)) {
continue;
}

$addition = self::getAdditionFromParam($paramTag);

if (! ($addition instanceof WordPressTag)) {
Expand Down Expand Up @@ -308,7 +314,7 @@ static function (WordPressTag $tag): string {
*/
private function discoverInheritedArgs(DocBlock $docblock, array $additions): array
{
/** @var list<\phpDocumentor\Reflection\DocBlock\Tags\Param> $params */
/** @var list<\phpDocumentor\Reflection\DocBlock\Tags\Param|\phpDocumentor\Reflection\DocBlock\Tags\InvalidTag> $params */
$params = $docblock->getTagsByName('param');

$phpStanParams = array_filter(
Expand All @@ -319,6 +325,10 @@ static function (WordPressTag $addition): bool {
);

foreach ($params as $param) {
if (! $param instanceof Param) {
continue;
}

$inherited = $this->getInheritedTagsForParam($param);

if (count($inherited) === 0) {
Expand Down Expand Up @@ -889,9 +899,7 @@ private function cleanComments(Node $node): void
$commentText = trim($comment->getText());

// Strip out comments that are not PHPDoc comments.
if (
strpos($commentText, '/**') === false
) {
if (strpos($commentText, '/**') === false) {
continue;
}

Expand Down
6 changes: 3 additions & 3 deletions wordpress-stubs.php
Original file line number Diff line number Diff line change
Expand Up @@ -25424,7 +25424,7 @@ class File implements \SimplePie\HTTP\Response
* @deprecated Use `get_status_code()` method.
*/
public $status_code = 0;
/** @var int<0,max> Number of redirect that were already performed during this request sequence. */
/** @var non-negative-int Number of redirect that were already performed during this request sequence. */
public $redirects = 0;
/** @var ?string */
public $error;
Expand Down Expand Up @@ -25700,7 +25700,7 @@ protected function chunked()
* Prepare headers (take care of proxies headers)
*
* @param string $headers Raw headers
* @param int<0,max> $count Redirection count. Default to 1.
* @param non-negative-int $count Redirection count. Default to 1.
*
* @return string
*/
Expand Down Expand Up @@ -85251,7 +85251,7 @@ public static function render_control_template_scripts()
/**
* Reads an unsigned integer with most significant bits first.
*
* @param binary string $input Must be at least $num_bytes-long.
* @param string $input Must be at least $num_bytes-long.
* @param int $num_bytes Number of parsed bytes.
* @return int Value.
*/
Expand Down