From f361946091e397cf29e794b76103c3cbb40a51a4 Mon Sep 17 00:00:00 2001
From: Mark Kelnar <749603+markkelnar@users.noreply.github.com>
Date: Tue, 1 Aug 2023 14:31:10 -0500
Subject: [PATCH 1/3] phpstand level 7
---
composer.lock | 36 ++++++++++++++++++------------------
phpstan.neon.dist | 2 +-
src/Cache/Results.php | 2 +-
src/Document.php | 6 +++---
src/Document/MaxAge.php | 6 ++++--
src/Utils.php | 7 ++++---
6 files changed, 31 insertions(+), 28 deletions(-)
diff --git a/composer.lock b/composer.lock
index 6aaf7cc6..df648e7a 100644
--- a/composer.lock
+++ b/composer.lock
@@ -1644,16 +1644,16 @@
},
{
"name": "illuminate/collections",
- "version": "v10.16.1",
+ "version": "v10.17.0",
"source": {
"type": "git",
"url": "https://github.com/illuminate/collections.git",
- "reference": "07ec467c42b90ec6e7e2faec381e3457dcfd5571"
+ "reference": "bc030c443fc43776070b96d66257c3b29153f30a"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/illuminate/collections/zipball/07ec467c42b90ec6e7e2faec381e3457dcfd5571",
- "reference": "07ec467c42b90ec6e7e2faec381e3457dcfd5571",
+ "url": "https://api.github.com/repos/illuminate/collections/zipball/bc030c443fc43776070b96d66257c3b29153f30a",
+ "reference": "bc030c443fc43776070b96d66257c3b29153f30a",
"shasum": ""
},
"require": {
@@ -1695,11 +1695,11 @@
"issues": "https://github.com/laravel/framework/issues",
"source": "https://github.com/laravel/framework"
},
- "time": "2023-07-24T14:56:19+00:00"
+ "time": "2023-07-27T15:19:34+00:00"
},
{
"name": "illuminate/conditionable",
- "version": "v10.16.1",
+ "version": "v10.17.0",
"source": {
"type": "git",
"url": "https://github.com/illuminate/conditionable.git",
@@ -1745,16 +1745,16 @@
},
{
"name": "illuminate/contracts",
- "version": "v10.16.1",
+ "version": "v10.17.0",
"source": {
"type": "git",
"url": "https://github.com/illuminate/contracts.git",
- "reference": "ec47d1aa1a1b1a679d8553836b417343881b8215"
+ "reference": "eb1a7e72e159136a832f2c0467de5570bdc208ae"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/illuminate/contracts/zipball/ec47d1aa1a1b1a679d8553836b417343881b8215",
- "reference": "ec47d1aa1a1b1a679d8553836b417343881b8215",
+ "url": "https://api.github.com/repos/illuminate/contracts/zipball/eb1a7e72e159136a832f2c0467de5570bdc208ae",
+ "reference": "eb1a7e72e159136a832f2c0467de5570bdc208ae",
"shasum": ""
},
"require": {
@@ -1789,11 +1789,11 @@
"issues": "https://github.com/laravel/framework/issues",
"source": "https://github.com/laravel/framework"
},
- "time": "2023-06-27T14:35:49+00:00"
+ "time": "2023-07-26T21:27:34+00:00"
},
{
"name": "illuminate/macroable",
- "version": "v10.16.1",
+ "version": "v10.17.0",
"source": {
"type": "git",
"url": "https://github.com/illuminate/macroable.git",
@@ -1839,16 +1839,16 @@
},
{
"name": "illuminate/support",
- "version": "v10.16.1",
+ "version": "v10.17.0",
"source": {
"type": "git",
"url": "https://github.com/illuminate/support.git",
- "reference": "40b87e80d150339bc186256576e11ea3be3d0ff5"
+ "reference": "7549dd081cc45c742b7d97064b64cf67fab4c7b6"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/illuminate/support/zipball/40b87e80d150339bc186256576e11ea3be3d0ff5",
- "reference": "40b87e80d150339bc186256576e11ea3be3d0ff5",
+ "url": "https://api.github.com/repos/illuminate/support/zipball/7549dd081cc45c742b7d97064b64cf67fab4c7b6",
+ "reference": "7549dd081cc45c742b7d97064b64cf67fab4c7b6",
"shasum": ""
},
"require": {
@@ -1860,7 +1860,7 @@
"illuminate/conditionable": "^10.0",
"illuminate/contracts": "^10.0",
"illuminate/macroable": "^10.0",
- "nesbot/carbon": "^2.62.1",
+ "nesbot/carbon": "^2.67",
"php": "^8.1",
"voku/portable-ascii": "^2.0"
},
@@ -1906,7 +1906,7 @@
"issues": "https://github.com/laravel/framework/issues",
"source": "https://github.com/laravel/framework"
},
- "time": "2023-07-25T19:33:34+00:00"
+ "time": "2023-07-31T15:02:41+00:00"
},
{
"name": "ivome/graphql-relay-php",
diff --git a/phpstan.neon.dist b/phpstan.neon.dist
index 26605199..16672ff5 100644
--- a/phpstan.neon.dist
+++ b/phpstan.neon.dist
@@ -1,5 +1,5 @@
parameters:
- level: 6
+ level: 7
inferPrivatePropertyTypeFromConstructor: true
checkMissingIterableValueType: false
stubFiles:
diff --git a/src/Cache/Results.php b/src/Cache/Results.php
index c5bb8021..27b2e850 100644
--- a/src/Cache/Results.php
+++ b/src/Cache/Results.php
@@ -90,7 +90,7 @@ public function add_cache_key_to_response_extensions(
if ( is_array( $response ) ) {
$response['extensions']['graphqlSmartCache']['graphqlObjectCache'] = $message;
- } if ( is_object( $response ) ) {
+ } if ( is_object( $response ) && property_exists( $response, 'extensions' ) ) {
$response->extensions['graphqlSmartCache']['graphqlObjectCache'] = $message;
}
}
diff --git a/src/Document.php b/src/Document.php
index a47501cc..d0c01f59 100644
--- a/src/Document.php
+++ b/src/Document.php
@@ -183,7 +183,7 @@ public function graphql_mutation_insert( $post_object, $filtered_input, $input,
// Remove the existing/old alias terms before update
$terms = wp_get_post_terms( $post_object['postObjectId'], self::ALIAS_TAXONOMY_NAME );
- if ( $terms ) {
+ if ( $terms && ! is_wp_error( $terms ) ) {
foreach ( $terms as $term ) {
wp_remove_object_terms( $post_object['postObjectId'], $term->term_id, self::ALIAS_TAXONOMY_NAME );
wp_delete_term( $term->term_id, self::ALIAS_TAXONOMY_NAME );
@@ -353,7 +353,7 @@ public function after_updated_cb( $post_ID, $post_after, $post_before ) {
// If the old query string hash is assigned to this post, delete it
$terms = wp_get_post_terms( $post_ID, self::ALIAS_TAXONOMY_NAME );
- if ( $terms ) {
+ if ( $terms && ! is_wp_error( $terms ) ) {
foreach ( $terms as $term ) {
if ( $old_query_id === $term->name ) {
wp_remove_object_terms( $post_ID, $term->term_id, self::ALIAS_TAXONOMY_NAME );
@@ -469,7 +469,7 @@ public function delete_post_cb( $post_id ) {
*/
public function delete_term( $post_id ) {
$terms = wp_get_object_terms( $post_id, self::ALIAS_TAXONOMY_NAME );
- if ( $terms ) {
+ if ( $terms && ! is_wp_error( $terms ) ) {
foreach ( $terms as $term ) {
wp_delete_term( $term->term_id, self::ALIAS_TAXONOMY_NAME );
}
diff --git a/src/Document/MaxAge.php b/src/Document/MaxAge.php
index 8bfb647e..33eeb845 100644
--- a/src/Document/MaxAge.php
+++ b/src/Document/MaxAge.php
@@ -152,8 +152,10 @@ public function get( $post_id ) {
if ( is_wp_error( $item ) ) {
return $item;
}
-
- return property_exists( $item[0], 'name' ) ? $item[0]->name : null;
+ if ( ! $item || ! property_exists( $item[0], 'name' ) ) {
+ return null;
+ }
+ return $item[0]->name;
}
/**
diff --git a/src/Utils.php b/src/Utils.php
index 5bda6028..eee4a32c 100644
--- a/src/Utils.php
+++ b/src/Utils.php
@@ -14,7 +14,7 @@ class Utils {
* @param string|array $type
* @param string $taxonomy
*
- * @return \WP_Post|bool false when not exist
+ * @return \WP_Post|false false when not exist
*/
public static function getPostByTermName( $query_id, $type, $taxonomy ) {
$wp_query = new \WP_Query(
@@ -32,13 +32,14 @@ public static function getPostByTermName( $query_id, $type, $taxonomy ) {
],
]
);
- $posts = $wp_query->get_posts();
+ // returns an array of post objects.
+ $posts = $wp_query->get_posts();
if ( empty( $posts ) ) {
return false;
}
$post = array_pop( $posts );
- if ( ! $post->ID ) {
+ if ( ! ( $post instanceof \WP_Post ) || ! $post->ID ) {
return false;
}
From 6b9b29351cea113c70aaf8bc8e82c6460f8f9510 Mon Sep 17 00:00:00 2001
From: Mark Kelnar <749603+markkelnar@users.noreply.github.com>
Date: Wed, 2 Aug 2023 10:05:48 -0500
Subject: [PATCH 2/3] phpstan level 7 changes
---
composer.lock | 12 +++++------
src/Admin/Editor.php | 41 ++++++++++++++++++++++++++------------
src/AdminErrors.php | 18 ++++++++++-------
src/Cache/Collection.php | 4 ++++
src/Cache/Invalidation.php | 16 ++++++++++++---
src/Cache/Query.php | 11 ++++++++--
6 files changed, 71 insertions(+), 31 deletions(-)
diff --git a/composer.lock b/composer.lock
index df648e7a..ab01a5d9 100644
--- a/composer.lock
+++ b/composer.lock
@@ -4293,16 +4293,16 @@
},
{
"name": "sebastian/global-state",
- "version": "5.0.5",
+ "version": "5.0.6",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/global-state.git",
- "reference": "0ca8db5a5fc9c8646244e629625ac486fa286bf2"
+ "reference": "bde739e7565280bda77be70044ac1047bc007e34"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/0ca8db5a5fc9c8646244e629625ac486fa286bf2",
- "reference": "0ca8db5a5fc9c8646244e629625ac486fa286bf2",
+ "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/bde739e7565280bda77be70044ac1047bc007e34",
+ "reference": "bde739e7565280bda77be70044ac1047bc007e34",
"shasum": ""
},
"require": {
@@ -4345,7 +4345,7 @@
],
"support": {
"issues": "https://github.com/sebastianbergmann/global-state/issues",
- "source": "https://github.com/sebastianbergmann/global-state/tree/5.0.5"
+ "source": "https://github.com/sebastianbergmann/global-state/tree/5.0.6"
},
"funding": [
{
@@ -4353,7 +4353,7 @@
"type": "github"
}
],
- "time": "2022-02-14T08:28:10+00:00"
+ "time": "2023-08-02T09:26:13+00:00"
},
{
"name": "sebastian/lines-of-code",
diff --git a/src/Admin/Editor.php b/src/Admin/Editor.php
index 4129360f..9234a0b4 100644
--- a/src/Admin/Editor.php
+++ b/src/Admin/Editor.php
@@ -170,18 +170,21 @@ public static function grant_input_box_cb( $post ) {
checked( $value, Grant::USE_DEFAULT, false )
);
$html .= '
';
+
+ /** @var array[] */
+ $allowed_html = [
+ 'input' => [
+ 'type' => true,
+ 'id' => true,
+ 'name' => true,
+ 'value' => true,
+ 'checked' => true,
+ ],
+ 'br' => true,
+ ];
echo wp_kses(
$html,
- [
- 'input' => [
- 'type' => true,
- 'id' => true,
- 'name' => true,
- 'value' => true,
- 'checked' => true,
- ],
- 'br' => true,
- ]
+ $allowed_html
);
}
@@ -196,9 +199,21 @@ public static function maxage_input_box_cb( $post ) {
$max_age = new MaxAge();
$value = $max_age->get( $post->ID );
- $value = absint( $value ) ? $value : 0;
- $html = sprintf( '', $value );
- $html .= '
';
+
+ if ( is_wp_error( $value ) ) {
+ AdminErrors::add_message(
+ sprintf(
+ __( 'Invalid max age %s.', 'wp-graphql-smart-cache' ),
+ $value->get_error_message()
+ )
+ );
+ $value = 0;
+ } else {
+ $value = absint( $value ) ? $value : 0;
+ }
+
+ $html = sprintf( '', $value );
+ $html .= '
';
echo wp_kses(
$html,
[
diff --git a/src/AdminErrors.php b/src/AdminErrors.php
index f66bc234..48a2fa28 100644
--- a/src/AdminErrors.php
+++ b/src/AdminErrors.php
@@ -45,15 +45,19 @@ public function display_validation_messages() {
foreach ( $error_messages as $message ) {
$html = sprintf( '
%s