1414 *
1515 * @see Iterator
1616 * @see ArrayAccess
17+ *
18+ * @phpstan-type Hook_Callback array{
19+ * function: callable,
20+ * accepted_args: int,
21+ * }
22+ *
23+ * @phpstan-implements Iterator<int, array<string, Hook_Callback>>
24+ * @phpstan-implements ArrayAccess<int, array<string, Hook_Callback>>
1725 */
1826#[AllowDynamicProperties]
1927final class WP_Hook implements Iterator, ArrayAccess {
2028
2129 /**
22- * Hook callbacks.
30+ * Hook callbacks keyed by priority .
2331 *
2432 * @since 4.7.0
2533 * @var array
34+ * @phpstan-var array<int, array<string, Hook_Callback>>
2635 */
2736 public $ callbacks = array ();
2837
2938 /**
3039 * Priorities list.
3140 *
3241 * @since 6.4.0
33- * @var array
42+ * @var list<int>
3443 */
3544 protected $ priorities = array ();
3645
3746 /**
3847 * The priority keys of actively running iterations of a hook.
3948 *
4049 * @since 4.7.0
41- * @var array
50+ * @var array<int, list<int>>
4251 */
4352 private $ iterations = array ();
4453
4554 /**
4655 * The current priority of actively running iterations of a hook.
4756 *
4857 * @since 4.7.0
49- * @var array
58+ * @var array<int, int>
5059 */
5160 private $ current_priority = array ();
5261
@@ -439,10 +448,11 @@ public function current_priority() {
439448 * @since 4.7.0
440449 *
441450 * @param array $filters Filters to normalize. See documentation above for details.
442- * @return WP_Hook[] Array of normalized filters.
451+ * @phpstan-param array<string, WP_Hook|array<int, array<Hook_Callback>>> $filters
452+ * @return array<string, WP_Hook> Array of normalized filters keyed by hook name.
443453 */
444454 public static function build_preinitialized_hooks ( $ filters ) {
445- /** @var WP_Hook[] $normalized */
455+ /** @var array<string, WP_Hook> $normalized */
446456 $ normalized = array ();
447457
448458 foreach ( $ filters as $ hook_name => $ callback_groups ) {
@@ -475,7 +485,7 @@ public static function build_preinitialized_hooks( $filters ) {
475485 *
476486 * @link https://www.php.net/manual/en/arrayaccess.offsetexists.php
477487 *
478- * @param mixed $offset An offset to check for.
488+ * @param int $offset An offset to check for.
479489 * @return bool True if the offset exists, false otherwise.
480490 */
481491 #[ReturnTypeWillChange]
@@ -490,8 +500,9 @@ public function offsetExists( $offset ) {
490500 *
491501 * @link https://www.php.net/manual/en/arrayaccess.offsetget.php
492502 *
493- * @param mixed $offset The offset to retrieve.
494- * @return mixed If set, the value at the specified offset, null otherwise.
503+ * @param int $offset The offset to retrieve.
504+ * @return array|null If set, the value at the specified offset, null otherwise.
505+ * @phpstan-return array<string, Hook_Callback>|null
495506 */
496507 #[ReturnTypeWillChange]
497508 public function offsetGet ( $ offset ) {
@@ -505,8 +516,9 @@ public function offsetGet( $offset ) {
505516 *
506517 * @link https://www.php.net/manual/en/arrayaccess.offsetset.php
507518 *
508- * @param mixed $offset The offset to assign the value to.
509- * @param mixed $value The value to set.
519+ * @param int|null $offset The offset to assign the value to.
520+ * @param array $value The value to set.
521+ * @phpstan-param array<string, Hook_Callback> $value
510522 */
511523 #[ReturnTypeWillChange]
512524 public function offsetSet ( $ offset , $ value ) {
@@ -526,7 +538,7 @@ public function offsetSet( $offset, $value ) {
526538 *
527539 * @link https://www.php.net/manual/en/arrayaccess.offsetunset.php
528540 *
529- * @param mixed $offset The offset to unset.
541+ * @param int $offset The offset to unset.
530542 */
531543 #[ReturnTypeWillChange]
532544 public function offsetUnset ( $ offset ) {
@@ -541,7 +553,8 @@ public function offsetUnset( $offset ) {
541553 *
542554 * @link https://www.php.net/manual/en/iterator.current.php
543555 *
544- * @return array Of callbacks at current priority.
556+ * @return array|false Array of callbacks at current priority, false if there are no more elements.
557+ * @phpstan-return array<string, Hook_Callback>|false
545558 */
546559 #[ReturnTypeWillChange]
547560 public function current () {
@@ -555,7 +568,8 @@ public function current() {
555568 *
556569 * @link https://www.php.net/manual/en/iterator.next.php
557570 *
558- * @return array Of callbacks at next priority.
571+ * @return array|false Array of callbacks at next priority, false if there are no more elements.
572+ * @phpstan-return array<string, Hook_Callback>|false
559573 */
560574 #[ReturnTypeWillChange]
561575 public function next () {
@@ -569,7 +583,7 @@ public function next() {
569583 *
570584 * @link https://www.php.net/manual/en/iterator.key.php
571585 *
572- * @return mixed Returns current priority on success, or NULL on failure
586+ * @return int|null Returns current priority on success, or NULL on failure
573587 */
574588 #[ReturnTypeWillChange]
575589 public function key () {
0 commit comments