Skip to content

Commit 3d3d723

Browse files
authored
Merge pull request #3010 from justlevine/chore/stricter-phpdoc-types
chore: implement stricter PHPDoc types
2 parents eb9b067 + e250141 commit 3d3d723

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+440
-458
lines changed

access-functions.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,8 @@ function get_graphql_register_action() {
150150
*
151151
* Should be used at the `graphql_register_types` hook.
152152
*
153-
* @param mixed|string|array<string> $interface_names Array of one or more names of the GraphQL Interfaces to apply to the GraphQL Types
154-
* @param mixed|string|array<string> $type_names Array of one or more names of the GraphQL Types to apply the interfaces to.
153+
* @param string|string[] $interface_names Array of one or more names of the GraphQL Interfaces to apply to the GraphQL Types
154+
* @param string|string[] $type_names Array of one or more names of the GraphQL Types to apply the interfaces to.
155155
*
156156
* Example:
157157
* The following would register the "MyNewInterface" interface to the Post and Page type in the
@@ -819,10 +819,10 @@ function get_graphql_setting( string $option_name, $default_value = '', $section
819819

820820
/**
821821
* Filter the section fields
822-
*
823-
* @param array $section_fields The values of the fields stored for the section
824-
* @param string $section_name The name of the section
825-
* @param mixed $default_value The default value for the option being retrieved
822+
823+
* @param array<string,mixed> $section_fields The values of the fields stored for the section
824+
* @param string $section_name The name of the section
825+
* @param mixed $default_value The default value for the option being retrieved
826826
*/
827827
$section_fields = apply_filters( 'graphql_get_setting_section_fields', $section_fields, $section_name, $default_value );
828828

@@ -834,11 +834,11 @@ function get_graphql_setting( string $option_name, $default_value = '', $section
834834
/**
835835
* Filter the value before returning it
836836
*
837-
* @param mixed $value The value of the field
838-
* @param mixed $default_value The default value if there is no value set
839-
* @param string $option_name The name of the option
840-
* @param array $section_fields The setting values within the section
841-
* @param string $section_name The name of the section the setting belongs to
837+
* @param mixed $value The value of the field
838+
* @param mixed $default_value The default value if there is no value set
839+
* @param string $option_name The name of the option
840+
* @param array<string,mixed> $section_fields The setting values within the section
841+
* @param string $section_name The name of the section the setting belongs to
842842
*/
843843
return apply_filters( 'graphql_get_setting_section_field_value', $value, $default_value, $option_name, $section_fields, $section_name );
844844
}

src/Admin/Settings/SettingsRegistry.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,9 @@ public function register_field( string $section, array $field ) {
128128
/**
129129
* Filter the setting field config
130130
*
131-
* @param array $field_config The field config for the setting
132-
* @param string $field_name The name of the field (unfilterable in the config)
133-
* @param string $section The slug of the section the field is registered to
131+
* @param array<string,mixed> $field_config The field config for the setting
132+
* @param string $field_name The name of the field (unfilterable in the config)
133+
* @param string $section The slug of the section the field is registered to
134134
*/
135135
$field = apply_filters( 'graphql_setting_field_config', $field_config, $field_name, $section );
136136

@@ -160,7 +160,7 @@ public function admin_init() {
160160
/**
161161
* Filter the settings sections
162162
*
163-
* @param array $setting_sections The registered settings sections
163+
* @param array<string,array<string,mixed>> $setting_sections The registered settings sections
164164
*/
165165
$setting_sections = apply_filters( 'graphql_settings_sections', $this->settings_sections );
166166

@@ -551,7 +551,7 @@ public function callback_user_role_select( array $args ) {
551551
*
552552
* @param array<string,mixed> $options settings field args
553553
*
554-
* @return mixed
554+
* @return array<string,mixed>
555555
*/
556556
public function sanitize_options( array $options ) {
557557
if ( ! $options ) {
@@ -576,7 +576,7 @@ public function sanitize_options( array $options ) {
576576
*
577577
* @param string $slug option slug
578578
*
579-
* @return mixed string or bool false
579+
* @return callable|false
580580
*/
581581
public function get_sanitize_callback( $slug = '' ) {
582582
if ( empty( $slug ) ) {

src/AppContext.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class AppContext {
6666
/**
6767
* Passes context about the current connection being resolved
6868
*
69-
* @var mixed|String|null
69+
* @var mixed|string|null
7070
*/
7171
public $currentConnection = null;
7272

@@ -148,7 +148,7 @@ public function __construct() {
148148
*
149149
* @param string $key The name of the loader to get
150150
*
151-
* @return mixed
151+
* @return \WPGraphQL\Data\Loader\AbstractDataLoader|mixed
152152
*
153153
* @deprecated Use get_loader instead.
154154
*/

src/Data/CommentMutation.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@ public static function prepare_comment_object( array $input, array &$output_args
103103
/**
104104
* Filter the $insert_post_args
105105
*
106-
* @param array $output_args The array of $input_post_args that will be passed to wp_new_comment
107-
* @param array $input The data that was entered as input for the mutation
108-
* @param string $mutation_type The type of mutation being performed ( create, edit, etc )
106+
* @param array<string,mixed> $output_args The array of $input_post_args that will be passed to wp_new_comment
107+
* @param array<string,mixed> $input The data that was entered as input for the mutation
108+
* @param string $mutation_type The type of mutation being performed ( create, edit, etc )
109109
*/
110110
$output_args = apply_filters( 'graphql_comment_insert_post_args', $output_args, $input, $mutation_name );
111111

src/Data/Config.php

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -382,12 +382,10 @@ public function graphql_wp_term_query_cursor_pagination_support( array $pieces,
382382
/**
383383
* If pre-filter hooked, return $pre_pieces.
384384
*
385-
* @param array<string, mixed>|null $pre_pieces The pre-filtered term query SQL clauses.
386-
* @param array<string,mixed> $pieces Terms query SQL clauses.
387-
* @param string[] $taxonomies An array of taxonomies.
388-
* @param array<string,mixed> $args An array of terms query arguments.
389-
*
390-
* @return array|null
385+
* @param ?array<string,mixed> $pre_pieces The pre-filtered term query SQL clauses.
386+
* @param array<string,mixed> $pieces Terms query SQL clauses.
387+
* @param string[] $taxonomies An array of taxonomies.
388+
* @param array<string,mixed> $args An array of terms query arguments.
391389
*/
392390
$pre_pieces = apply_filters( 'graphql_pre_wp_term_query_cursor_pagination_support', null, $pieces, $taxonomies, $args );
393391
if ( null !== $pre_pieces ) {
@@ -455,11 +453,9 @@ public function graphql_wp_comments_query_cursor_pagination_support( array $piec
455453
/**
456454
* If pre-filter hooked, return $pre_pieces.
457455
*
458-
* @param array|null $pre_pieces The pre-filtered comment query clauses.
459-
* @param array $pieces A compacted array of comment query clauses.
460-
* @param \WP_Comment_Query $query Current instance of WP_Comment_Query, passed by reference.
461-
*
462-
* @return array|null
456+
* @param ?array<string,mixed> $pre_pieces The pre-filtered comment query clauses.
457+
* @param array<string,mixed> $pieces A compacted array of comment query clauses.
458+
* @param \WP_Comment_Query $query Current instance of WP_Comment_Query, passed by reference.
463459
*/
464460
$pre_pieces = apply_filters( 'graphql_pre_wp_comments_query_cursor_pagination_support', null, $pieces, $query );
465461
if ( null !== $pre_pieces ) {

src/Data/Connection/AbstractConnectionResolver.php

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ abstract class AbstractConnectionResolver {
102102
protected $ids;
103103

104104
/**
105-
* @var array<string,mixed>
105+
* @var mixed[]
106106
*/
107107
protected $nodes;
108108

@@ -162,9 +162,9 @@ public function __construct( $source, array $args, AppContext $context, ResolveI
162162
*
163163
* Filters the GraphQL args before they are used in get_query_args().
164164
*
165-
* @param array $args The GraphQL args passed to the resolver.
165+
* @param array<string,mixed> $args The GraphQL args passed to the resolver.
166166
* @param \WPGraphQL\Data\Connection\AbstractConnectionResolver $connection_resolver Instance of the ConnectionResolver.
167-
* @param array $unfiltered_args Array of arguments input in the field as part of the GraphQL query.
167+
* @param array<string,mixed> $unfiltered_args Array of arguments input in the field as part of the GraphQL query.
168168
*
169169
* @since 1.11.0
170170
*/
@@ -188,10 +188,9 @@ public function __construct( $source, array $args, AppContext $context, ResolveI
188188
*
189189
* Filters the args
190190
*
191-
* @param array $query_args The query args to be used with the executable query to get data.
192-
* This should take in the GraphQL args and return args for use in fetching the data.
191+
* @param array<string,mixed> $query_args The query args to be used with the executable query to get data.
193192
* @param \WPGraphQL\Data\Connection\AbstractConnectionResolver $connection_resolver Instance of the ConnectionResolver
194-
* @param array $unfiltered_args Array of arguments input in the field as part of the GraphQL query.
193+
* @param array<string,mixed> $unfiltered_args Array of arguments input in the field as part of the GraphQL query.
195194
*/
196195
$this->query_args = apply_filters( 'graphql_connection_query_args', $this->get_query_args(), $this, $args );
197196
}
@@ -430,11 +429,11 @@ public function get_query_amount() {
430429
*
431430
* This filter is intentionally applied AFTER the query_args filter, as
432431
*
433-
* @param int $max_posts the maximum number of posts per page.
434-
* @param mixed $source source passed down from the resolve tree
435-
* @param array $args array of arguments input in the field as part of the GraphQL query
436-
* @param \WPGraphQL\AppContext $context Object containing app context that gets passed down the resolve tree
437-
* @param \GraphQL\Type\Definition\ResolveInfo $info Info about fields passed down the resolve tree
432+
* @param int $max_posts the maximum number of posts per page.
433+
* @param mixed $source source passed down from the resolve tree
434+
* @param array<string,mixed> $args array of arguments input in the field as part of the GraphQL query
435+
* @param \WPGraphQL\AppContext $context Object containing app context that gets passed down the resolve tree
436+
* @param \GraphQL\Type\Definition\ResolveInfo $info Info about fields passed down the resolve tree
438437
*
439438
* @since 0.0.6
440439
*/
@@ -830,7 +829,7 @@ public function get_edges() {
830829
/**
831830
* Create the edge, pass it through a filter.
832831
*
833-
* @param array $edge The edge within the connection
832+
* @param array<string,mixed> $edge The edge within the connection
834833
* @param \WPGraphQL\Data\Connection\AbstractConnectionResolver $connection_resolver Instance of the connection resolver class
835834
*/
836835
$edge = apply_filters(
@@ -950,7 +949,7 @@ public function execute_and_get_ids() {
950949
/**
951950
* Filter the connection IDs
952951
*
953-
* @param array $ids Array of IDs this connection will be resolving
952+
* @param int[]|string[] $ids Array of IDs this connection will be resolving
954953
* @param \WPGraphQL\Data\Connection\AbstractConnectionResolver $connection_resolver Instance of the Connection Resolver
955954
*/
956955
$this->ids = apply_filters( 'graphql_connection_ids', $this->get_ids(), $this );
@@ -994,15 +993,15 @@ function () {
994993
*
995994
* Filters the nodes in the connection
996995
*
997-
* @param array $nodes The nodes in the connection
996+
* @param array<int|string,mixed|\WPGraphQL\Model\Model|null> $nodes The nodes in the connection
998997
* @param \WPGraphQL\Data\Connection\AbstractConnectionResolver $connection_resolver Instance of the Connection Resolver
999998
*/
1000999
$this->nodes = apply_filters( 'graphql_connection_nodes', $this->get_nodes(), $this );
10011000

10021001
/**
10031002
* Filters the edges in the connection
10041003
*
1005-
* @param array $nodes The nodes in the connection
1004+
* @param array<int|string,mixed|\WPGraphQL\Model\Model|null> $nodes The nodes in the connection
10061005
* @param \WPGraphQL\Data\Connection\AbstractConnectionResolver $connection_resolver Instance of the Connection Resolver
10071006
*/
10081007
$this->edges = apply_filters( 'graphql_connection_edges', $this->get_edges(), $this );
@@ -1025,7 +1024,7 @@ function () {
10251024
*
10261025
* This filter allows additional fields to be returned to the connection resolver
10271026
*
1028-
* @param array $connection The connection data being returned
1027+
* @param array<string,mixed> $connection The connection data being returned
10291028
* @param \WPGraphQL\Data\Connection\AbstractConnectionResolver $connection_resolver The instance of the connection resolver
10301029
*/
10311030
return apply_filters( 'graphql_connection', $connection, $this );

src/Data/Connection/CommentConnectionResolver.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,10 @@ public function get_query_args() {
135135
* Filter the query_args that should be applied to the query. This filter is applied AFTER the input args from
136136
* the GraphQL Query have been applied and has the potential to override the GraphQL Query Input Args.
137137
*
138-
* @param array $query_args array of query_args being passed to the
139-
* @param mixed $source source passed down from the resolve tree
140-
* @param array $args array of arguments input in the field as part of the GraphQL query
141-
* @param \WPGraphQL\AppContext $context object passed down the resolve tree
138+
* @param array<string,mixed> $query_args array of query_args being passed to the
139+
* @param mixed $source source passed down from the resolve tree
140+
* @param array<string,mixed> $args array of arguments input in the field as part of the GraphQL query
141+
* @param \WPGraphQL\AppContext $context object passed down the resolve tree
142142
* @param \GraphQL\Type\Definition\ResolveInfo $info info about fields passed down the resolve tree
143143
*
144144
* @since 0.0.6
@@ -256,7 +256,7 @@ static function ( $id ) {
256256
*
257257
* Filters the GraphQL args before they are used in get_query_args().
258258
*
259-
* @param array $args The GraphQL args passed to the resolver.
259+
* @param array<string,mixed> $args The GraphQL args passed to the resolver.
260260
* @param \WPGraphQL\Data\Connection\CommentConnectionResolver $connection_resolver Instance of the ConnectionResolver
261261
*
262262
* @since 1.11.0

src/Data/Connection/MenuItemConnectionResolver.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ public function get_args(): array {
104104
*
105105
* Filters the GraphQL args before they are used in get_query_args().
106106
*
107-
* @param array $args The GraphQL args passed to the resolver.
108-
* @param array $unfiltered_args Array of arguments input in the field as part of the GraphQL query.
107+
* @param array<string,mixed> $args The GraphQL args passed to the resolver.
108+
* @param array<string,mixed> $unfiltered_args Array of arguments input in the field as part of the GraphQL query.
109109
*
110110
* @since 1.11.0
111111
*/

src/Data/Connection/PostObjectConnectionResolver.php

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class PostObjectConnectionResolver extends AbstractConnectionResolver {
1818
/**
1919
* The name of the post type, or array of post types the connection resolver is resolving for
2020
*
21-
* @var mixed string|array
21+
* @var mixed|string|string[]
2222
*/
2323
protected $post_type;
2424

@@ -352,11 +352,11 @@ static function ( $id ) {
352352
/**
353353
* Filter the $query args to allow folks to customize queries programmatically
354354
*
355-
* @param array $query_args The args that will be passed to the WP_Query
356-
* @param mixed $source The source that's passed down the GraphQL queries
357-
* @param array $args The inputArgs on the field
358-
* @param \WPGraphQL\AppContext $context The AppContext passed down the GraphQL tree
359-
* @param \GraphQL\Type\Definition\ResolveInfo $info The ResolveInfo passed down the GraphQL tree
355+
* @param array<string,mixed> $query_args The args that will be passed to the WP_Query
356+
* @param mixed $source The source that's passed down the GraphQL queries
357+
* @param array<string,mixed> $args The inputArgs on the field
358+
* @param \WPGraphQL\AppContext $context The AppContext passed down the GraphQL tree
359+
* @param \GraphQL\Type\Definition\ResolveInfo $info The ResolveInfo passed down the GraphQL tree
360360
*/
361361
return apply_filters( 'graphql_post_object_connection_query_args', $query_args, $this->source, $this->args, $this->context, $this->info );
362362
}
@@ -419,15 +419,14 @@ public function sanitize_input_fields( array $where_args ) {
419419
* This allows plugins/themes to hook in and alter what $args should be allowed to be passed
420420
* from a GraphQL Query to the WP_Query
421421
*
422-
* @param array $query_args The mapped query arguments
423-
* @param array $args Query "where" args
424-
* @param mixed $source The query results for a query calling this
425-
* @param array $all_args All of the arguments for the query (not just the "where" args)
426-
* @param \WPGraphQL\AppContext $context The AppContext object
427-
* @param \GraphQL\Type\Definition\ResolveInfo $info The ResolveInfo object
428-
* @param mixed|string|array $post_type The post type for the query
422+
* @param array<string,mixed> $query_args The mapped query arguments
423+
* @param array<string,mixed> $args Query "where" args
424+
* @param mixed $source The query results for a query calling this
425+
* @param array<string,mixed> $all_args All of the arguments for the query (not just the "where" args)
426+
* @param \WPGraphQL\AppContext $context The AppContext object
427+
* @param \GraphQL\Type\Definition\ResolveInfo $info The ResolveInfo object
428+
* @param mixed|string|string[] $post_type The post type for the query
429429
*
430-
* @return array
431430
* @since 0.0.5
432431
*/
433432
$query_args = apply_filters( 'graphql_map_input_fields_to_wp_query', $query_args, $where_args, $this->source, $this->args, $this->context, $this->info, $this->post_type );
@@ -446,7 +445,7 @@ public function sanitize_input_fields( array $where_args ) {
446445
* This strips the status from the query_args if the user doesn't have permission to query for
447446
* posts of that status.
448447
*
449-
* @param mixed $stati The status(es) to sanitize
448+
* @param string[]|string $stati The status(es) to sanitize.
450449
*
451450
* @return string[]|null
452451
*/
@@ -576,9 +575,9 @@ static function ( $id ) {
576575
*
577576
* Filters the GraphQL args before they are used in get_query_args().
578577
*
579-
* @param array $args The GraphQL args passed to the resolver.
578+
* @param array<string,mixed> $args The GraphQL args passed to the resolver.
580579
* @param \WPGraphQL\Data\Connection\PostObjectConnectionResolver $connection_resolver Instance of the ConnectionResolver.
581-
* @param array $unfiltered_args Array of arguments input in the field as part of the GraphQL query.
580+
* @param array<string,mixed> $unfiltered_args Array of arguments input in the field as part of the GraphQL query.
582581
*
583582
* @since 1.11.0
584583
*/

0 commit comments

Comments
 (0)