Skip to content
Closed
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
16 changes: 16 additions & 0 deletions src/wp-includes/class-wp-block-styles-registry.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,23 @@
/**
* Class used for interacting with block styles.
*
* The properties of a block style as the registry stores them are more than its register() hash
* accepts: `name` is required for a style to be registered at all, and `label` is filled in from
* the name when the caller omits it, so both are always present on the way back out. The shape
* stays open because the array is stored verbatim, so a caller's own keys survive, including
* into the REST response, which does not set `additionalProperties` to false.
*
* @since 5.3.0
*
* @phpstan-type Block_Style_Properties array{
* name: string,
* label: string,
* inline_style?: string,
* style_handle?: string,
* is_default?: bool,
* style_data?: array<string, mixed>,
* ...
* }
*/
#[AllowDynamicProperties]
final class WP_Block_Styles_Registry {
Expand Down
4 changes: 2 additions & 2 deletions src/wp-includes/class-wp-hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ private function resort_active_iterations( $new_priority = false, $priority_exis
* a callback that may or may not exist.
* @param int $priority The exact priority used when adding the original filter callback.
* @return bool Whether the callback existed before it was removed.
* @phpstan-param Maybe_Callable $callback
* @phpstan-param callable|string|array{0: string|object, 1: string} $callback
*/
public function remove_filter( $hook_name, $callback, $priority ) {
if ( null === $priority ) {
Expand Down Expand Up @@ -249,7 +249,7 @@ public function remove_filter( $hook_name, $callback, $priority ) {
* of that hook is returned, or false if the function is not attached.
* If `$callback` and `$priority` are both provided, a boolean is returned
* for whether the specific function is registered at that priority.
* @phpstan-param Maybe_Callable|false $callback
* @phpstan-param callable|string|array{0: string|object, 1: string}|false $callback
* @phpstan-return (
* $callback is false
* ? bool
Expand Down
10 changes: 5 additions & 5 deletions src/wp-includes/plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ function apply_filters_ref_array( $hook_name, $args ) {
* of that hook is returned, or false if the function is not attached.
* If `$callback` and `$priority` are both provided, a boolean is returned
* for whether the specific function is registered at that priority.
* @phpstan-param Maybe_Callable|false $callback
* @phpstan-param callable|string|array{0: string|object, 1: string}|false $callback
* @phpstan-return (
* $callback is false
* ? bool
Expand Down Expand Up @@ -324,7 +324,7 @@ function has_filter( $hook_name, $callback = false, $priority = false ) {
* @param int $priority Optional. The exact priority used when adding the original
* filter callback. Default 10.
* @return bool Whether the function existed before it was removed.
* @phpstan-param Maybe_Callable $callback
* @phpstan-param callable|string|array{0: string|object, 1: string} $callback
*/
function remove_filter( $hook_name, $callback, $priority = 10 ) {
global $wp_filter;
Expand Down Expand Up @@ -606,7 +606,7 @@ function do_action_ref_array( $hook_name, $args ) {
* of that hook is returned, or false if the function is not attached.
* If `$callback` and `$priority` are both provided, a boolean is returned
* for whether the specific function is registered at that priority.
* @phpstan-param Maybe_Callable|false $callback
* @phpstan-param callable|string|array{0: string|object, 1: string}|false $callback
* @phpstan-return (
* $callback is false
* ? bool
Expand Down Expand Up @@ -638,7 +638,7 @@ function has_action( $hook_name, $callback = false, $priority = false ) {
* @param int $priority Optional. The exact priority used when adding the original
* action callback. Default 10.
* @return bool Whether the function is removed.
* @phpstan-param Maybe_Callable $callback
* @phpstan-param callable|string|array{0: string|object, 1: string} $callback
*/
function remove_action( $hook_name, $callback, $priority = 10 ) {
return remove_filter( $hook_name, $callback, $priority );
Expand Down Expand Up @@ -1019,7 +1019,7 @@ function _wp_call_all_hook( $args ) {
* @param int $priority Unused. The order in which the functions
* associated with a particular action are executed.
* @return string|null Unique function ID for usage as array key, or null if it couldn't be determined.
* @phpstan-param Maybe_Callable $callback
* @phpstan-param callable|string|array{0: string|object, 1: string} $callback
* @phpstan-return non-decimal-int-string|null
*/
function _wp_filter_build_unique_id( $hook_name, $callback, $priority ): ?string {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
* @since 5.5.0
*
* @see WP_REST_Controller
*
* @phpstan-import-type Block_Style_Properties from WP_Block_Styles_Registry
*/
class WP_REST_Block_Types_Controller extends WP_REST_Controller {

Expand Down
32 changes: 6 additions & 26 deletions tests/phpstan/base.neon
Original file line number Diff line number Diff line change
Expand Up @@ -351,30 +351,10 @@ parameters:
- ../../src/wp-includes/pomo
- ../../src/wp-includes/rss.php
- ../../src/wp-includes/sodium_compat
typeAliases:
# A callable that may not be defined in the current scope.
Maybe_Callable: '''
callable|string|array{
0: string|object,
1: string,
}
'''

# The properties of a block style as WP_Block_Styles_Registry stores them, which is
# more than its register() hash accepts: `name` is required for a style to be
# registered at all, and `label` is filled in from the name when the caller omits
# it, so both are always present on the way back out. The shape stays open because
# the array is stored verbatim, so a caller's own keys survive — including into the
# REST response, which does not set `additionalProperties` to false. Read from
# procedural files as well as classes, which is why it is declared here.
Block_Style_Properties: '''
array{
name: string,
label: string,
inline_style?: string,
style_handle?: string,
is_default?: bool,
style_data?: array<string, mixed>,
...
}
'''
# No global `typeAliases` are defined here, since docblocks in src/ that use them are not
# self-contained: the aliases are lost from the stubs generated from core, and anyone who
# analyzes against core would have to define each one. Declare an alias with `@phpstan-type`
# on a class, and import it with `@phpstan-import-type` into other classes, instead. A type
# used by functions has to be repeated until PHPStan supports declaring an alias with
# `@phpstan-type` outside a class: https://github.com/phpstan/phpstan/issues/9164
Loading