diff --git a/src/wp-includes/class-wp-hook.php b/src/wp-includes/class-wp-hook.php index 2ce6ee0a17648..38895c87f1349 100644 --- a/src/wp-includes/class-wp-hook.php +++ b/src/wp-includes/class-wp-hook.php @@ -14,15 +14,24 @@ * * @see Iterator * @see ArrayAccess + * + * @phpstan-type Hook_Callback array{ + * function: callable, + * accepted_args: int, + * } + * + * @phpstan-implements Iterator> + * @phpstan-implements ArrayAccess> */ #[AllowDynamicProperties] final class WP_Hook implements Iterator, ArrayAccess { /** - * Hook callbacks. + * Hook callbacks keyed by priority. * * @since 4.7.0 * @var array + * @phpstan-var array> */ public $callbacks = array(); @@ -30,7 +39,7 @@ final class WP_Hook implements Iterator, ArrayAccess { * Priorities list. * * @since 6.4.0 - * @var array + * @var list */ protected $priorities = array(); @@ -38,7 +47,7 @@ final class WP_Hook implements Iterator, ArrayAccess { * The priority keys of actively running iterations of a hook. * * @since 4.7.0 - * @var array + * @var array> */ private $iterations = array(); @@ -46,7 +55,7 @@ final class WP_Hook implements Iterator, ArrayAccess { * The current priority of actively running iterations of a hook. * * @since 4.7.0 - * @var array + * @var array */ private $current_priority = array(); @@ -439,10 +448,11 @@ public function current_priority() { * @since 4.7.0 * * @param array $filters Filters to normalize. See documentation above for details. - * @return WP_Hook[] Array of normalized filters. + * @phpstan-param array>> $filters + * @return array Array of normalized filters keyed by hook name. */ public static function build_preinitialized_hooks( $filters ) { - /** @var WP_Hook[] $normalized */ + /** @var array $normalized */ $normalized = array(); foreach ( $filters as $hook_name => $callback_groups ) { @@ -475,7 +485,7 @@ public static function build_preinitialized_hooks( $filters ) { * * @link https://www.php.net/manual/en/arrayaccess.offsetexists.php * - * @param mixed $offset An offset to check for. + * @param int $offset An offset to check for. * @return bool True if the offset exists, false otherwise. */ #[ReturnTypeWillChange] @@ -490,8 +500,9 @@ public function offsetExists( $offset ) { * * @link https://www.php.net/manual/en/arrayaccess.offsetget.php * - * @param mixed $offset The offset to retrieve. - * @return mixed If set, the value at the specified offset, null otherwise. + * @param int $offset The offset to retrieve. + * @return array|null If set, the value at the specified offset, null otherwise. + * @phpstan-return array|null */ #[ReturnTypeWillChange] public function offsetGet( $offset ) { @@ -505,8 +516,9 @@ public function offsetGet( $offset ) { * * @link https://www.php.net/manual/en/arrayaccess.offsetset.php * - * @param mixed $offset The offset to assign the value to. - * @param mixed $value The value to set. + * @param int|null $offset The offset to assign the value to. + * @param array $value The value to set. + * @phpstan-param array $value */ #[ReturnTypeWillChange] public function offsetSet( $offset, $value ) { @@ -526,7 +538,7 @@ public function offsetSet( $offset, $value ) { * * @link https://www.php.net/manual/en/arrayaccess.offsetunset.php * - * @param mixed $offset The offset to unset. + * @param int $offset The offset to unset. */ #[ReturnTypeWillChange] public function offsetUnset( $offset ) { @@ -541,7 +553,8 @@ public function offsetUnset( $offset ) { * * @link https://www.php.net/manual/en/iterator.current.php * - * @return array Of callbacks at current priority. + * @return array|false Array of callbacks at current priority, false if there are no more elements. + * @phpstan-return array|false */ #[ReturnTypeWillChange] public function current() { @@ -555,7 +568,8 @@ public function current() { * * @link https://www.php.net/manual/en/iterator.next.php * - * @return array Of callbacks at next priority. + * @return array|false Array of callbacks at next priority, false if there are no more elements. + * @phpstan-return array|false */ #[ReturnTypeWillChange] public function next() { @@ -569,7 +583,7 @@ public function next() { * * @link https://www.php.net/manual/en/iterator.key.php * - * @return mixed Returns current priority on success, or NULL on failure + * @return int|null Returns current priority on success, or NULL on failure */ #[ReturnTypeWillChange] public function key() {