php-stubs / wordpress-stubs

Up-to-date WordPress function and class declaration stubs for static analysis by PHPStan
https://packagist.org/packages/php-stubs/wordpress-stubs
MIT License
151 stars 19 forks source link

Add @param-out for wp_parse_str() #204

Closed IanDelMar closed 3 months ago

IanDelMar commented 3 months ago

Currently, no tests have been added as PHPStan requires bleeding edge to be enabled in order not to discard the type provided via @param-out.

Assertions might look like

// tests/data/wp_parse_str.php

declare(strict_types=1);

namespace PhpStubs\WordPress\Core\Tests;

use function wp_parse_str;
use function PHPStan\Testing\assertType;

// The type of `$result` cannot be narrowed further via stubs.
wp_parse_str('key=value');
assertType('array<int|string, array|string>', $result);
wp_parse_str('key1[key2]]=value');
assertType('array<int|string, array|string>', $result);
szepeviktor commented 3 months ago

The docs say it needs a parameter name https://phpstan.org/writing-php-code/phpdocs-basics#setting-parameter-type-passed-by-reference

IanDelMar commented 3 months ago

Of course.

johnbillion commented 3 months ago

I think it's worth using the phpstan- prefix on these tag names so it's clear what they are for. Especially as this is a new phpstan feature.

johnbillion commented 3 months ago

Oh not that new actually. But still.