From 51739c0708de753310eba7e5261a842e29f16944 Mon Sep 17 00:00:00 2001 From: Mark Kelnar <749603+markkelnar@users.noreply.github.com> Date: Tue, 1 Aug 2023 11:09:38 -0500 Subject: [PATCH 1/2] phpstan changes for level 6 --- phpstan.neon.dist | 2 +- src/Admin/Editor.php | 47 ++++++++++++++- src/Admin/Settings.php | 20 ++++++- src/AdminErrors.php | 10 ++++ src/Cache/Collection.php | 6 +- src/Cache/Invalidation.php | 38 ++++++++++++- src/Cache/Query.php | 11 +++- src/Cache/Results.php | 13 ++++- src/Document.php | 56 +++++++++++++++++- src/Document/Description.php | 5 ++ src/Document/Grant.php | 45 +++++++++++++-- src/Document/Loader.php | 2 +- src/Document/MaxAge.php | 57 +++++++++++++++++-- src/Storage/Ephemeral.php | 11 ++++ src/Storage/Transient.php | 7 +++ src/Storage/WpCache.php | 7 +++ src/Utils.php | 2 + .../AllowDenyQueryDocument.php | 22 ++++++- wp-graphql-smart-cache.php | 2 + 19 files changed, 333 insertions(+), 30 deletions(-) diff --git a/phpstan.neon.dist b/phpstan.neon.dist index cbd35f21..26605199 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -1,5 +1,5 @@ parameters: - level: 4 + level: 6 inferPrivatePropertyTypeFromConstructor: true checkMissingIterableValueType: false stubFiles: diff --git a/src/Admin/Editor.php b/src/Admin/Editor.php index 967407f5..4129360f 100644 --- a/src/Admin/Editor.php +++ b/src/Admin/Editor.php @@ -16,6 +16,9 @@ class Editor { + /** + * @return void + */ public function admin_init() { add_filter( 'wp_insert_post_data', [ $this, 'validate_before_save_cb' ], 10, 2 ); add_action( sprintf( 'save_post_%s', Document::TYPE_NAME ), [ $this, 'save_document_cb' ], 10, 2 ); @@ -34,6 +37,10 @@ public function admin_init() { /** * If existing post is edited, verify query string in content is valid graphql + * + * @param array $data An array of slashed, sanitized, and processed post data. + * @param array $post An array of sanitized (and slashed) but otherwise unmodified post data. + * @return array */ public function validate_before_save_cb( $data, $post ) { try { @@ -50,6 +57,12 @@ public function validate_before_save_cb( $data, $post ) { return $data; } + /** + * Initialize Admin functionality for WPGraphQL + * + * @param int $post_id post id + * @return void|bool + */ public function is_valid_form( $post_id ) { if ( empty( $_POST ) ) { return; @@ -97,8 +110,12 @@ public function is_valid_form( $post_id ) { } /** - * When a post is saved, sanitize and store the data. - */ + * When a post is saved, sanitize and store the data. + * + * @param int $post_id Post ID. + * @param \WP_Post $post Post object. + * @return void + */ public function save_document_cb( $post_id, $post ) { if ( ! $this->is_valid_form( $post_id ) ) { AdminErrors::add_message( 'Something is wrong with the form data' ); @@ -119,7 +136,7 @@ public function save_document_cb( $post_id, $post ) { $data = sanitize_text_field( wp_unslash( $_POST['graphql_query_maxage'] ) ); $max_age->save( $post_id, $data ); } catch ( SyntaxError $e ) { - AdminErrors::add_message( 'Did not save invalid graphql query string. ' . $post['post_content'] ); + AdminErrors::add_message( 'Did not save invalid graphql query string. ' . $post->post_content ); } catch ( RequestError $e ) { AdminErrors::add_message( $e->getMessage() ); } @@ -127,6 +144,9 @@ public function save_document_cb( $post_id, $post ) { /** * Draw the input field for the post edit + * + * @param \WP_Post $post Post object. + * @return void */ public static function grant_input_box_cb( $post ) { wp_nonce_field( 'graphql_query_grant', 'savedquery_grant_noncename' ); @@ -167,6 +187,9 @@ public static function grant_input_box_cb( $post ) { /** * Draw the input field for the post edit + * + * @param \WP_Post $post Post object. + * @return void */ public static function maxage_input_box_cb( $post ) { wp_nonce_field( 'graphql_query_maxage', 'savedquery_maxage_noncename' ); @@ -211,6 +234,9 @@ public function translate_excerpt_text_cb( $string ) { /** * Enable excerpt as the description. + * + * @param string[] $columns An associative array of column headings. + * @return array */ public function add_description_column_to_admin_cb( $columns ) { // Use 'description' as the text the user sees @@ -218,17 +244,32 @@ public function add_description_column_to_admin_cb( $columns ) { return $columns; } + /** + * @param string $column The name of the column to display. + * @param int $post_id The current post ID. + * @return void + */ public function fill_excerpt_content_cb( $column, $post_id ) { if ( 'excerpt' === $column ) { echo esc_html( get_the_excerpt( $post_id ) ); } } + /** + * @param array $columns An array of sortable columns. + * @return array + */ public function make_excerpt_column_sortable_in_admin_cb( $columns ) { $columns['excerpt'] = true; return $columns; } + /** + * @param array $settings Array of editor arguments. + * @param string $editor_id Unique editor identifier, e.g. 'content'. Accepts 'classic-block' + * when called from block editor's Classic block. + * @return array + */ public function wp_editor_settings( $settings, $editor_id ) { if ( 'content' === $editor_id && Document::TYPE_NAME === get_current_screen()->post_type ) { $settings['tinymce'] = false; diff --git a/src/Admin/Settings.php b/src/Admin/Settings.php index 9a6a09d1..4f90b0db 100644 --- a/src/Admin/Settings.php +++ b/src/Admin/Settings.php @@ -7,7 +7,11 @@ class Settings { - // set this to true to see these in wp-admin + /** + * Set this to true to see these in wp-admin + * + * @return bool + */ public static function show_in_admin() { $display_admin = function_exists( 'get_graphql_setting' ) ? \get_graphql_setting( 'editor_display', false, 'graphql_persisted_queries_section' ) : false; return ( 'on' === $display_admin ); @@ -60,16 +64,28 @@ public static function purge_logging_enabled() { return ( 'on' === $option ); } - // Date/Time of the last time purge all happened through admin. + /** + * Date/Time of the last time purge all happened through admin. + * + * @return string|false + */ public static function caching_purge_timestamp() { return function_exists( 'get_graphql_setting' ) ? \get_graphql_setting( 'purge_all_timestamp', false, 'graphql_cache_section' ) : false; } + /** + * The graphql url endpoint with leading slash. + * + * @return string + */ public static function graphql_endpoint() { $path = function_exists( 'get_graphql_setting' ) ? \get_graphql_setting( 'graphql_endpoint', 'graphql', 'graphql_general_settings' ) : 'graphql'; return '/' . $path; } + /** + * @return void + */ public function init() { // Add to the wp-graphql admin settings page add_action( diff --git a/src/AdminErrors.php b/src/AdminErrors.php index 36363534..f66bc234 100644 --- a/src/AdminErrors.php +++ b/src/AdminErrors.php @@ -14,14 +14,24 @@ class AdminErrors { const TRANSIENT_NAME = 'graphql_save_graphql_query_validation_error_messages'; const MESSAGE_TTL_SECONDS = 60; + /** + * @return void + */ public function init() { add_action( 'admin_notices', [ $this, 'display_validation_messages' ] ); } + /** + * @param string $message + * @return void + */ public static function add_message( $message ) { set_transient( self::TRANSIENT_NAME, [ $message ], self::MESSAGE_TTL_SECONDS ); } + /** + * @return void + */ public function display_validation_messages() { $screen = get_current_screen(); if ( $screen && Document::TYPE_NAME !== $screen->post_type ) { diff --git a/src/Cache/Collection.php b/src/Cache/Collection.php index f926c442..b508a520 100644 --- a/src/Cache/Collection.php +++ b/src/Cache/Collection.php @@ -14,7 +14,11 @@ class Collection extends Query { - // initialize the cache collection + /** + * Initialize the cache collection + * + * @return void + */ public function init() { add_action( 'graphql_return_response', [ $this, 'save_query_mapping_cb' ], 10, 8 ); parent::init(); diff --git a/src/Cache/Invalidation.php b/src/Cache/Invalidation.php index dbc881d7..7fa7dc6d 100644 --- a/src/Cache/Invalidation.php +++ b/src/Cache/Invalidation.php @@ -30,6 +30,7 @@ class Invalidation { * Instantiate the Cache Invalidation class * * @param Collection $collection + * @return void */ public function __construct( Collection $collection ) { $this->collection = $collection; @@ -37,6 +38,8 @@ public function __construct( Collection $collection ) { /** * Initialize the actions to listen for + * + * @return void */ public function init() { // @phpcs:ignore @@ -200,6 +203,8 @@ public function should_track_meta( $meta_key, $meta_value, $object ) { * * @param string $key An identifiers for data stored in memory. * @param string $event The event that caused the purge + * + * @return void */ public function purge( $key, $event = 'undefined event' ) { @@ -223,6 +228,8 @@ public function purge( $key, $event = 'undefined event' ) { * @param string $id_prefix The type name specific to the id to form the "global ID" that is unique among all types * @param mixed|string|int $id The node entity identifier * @param string $event The event that caused the purge + * + * @return void */ public function purge_nodes( $id_prefix, $id, $event = 'unknown event' ) { if ( ! method_exists( Relay::class, 'toGlobalId' ) ) { @@ -328,6 +335,8 @@ public function on_deleted_post_cb( $post_id, WP_Post $post ) { * @param int $term_id Term ID. * @param int $tt_id Taxonomy term ID. * @param string $taxonomy Taxonomy name. + * + * @return void */ public function on_created_term_cb( $term_id, $tt_id, $taxonomy ) { $tax_object = get_taxonomy( $taxonomy ); @@ -364,6 +373,8 @@ public function is_taxonomy_tracked( $taxonomy ) { * @param int $tt_id Taxonomy term ID. * @param string $taxonomy Taxonomy name. * @param mixed $deleted_term Deleted term object. + * + * @return void */ public function on_deleted_term_cb( $term_id, $tt_id, $taxonomy, $deleted_term ) { $tax_object = get_taxonomy( $taxonomy ); @@ -387,6 +398,8 @@ public function on_deleted_term_cb( $term_id, $tt_id, $taxonomy, $deleted_term ) * @param int $object_id ID of the object metadata is for. * @param string $meta_key Metadata key. * @param mixed $meta_value Metadata value. Serialized if non-scalar. + * + * @return void */ public function on_updated_term_meta_cb( $meta_id, $object_id, $meta_key, $meta_value ) { if ( empty( $term = get_term( $object_id ) ) || ! $term instanceof WP_Term ) { @@ -503,6 +516,8 @@ public function on_added_term_relationship_cb( $object_id, $tt_id, $taxonomy ) { * @param string $new_status The new status of the post * @param string $old_status The old status of the post * @param WP_Post $post The post being updated + * + * @return void */ public function on_transition_post_status_cb( $new_status, $old_status, WP_Post $post ) { @@ -612,6 +627,8 @@ function ( $term ) use ( $post ) { * * @param int $user_id User ID. * @param WP_User $old_user_data Object containing user's data prior to update. + * + * @return void */ public function on_user_profile_update_cb( $user_id, $old_user_data ) { // Delete the cached results associated with this key @@ -625,6 +642,8 @@ public function on_user_profile_update_cb( $user_id, $old_user_data ) { * @param int $object_id ID of the object metadata is for. * @param string $meta_key Metadata key. * @param mixed $_meta_value Metadata value. Serialized if non-scalar. + * + * @return void */ public function on_user_meta_change_cb( $meta_id, $object_id, $meta_key, $_meta_value ) { $user = get_user_by( 'id', $object_id ); @@ -642,10 +661,10 @@ public function on_user_meta_change_cb( $meta_id, $object_id, $meta_key, $_meta_ } /** - * * @param int $deleted_id ID of the deleted user. * @param int|null $reassign_id ID of the user to reassign posts and links to. * Default null, for no reassignment. + * @return void */ public function on_user_deleted_cb( $deleted_id, $reassign_id ) { global $wpdb; @@ -679,6 +698,8 @@ public function on_user_deleted_cb( $deleted_id, $reassign_id ) { * @param mixed $meta_value Metadata value. This will be a PHP-serialized string * representation of the value if the value is an array, an object, * or itself a PHP-serialized string. + * + * @return void */ public function on_postmeta_change_cb( $meta_id, $post_id, $meta_key, $meta_value ) { @@ -856,6 +877,8 @@ public function on_updated_menu_meta_cb( $meta_id, $object_id, $meta_key, $meta_ * @param mixed $meta_value Metadata value. This will be a PHP-serialized string * representation of the value if the value is an array, an object, * or itself a PHP-serialized string. + * + * @return void */ public function on_menu_item_change_cb( $meta_id, $post_id, $meta_key, $meta_value ) { @@ -901,11 +924,18 @@ public function on_add_attachment_cb( $attachment_id ) { * @param string $image Unused. * @param string $mime_type Unused. * @param int $post_id Post ID. + * + * @return void */ public function on_save_image_file_cb( $dummy, $filename, $image, $mime_type, $post_id ) { $this->on_edit_attachment_cb( $post_id ); } + /** + * @param int $attachment_id Attachment ID. + * + * @return void + */ public function on_edit_attachment_cb( $attachment_id ) { $attachment = get_post( $attachment_id ); @@ -919,7 +949,7 @@ public function on_edit_attachment_cb( $attachment_id ) { /** * Handle purging when attachment is deleted * - * @param $attachment_id + * @param int $attachment_id Attachment ID. * * @return void */ @@ -939,6 +969,8 @@ public function on_delete_attachment( $attachment_id ) { * @param int|string $new_status The new comment status. * @param int|string $old_status The old comment status. * @param WP_Comment $comment Comment object. + * + * @return void */ public function on_comment_transition_cb( $new_status, $old_status, $comment ) { // Only evict cache if transitioning to or from 'approved' @@ -953,6 +985,8 @@ public function on_comment_transition_cb( $new_status, $old_status, $comment ) { * * @param int $comment_id The comment ID. * @param WP_Comment $comment Comment object. + * + * @return void */ public function on_insert_comment_cb( $comment_id, $comment ) { if ( property_exists( $comment, 'comment_approved' ) && '1' === $comment->comment_approved ) { diff --git a/src/Cache/Query.php b/src/Cache/Query.php index 0d9ce247..9a3b5968 100644 --- a/src/Cache/Query.php +++ b/src/Cache/Query.php @@ -14,11 +14,18 @@ class Query { const GROUP_NAME = 'gql_cache'; - // The storage object for the actual system of choice transient, database, object, memory, etc + /** + * The storage object for the actual system of choice transient, database, object, memory, etc + * + * @var object + **/ public static $storage = null; + /** + * @return void + */ public function init() { - if ( ! self::$storage ) { + if ( null === self::$storage ) { self::$storage = apply_filters( 'graphql_cache_storage_object', //phpcs:ignore wp_using_ext_object_cache() ? new WpCache( self::GROUP_NAME ) : new Transient( self::GROUP_NAME ) diff --git a/src/Cache/Results.php b/src/Cache/Results.php index a0051996..c5bb8021 100644 --- a/src/Cache/Results.php +++ b/src/Cache/Results.php @@ -15,9 +15,9 @@ class Results extends Query { const GLOBAL_DEFAULT_TTL = 600; /** - * Indicator of the GraphQL Query execution cached or not. + * Indicator of the GraphQL Query keys cached or not. * - * @array bool + * @var array */ protected $is_cached = []; @@ -26,6 +26,9 @@ class Results extends Query { */ protected $request; + /** + * @return void + */ public function init() { add_filter( 'pre_graphql_execute_request', [ $this, 'get_query_results_from_cache_cb' ], 10, 2 ); add_action( 'graphql_return_response', [ $this, 'save_query_results_to_cache_cb' ], 10, 8 ); @@ -256,9 +259,11 @@ public function save_query_results_to_cache_cb( /** * When an item changed and this callback is triggered to delete results we have cached for that list of nodes * Related to the data type that changed. - * + * * @param string $id An identifier for data stored in memory. * @param mixed|array|object|null $nodes The graphql response or false + * + * @return void */ public function purge_nodes_cb( $id, $nodes ) { if ( is_array( $nodes ) && ! empty( $nodes ) ) { @@ -273,6 +278,8 @@ public function purge_nodes_cb( $id, $nodes ) { /** * Purge the local cache results if enabled + * + * @return void */ public function purge_all_cb() { $this->purge_all(); diff --git a/src/Document.php b/src/Document.php index 7bc8b4a4..a47501cc 100644 --- a/src/Document.php +++ b/src/Document.php @@ -18,6 +18,9 @@ class Document { const ALIAS_TAXONOMY_NAME = 'graphql_query_alias'; const GRAPHQL_NAME = 'graphqlDocument'; + /** + * @return void + */ public function init() { add_filter( 'graphql_request_data', [ $this, 'graphql_query_contains_query_id_cb' ], 10, 2 ); add_filter( 'graphql_execute_query_params', [ $this, 'graphql_execute_query_params_cb' ], 10, 2 ); @@ -107,6 +110,13 @@ function ( $term ) { /** * Run on mutation create/update. + * + * @param array $insert_post_args The array of $input_post_args that will be passed to wp_insert_post + * @param array $input The data that was entered as input for the mutation + * @param \WP_Post_Type $post_type_object The post_type_object that the mutation is affecting + * @param string $mutation_name The type of mutation being performed (create, edit, etc) + * + * @return array */ public function mutation_filter_post_args( $insert_post_args, $input, $post_type_object, $mutation_name ) { if ( in_array( $mutation_name, [ 'createGraphqlDocument', 'updateGraphqlDocument' ], true ) ) { @@ -115,8 +125,19 @@ public function mutation_filter_post_args( $insert_post_args, $input, $post_type return $insert_post_args; } - // This runs on post create/update - // Insert/Update the alias name. Make sure it is unique + /** + * This runs on post create/update + * Insert/Update the alias name. Make sure it is unique + * Filters the mutation input before it's passed to the `mutateAndGetPayload` callback. + * + * @param array $input The mutation input args. + * @param \WPGraphQL\AppContext $context The AppContext object. + * @param \GraphQL\Type\Definition\ResolveInfo $info The ResolveInfo object. + * @param string $mutation_name The name of the mutation field. + * + * @return array + * @throws RequestError + */ public function graphql_mutation_filter( $input, $context, $info, $mutation_name ) { if ( ! in_array( $mutation_name, [ 'createGraphqlDocument', 'updateGraphqlDocument' ], true ) ) { return $input; @@ -139,6 +160,18 @@ public function graphql_mutation_filter( $input, $context, $info, $mutation_name return $input; } + /** + * Fires after the mutation payload has been returned from the `mutateAndGetPayload` callback. + * + * @param array $post_object The Payload returned from the mutation. + * @param array $filtered_input The mutation input args, after being filtered by 'graphql_mutation_input'. + * @param array $input The unfiltered input args of the mutation + * @param \WPGraphQL\AppContext $context The AppContext object. + * @param \GraphQL\Type\Definition\ResolveInfo $info The ResolveInfo object. + * @param string $mutation_name The name of the mutation field. + * + * @return void + */ public function graphql_mutation_insert( $post_object, $filtered_input, $input, $context, $info, $mutation_name ) { if ( ! in_array( $mutation_name, [ 'createGraphqlDocument', 'updateGraphqlDocument' ], true ) ) { return; @@ -166,7 +199,9 @@ public function graphql_mutation_insert( $post_object, $filtered_input, $input, * * @param array $parsed_body_params Request parameters. * @param array $request_context An array containing the both body and query params + * * @return array Updated $parsed_body_params Request parameters. + * @throws RequestError */ public function graphql_query_contains_query_id_cb( $parsed_body_params, $request_context ) { @@ -199,6 +234,8 @@ public function graphql_query_contains_query_id_cb( $parsed_body_params, $reques * * @param string $query The graphql query string. * @param mixed|array|\GraphQL\Server\OperationParams $params The graphql request params, containing queryId + * + * @return string|null */ public function graphql_execute_query_params_cb( $query, $params ) { $query_id = null; @@ -223,6 +260,9 @@ public function graphql_execute_query_params_cb( $query, $params ) { * * @param array $data An array of slashed, sanitized, and processed post data. * @param array $post An array of sanitized (and slashed) but otherwise unmodified post data. + * + * @return array $data + * @throws RequestError */ public function validate_before_save_cb( $data, $post ) { if ( self::TYPE_NAME !== $post['post_type'] ) { @@ -264,6 +304,8 @@ public function validate_before_save_cb( $data, $post ) { * * @param int $post_ID * @param \WP_Post $post + * + * @return void */ public function save_document_cb( $post_ID, $post ) { if ( empty( $post->post_content ) ) { @@ -286,6 +328,8 @@ public function save_document_cb( $post_ID, $post ) { * @param int $post_ID Post ID. * @param \WP_Post $post_after Post object following the update. * @param \WP_Post $post_before Post object before the update. + * + * @return void */ public function after_updated_cb( $post_ID, $post_after, $post_before ) { if ( self::TYPE_NAME !== $post_before->post_type ) { @@ -323,7 +367,7 @@ public function after_updated_cb( $post_ID, $post_after, $post_before ) { * Load a persisted query corresponding to a query ID (hash) or alias/alternate name * * @param string $query_id Query ID - * @return mixed string|null + * @return string|null */ public function get( $query_id ) { $post = Utils::getPostByTermName( $query_id, self::TYPE_NAME, self::ALIAS_TAXONOMY_NAME ); @@ -339,6 +383,10 @@ public function get( $query_id ) { * * @param string $query_id Query string str256 hash * @param string $query The graphql query string. + * + * @throws RequestError + * + * @return int post id */ public function save( $query_id, $query ) { // Get post using the normalized hash of the query string @@ -405,6 +453,7 @@ public function save( $query_id, $query ) { * When a saved query post type is deleted, also delete the data for the other information. * * @param int $post_id the Post Object Id + * @return void */ public function delete_post_cb( $post_id ) { if ( self::TYPE_NAME === get_post_type( $post_id ) ) { @@ -416,6 +465,7 @@ public function delete_post_cb( $post_id ) { * When a saved query post type is deleted, also delete the taxonomies. * * @param int $post_id the Post Object Id + * @return void */ public function delete_term( $post_id ) { $terms = wp_get_object_terms( $post_id, self::ALIAS_TAXONOMY_NAME ); diff --git a/src/Document/Description.php b/src/Document/Description.php index 5d3fa663..7956168c 100644 --- a/src/Document/Description.php +++ b/src/Document/Description.php @@ -11,6 +11,9 @@ class Description { + /** + * @return void + */ public function init() { add_action( 'graphql_register_types', @@ -50,6 +53,8 @@ function () { * @param array $input The data that was entered as input for the mutation * @param \WP_Post_Type $post_type_object The post_type_object that the mutation is affecting * @param string $mutation_name The type of mutation being performed (create, edit, etc) + * + * @return array */ public function mutation_filter_post_args( $insert_post_args, $input, $post_type_object, $mutation_name ) { if ( in_array( diff --git a/src/Document/Grant.php b/src/Document/Grant.php index f9a2317c..e5a2e5b8 100644 --- a/src/Document/Grant.php +++ b/src/Document/Grant.php @@ -30,6 +30,9 @@ class Grant { const GLOBAL_SETTING_NAME = 'grant_mode'; + /** + * @return void + */ public function init() { register_taxonomy( self::TAXONOMY_NAME, @@ -82,8 +85,17 @@ function () { add_action( 'graphql_mutation_response', [ $this, 'graphql_mutation_insert' ], 10, 6 ); } - // This runs on post create/update - // Check the grant allow/deny value is within limits + /** + * This runs on post create/update + * Check the grant allow/deny value is within limits + * + * @param array $input The mutation input args. + * @param \WPGraphQL\AppContext $context The AppContext object. + * @param \GraphQL\Type\Definition\ResolveInfo $info The ResolveInfo object. + * @param string $mutation_name The name of the mutation field. + * + * @return array + */ public function graphql_mutation_filter( $input, $context, $info, $mutation_name ) { if ( ! in_array( $mutation_name, @@ -108,8 +120,19 @@ public function graphql_mutation_filter( $input, $context, $info, $mutation_name return $input; } - // This runs on post create/update - // Check the grant allow/deny value is within limits + /** + * This runs on post create/update + * Check the grant allow/deny value is within limits + * + * @param array $post_object The Payload returned from the mutation. + * @param array $filtered_input The mutation input args, after being filtered by 'graphql_mutation_input'. + * @param array $input The unfiltered input args of the mutation + * @param \WPGraphQL\AppContext $context The AppContext object. + * @param \GraphQL\Type\Definition\ResolveInfo $info The ResolveInfo object. + * @param string $mutation_name The name of the mutation field. + * + * @return void + **/ public function graphql_mutation_insert( $post_object, $filtered_input, $input, $context, $info, $mutation_name ) { if ( ! in_array( $mutation_name, @@ -133,6 +156,7 @@ public function graphql_mutation_insert( $post_object, $filtered_input, $input, * Look up the allow/deny grant setting for a post * * @param int $post_id The post id + * @return string */ public static function getQueryGrantSetting( $post_id ) { $item = get_the_terms( $post_id, self::TAXONOMY_NAME ); @@ -164,6 +188,13 @@ public function the_selection( $value ) { return self::USE_DEFAULT; } + /** + * Save the data + * + * @param int $post_id + * @param string $grant + * @return array|false|\WP_Error Array of term taxonomy IDs of affected terms. WP_Error or false on failure. + */ public function save( $post_id, $grant ) { return wp_set_post_terms( $post_id, $grant, self::TAXONOMY_NAME ); } @@ -172,6 +203,12 @@ public function save( $post_id, $grant ) { * Use graphql-php built in validation rules when a query is being requested. * This allows the query to check access grant rules (allow/deny) and return correct error if * needed. + * + * Return the validation rules to use in the request + * + * @param array $validation_rules The validation rules to use in the request + * @param \WPGraphQL\Request $request The Request instance + * @return array */ public function add_validation_rules_cb( $validation_rules, $request ) { // Check the grant mode. If public for all, don't add this rule. diff --git a/src/Document/Loader.php b/src/Document/Loader.php index cfa441aa..1b1daf1c 100644 --- a/src/Document/Loader.php +++ b/src/Document/Loader.php @@ -16,7 +16,7 @@ class Loader { * string * Can be invoked on GET or POST params * - * @param array $query_id An array containing the pieces of the data of the GraphQL + * @param string $query_id An array containing the pieces of the data of the GraphQL * request * @param array $operation_params An array containing the method, body and query params * diff --git a/src/Document/MaxAge.php b/src/Document/MaxAge.php index ad49aabc..8bfb647e 100644 --- a/src/Document/MaxAge.php +++ b/src/Document/MaxAge.php @@ -15,9 +15,16 @@ class MaxAge { const TAXONOMY_NAME = 'graphql_document_http_maxage'; - // The in-progress query(s) + /** + * The in-progress query(s) + * + * @var array + */ public $query_ids = []; + /** + * @return void + */ public function init() { register_taxonomy( self::TAXONOMY_NAME, @@ -72,8 +79,17 @@ function () { add_action( 'graphql_mutation_response', [ $this, 'graphql_mutation_insert' ], 10, 6 ); } - // This runs on post create/update - // Check the max age value is within limits + /** + * This runs on post create/update + * Check the max age value is within limits + * + * @param array $input The mutation input args. + * @param \WPGraphQL\AppContext $context The AppContext object. + * @param \GraphQL\Type\Definition\ResolveInfo $info The ResolveInfo object. + * @param string $mutation_name The name of the mutation field. + * + * @return array + */ public function graphql_mutation_filter( $input, $context, $info, $mutation_name ) { if ( ! in_array( $mutation_name, @@ -93,8 +109,19 @@ public function graphql_mutation_filter( $input, $context, $info, $mutation_name return $input; } - // This runs on post create/update - // Check the grant allow/deny value is within limits + /** + * This runs on post create/update + * Check the max age value is within limits + * + * @param array $post_object The Payload returned from the mutation. + * @param array $filtered_input The mutation input args, after being filtered by 'graphql_mutation_input'. + * @param array $input The unfiltered input args of the mutation + * @param \WPGraphQL\AppContext $context The AppContext object. + * @param \GraphQL\Type\Definition\ResolveInfo $info The ResolveInfo object. + * @param string $mutation_name The name of the mutation field. + * + * @return void + **/ public function graphql_mutation_insert( $post_object, $filtered_input, $input, $context, $info, $mutation_name ) { if ( ! in_array( $mutation_name, @@ -116,6 +143,9 @@ public function graphql_mutation_insert( $post_object, $filtered_input, $input, /** * Get the max age if it exists for a saved persisted query + * + * @param int $post_id + * @return \WP_Error|string|null */ public function get( $post_id ) { $item = get_the_terms( $post_id, self::TAXONOMY_NAME ); @@ -126,6 +156,12 @@ public function get( $post_id ) { return property_exists( $item[0], 'name' ) ? $item[0]->name : null; } + /** + * Verify the max age value is acceptable + * + * @param string $value + * @return bool + */ public function valid( $value ) { // TODO: terms won't save 0, as considers that empty and removes the term. Consider 'zero' or 'stale' or greater than zero. return ( is_numeric( $value ) && $value >= 0 ); @@ -133,6 +169,10 @@ public function valid( $value ) { /** * Save the data + * + * @param int $post_id + * @param string $value + * @return array|false|\WP_Error Array of term taxonomy IDs of affected terms. WP_Error or false on failure. */ public function save( $post_id, $value ) { if ( ! $this->valid( $value ) ) { @@ -143,6 +183,12 @@ public function save( $post_id, $value ) { return wp_set_post_terms( $post_id, $value, self::TAXONOMY_NAME ); } + /** + * @param mixed|array|object $result The response from execution. Array for batch requests, + * single object for individual requests + * @param \WPGraphQL\Request $request + * @return mixed|array|object + */ public function peek_at_executing_query_cb( $result, $request ) { // For batch request, params are an array for each query/queryId in the batch $params = []; @@ -167,6 +213,7 @@ public function peek_at_executing_query_cb( $result, $request ) { /** * @param array $headers + * @return array */ public function http_headers_cb( $headers ) { $age = null; diff --git a/src/Storage/Ephemeral.php b/src/Storage/Ephemeral.php index c5947056..1acb3405 100644 --- a/src/Storage/Ephemeral.php +++ b/src/Storage/Ephemeral.php @@ -7,9 +7,20 @@ class Ephemeral { + /** + * @var string + */ public $group_name; + + /** + * @var array + */ public $data; + /** + * @param string $group_name + * @return void + */ public function __construct( $group_name ) { $this->group_name = $group_name; $this->data = []; diff --git a/src/Storage/Transient.php b/src/Storage/Transient.php index a78a5a24..574bc976 100644 --- a/src/Storage/Transient.php +++ b/src/Storage/Transient.php @@ -4,8 +4,15 @@ class Transient { + /** + * @var string + */ public $group_name; + /** + * @param string $group_name + * @return void + */ public function __construct( $group_name ) { $this->group_name = $group_name; } diff --git a/src/Storage/WpCache.php b/src/Storage/WpCache.php index cc58931f..5e732d8b 100644 --- a/src/Storage/WpCache.php +++ b/src/Storage/WpCache.php @@ -4,8 +4,15 @@ class WpCache { + /** + * @var string + */ public $group_name; + /** + * @param string $group_name + * @return void + */ public function __construct( $group_name ) { $this->group_name = $group_name; } diff --git a/src/Utils.php b/src/Utils.php index 03c111b4..5bda6028 100644 --- a/src/Utils.php +++ b/src/Utils.php @@ -11,6 +11,8 @@ class Utils { /** * @param string $query_id Query ID + * @param string|array $type + * @param string $taxonomy * * @return \WP_Post|bool false when not exist */ diff --git a/src/ValidationRules/AllowDenyQueryDocument.php b/src/ValidationRules/AllowDenyQueryDocument.php index 9b49a53f..d02f8238 100644 --- a/src/ValidationRules/AllowDenyQueryDocument.php +++ b/src/ValidationRules/AllowDenyQueryDocument.php @@ -26,11 +26,21 @@ class AllowDenyQueryDocument extends ValidationRule { /** * AllowDenyQueryDocument constructor. + * + * @param string $setting + * @return void */ public function __construct( $setting ) { $this->access_setting = $setting; } + /** + * Returns structure suitable for GraphQL\Language\Visitor + * + * @see \GraphQL\Language\Visitor + * + * @return mixed[] + */ public function getVisitor( ValidationContext $context ) { return [ NodeKind::DOCUMENT => function ( DocumentNode $node ) use ( $context ) { @@ -57,7 +67,7 @@ public function getVisitor( ValidationContext $context ) { $context->reportError( new Error( self::deniedDocumentMessage(), - [ $node ] + $node ) ); } @@ -68,14 +78,14 @@ public function getVisitor( ValidationContext $context ) { $context->reportError( new Error( self::notFoundDocumentMessage(), - [ $node ] + $node ) ); } elseif ( Grant::ALLOW !== Grant::getQueryGrantSetting( $post->ID ) ) { $context->reportError( new Error( self::deniedDocumentMessage(), - [ $node ] + $node ) ); } @@ -84,10 +94,16 @@ public function getVisitor( ValidationContext $context ) { ]; } + /** + * @return string + */ public static function deniedDocumentMessage() { return __( 'This query document has been blocked.', 'wp-graphql-smart-cache' ); } + /** + * @return string + */ public static function notFoundDocumentMessage() { return __( 'Not Found. Only pre-defined queries are allowed.', 'wp-graphql-smart-cache' ); } diff --git a/wp-graphql-smart-cache.php b/wp-graphql-smart-cache.php index 8e25797e..6041b1c7 100644 --- a/wp-graphql-smart-cache.php +++ b/wp-graphql-smart-cache.php @@ -143,6 +143,8 @@ function () { /** * Show admin notice to admins if this plugin is active but WPGraphQL * is not active, or doesn't meet version requirements + * + * @return void */ function show_admin_notice() { From c83fe52cb85328e551b14dc8d4c9c0f6fe1eb7ba Mon Sep 17 00:00:00 2001 From: Mark Kelnar <749603+markkelnar@users.noreply.github.com> Date: Wed, 2 Aug 2023 10:49:08 -0500 Subject: [PATCH 2/2] fix docblock comment to be meaningful --- src/Admin/Editor.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Admin/Editor.php b/src/Admin/Editor.php index 4129360f..ee96165c 100644 --- a/src/Admin/Editor.php +++ b/src/Admin/Editor.php @@ -58,7 +58,7 @@ public function validate_before_save_cb( $data, $post ) { } /** - * Initialize Admin functionality for WPGraphQL + * On save, validate the form data. * * @param int $post_id post id * @return void|bool