Skip to content

Conversation

@IanDelMar
Copy link
Contributor

PHPStan does not support the bracketed generic array syntax (string[]). When transforming WordPress’ @type array annotations, the visitor therefore uses a regular expression to replace Type[] patterns with array.

At present, the regex matches only a single level (Type[]) and misses nested forms (Type[][]), which also occur in the WordPress codebase. Missing these nested arrays results in invalid types like @phpstan-param array[]<int|string, array{...

This PR generalises the pattern to support multiple levels of nesting. Because the visitor derives array nesting from indentation, its behaviour is unchanged apart from correctly replacing these Type[][]… cases.

Comment on lines 113405 to 113406

This comment was marked as resolved.

@szepeviktor
Copy link
Member

Could we stop mixing array[] and array<>, and use only array<> and array{}?

@szepeviktor
Copy link
Member

array[] does not seem to be listed on https://phpstan.org/writing-php-code/phpdoc-types

@IanDelMar
Copy link
Contributor Author

These are coming from WordPress?! We are not using array[], we have to deal with array[] to build the array shapes.

@szepeviktor
Copy link
Member

szepeviktor commented Jan 23, 2026

At the end of the day wp_print_font_faces should have a 2-level array as a parameter.
array<int|string, array{ font-family: string, ... }>
Is it true?

@szepeviktor szepeviktor marked this pull request as draft January 23, 2026 21:22
@IanDelMar
Copy link
Contributor Author

IanDelMar commented Jan 23, 2026

$fonts is supposed to look like

[
	[
		[
			'font-family' => 'Font Family',
			'src' => ['src.woff2'],
			'font-style' => 'normal',
			'font-weight' => '400',
			// ...
		],
		[
			'font-family' => 'Font Family',
			'src' => ['src-700.woff2'],
			'font-style' => 'normal',
			'font-weight' => '700',
			// ...
		],
	],
    [
		[
			'font-family' => 'Other Font Family',
			'src' => ['other-src.woff2'],
			'font-style' => 'normal',
			'font-weight' => '400',
			// ...
		],
		[
			'font-family' => 'Other Font Family',
			'src' => ['other-src-700.woff2'],
			'font-style' => 'normal',
			'font-weight' => '700',
			// ...
		],
	],
];

@szepeviktor
Copy link
Member

szepeviktor commented Jan 23, 2026

I see!
So

  1. fonts
  2. families
  3. variations

Is it okay?
array<int|string, array<array{ font-family: string, ... }>>

@IanDelMar
Copy link
Contributor Author

The formatting in WordPressArg is incorrect. It is formatted using WordPressArg::formatArrayWithoutShape. I won’t be able to look into it any further today.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants