From f0b4a2455c5fbeff9bed518a38a35531f693dc11 Mon Sep 17 00:00:00 2001
From: Lee Rowlands <lee.rowlands@previousnext.com.au>
Date: Thu, 19 Dec 2024 11:42:18 +1000
Subject: [PATCH] Issue #3490964 by nexusnovaz, mstrelan: Add array return to
 all hook_jsonapi_ENTITY_TYPE_filter_access hook implementations

---
 core/.phpstan-baseline.php                    | 66 -------------------
 core/modules/jsonapi/jsonapi.api.php          |  2 +-
 .../modules/jsonapi/src/Hook/JsonapiHooks.php | 23 +++----
 3 files changed, 13 insertions(+), 78 deletions(-)

diff --git a/core/.phpstan-baseline.php b/core/.phpstan-baseline.php
index 604e3c40ed50..406d87679c21 100644
--- a/core/.phpstan-baseline.php
+++ b/core/.phpstan-baseline.php
@@ -21736,72 +21736,6 @@
 	'count' => 1,
 	'path' => __DIR__ . '/modules/jsonapi/src/Hook/JsonapiHooks.php',
 ];
-$ignoreErrors[] = [
-	// identifier: missingType.return
-	'message' => '#^Method Drupal\\\\jsonapi\\\\Hook\\\\JsonapiHooks\\:\\:jsonapiBlockContentFilterAccess\\(\\) has no return type specified\\.$#',
-	'count' => 1,
-	'path' => __DIR__ . '/modules/jsonapi/src/Hook/JsonapiHooks.php',
-];
-$ignoreErrors[] = [
-	// identifier: missingType.return
-	'message' => '#^Method Drupal\\\\jsonapi\\\\Hook\\\\JsonapiHooks\\:\\:jsonapiCommentFilterAccess\\(\\) has no return type specified\\.$#',
-	'count' => 1,
-	'path' => __DIR__ . '/modules/jsonapi/src/Hook/JsonapiHooks.php',
-];
-$ignoreErrors[] = [
-	// identifier: missingType.return
-	'message' => '#^Method Drupal\\\\jsonapi\\\\Hook\\\\JsonapiHooks\\:\\:jsonapiEntityFilterAccess\\(\\) has no return type specified\\.$#',
-	'count' => 1,
-	'path' => __DIR__ . '/modules/jsonapi/src/Hook/JsonapiHooks.php',
-];
-$ignoreErrors[] = [
-	// identifier: missingType.return
-	'message' => '#^Method Drupal\\\\jsonapi\\\\Hook\\\\JsonapiHooks\\:\\:jsonapiEntityTestFilterAccess\\(\\) has no return type specified\\.$#',
-	'count' => 1,
-	'path' => __DIR__ . '/modules/jsonapi/src/Hook/JsonapiHooks.php',
-];
-$ignoreErrors[] = [
-	// identifier: missingType.return
-	'message' => '#^Method Drupal\\\\jsonapi\\\\Hook\\\\JsonapiHooks\\:\\:jsonapiFileFilterAccess\\(\\) has no return type specified\\.$#',
-	'count' => 1,
-	'path' => __DIR__ . '/modules/jsonapi/src/Hook/JsonapiHooks.php',
-];
-$ignoreErrors[] = [
-	// identifier: missingType.return
-	'message' => '#^Method Drupal\\\\jsonapi\\\\Hook\\\\JsonapiHooks\\:\\:jsonapiMediaFilterAccess\\(\\) has no return type specified\\.$#',
-	'count' => 1,
-	'path' => __DIR__ . '/modules/jsonapi/src/Hook/JsonapiHooks.php',
-];
-$ignoreErrors[] = [
-	// identifier: missingType.return
-	'message' => '#^Method Drupal\\\\jsonapi\\\\Hook\\\\JsonapiHooks\\:\\:jsonapiNodeFilterAccess\\(\\) has no return type specified\\.$#',
-	'count' => 1,
-	'path' => __DIR__ . '/modules/jsonapi/src/Hook/JsonapiHooks.php',
-];
-$ignoreErrors[] = [
-	// identifier: missingType.return
-	'message' => '#^Method Drupal\\\\jsonapi\\\\Hook\\\\JsonapiHooks\\:\\:jsonapiShortcutFilterAccess\\(\\) has no return type specified\\.$#',
-	'count' => 1,
-	'path' => __DIR__ . '/modules/jsonapi/src/Hook/JsonapiHooks.php',
-];
-$ignoreErrors[] = [
-	// identifier: missingType.return
-	'message' => '#^Method Drupal\\\\jsonapi\\\\Hook\\\\JsonapiHooks\\:\\:jsonapiTaxonomyTermFilterAccess\\(\\) has no return type specified\\.$#',
-	'count' => 1,
-	'path' => __DIR__ . '/modules/jsonapi/src/Hook/JsonapiHooks.php',
-];
-$ignoreErrors[] = [
-	// identifier: missingType.return
-	'message' => '#^Method Drupal\\\\jsonapi\\\\Hook\\\\JsonapiHooks\\:\\:jsonapiUserFilterAccess\\(\\) has no return type specified\\.$#',
-	'count' => 1,
-	'path' => __DIR__ . '/modules/jsonapi/src/Hook/JsonapiHooks.php',
-];
-$ignoreErrors[] = [
-	// identifier: missingType.return
-	'message' => '#^Method Drupal\\\\jsonapi\\\\Hook\\\\JsonapiHooks\\:\\:jsonapiWorkspaceFilterAccess\\(\\) has no return type specified\\.$#',
-	'count' => 1,
-	'path' => __DIR__ . '/modules/jsonapi/src/Hook/JsonapiHooks.php',
-];
 $ignoreErrors[] = [
 	// identifier: missingType.return
 	'message' => '#^Method Drupal\\\\jsonapi\\\\JsonApiResource\\\\Data\\:\\:getTotalCount\\(\\) has no return type specified\\.$#',
diff --git a/core/modules/jsonapi/jsonapi.api.php b/core/modules/jsonapi/jsonapi.api.php
index 54033a137c4c..5b2f2002d25c 100644
--- a/core/modules/jsonapi/jsonapi.api.php
+++ b/core/modules/jsonapi/jsonapi.api.php
@@ -303,7 +303,7 @@ function hook_jsonapi_entity_filter_access(EntityTypeInterface $entity_type, Acc
  *
  * @see hook_jsonapi_entity_filter_access()
  */
-function hook_jsonapi_ENTITY_TYPE_filter_access(EntityTypeInterface $entity_type, AccountInterface $account) {
+function hook_jsonapi_ENTITY_TYPE_filter_access(EntityTypeInterface $entity_type, AccountInterface $account): array {
   return ([
     JSONAPI_FILTER_AMONG_ALL => AccessResult::allowedIfHasPermission($account, 'administer llamas'),
     JSONAPI_FILTER_AMONG_PUBLISHED => AccessResult::allowedIfHasPermission($account, 'view all published llamas'),
diff --git a/core/modules/jsonapi/src/Hook/JsonapiHooks.php b/core/modules/jsonapi/src/Hook/JsonapiHooks.php
index 1372a656e910..224a807c638e 100644
--- a/core/modules/jsonapi/src/Hook/JsonapiHooks.php
+++ b/core/modules/jsonapi/src/Hook/JsonapiHooks.php
@@ -96,7 +96,7 @@ public function entityDelete(EntityInterface $entity) {
    * Implements hook_jsonapi_entity_filter_access().
    */
   #[Hook('jsonapi_entity_filter_access')]
-  public function jsonapiEntityFilterAccess(EntityTypeInterface $entity_type, AccountInterface $account) {
+  public function jsonapiEntityFilterAccess(EntityTypeInterface $entity_type, AccountInterface $account): array {
     // All core entity types and most or all contrib entity types allow users
     // with the entity type's administrative permission to view all of the
     // entities, so enable similarly permissive filtering to those users as well.
@@ -107,13 +107,14 @@ public function jsonapiEntityFilterAccess(EntityTypeInterface $entity_type, Acco
         JSONAPI_FILTER_AMONG_ALL => AccessResult::allowedIfHasPermission($account, $admin_permission),
       ];
     }
+    return [];
   }
 
   /**
    * Implements hook_jsonapi_ENTITY_TYPE_filter_access() for 'block_content'.
    */
   #[Hook('jsonapi_block_content_filter_access')]
-  public function jsonapiBlockContentFilterAccess(EntityTypeInterface $entity_type, AccountInterface $account) {
+  public function jsonapiBlockContentFilterAccess(EntityTypeInterface $entity_type, AccountInterface $account): array {
     // @see \Drupal\block_content\BlockContentAccessControlHandler::checkAccess()
     // \Drupal\jsonapi\Access\TemporaryQueryGuard adds the condition for
     // (isReusable()), so this does not have to.
@@ -127,7 +128,7 @@ public function jsonapiBlockContentFilterAccess(EntityTypeInterface $entity_type
    * Implements hook_jsonapi_ENTITY_TYPE_filter_access() for 'comment'.
    */
   #[Hook('jsonapi_comment_filter_access')]
-  public function jsonapiCommentFilterAccess(EntityTypeInterface $entity_type, AccountInterface $account) {
+  public function jsonapiCommentFilterAccess(EntityTypeInterface $entity_type, AccountInterface $account): array {
     // @see \Drupal\comment\CommentAccessControlHandler::checkAccess()
     // \Drupal\jsonapi\Access\TemporaryQueryGuard adds the condition for
     // (access to the commented entity), so this does not have to.
@@ -141,7 +142,7 @@ public function jsonapiCommentFilterAccess(EntityTypeInterface $entity_type, Acc
    * Implements hook_jsonapi_ENTITY_TYPE_filter_access() for 'entity_test'.
    */
   #[Hook('jsonapi_entity_test_filter_access')]
-  public function jsonapiEntityTestFilterAccess(EntityTypeInterface $entity_type, AccountInterface $account) {
+  public function jsonapiEntityTestFilterAccess(EntityTypeInterface $entity_type, AccountInterface $account): array {
     // @see \Drupal\entity_test\EntityTestAccessControlHandler::checkAccess()
     return [
       JSONAPI_FILTER_AMONG_ALL => AccessResult::allowedIfHasPermission($account, 'view test entity'),
@@ -152,7 +153,7 @@ public function jsonapiEntityTestFilterAccess(EntityTypeInterface $entity_type,
    * Implements hook_jsonapi_ENTITY_TYPE_filter_access() for 'file'.
    */
   #[Hook('jsonapi_file_filter_access')]
-  public function jsonapiFileFilterAccess(EntityTypeInterface $entity_type, AccountInterface $account) {
+  public function jsonapiFileFilterAccess(EntityTypeInterface $entity_type, AccountInterface $account): array {
     // @see \Drupal\file\FileAccessControlHandler::checkAccess()
     // \Drupal\jsonapi\Access\TemporaryQueryGuard adds the condition for
     // (public OR owner), so this does not have to.
@@ -165,7 +166,7 @@ public function jsonapiFileFilterAccess(EntityTypeInterface $entity_type, Accoun
    * Implements hook_jsonapi_ENTITY_TYPE_filter_access() for 'media'.
    */
   #[Hook('jsonapi_media_filter_access')]
-  public function jsonapiMediaFilterAccess(EntityTypeInterface $entity_type, AccountInterface $account) {
+  public function jsonapiMediaFilterAccess(EntityTypeInterface $entity_type, AccountInterface $account): array {
     // @see \Drupal\media\MediaAccessControlHandler::checkAccess()
     return [
       JSONAPI_FILTER_AMONG_PUBLISHED => AccessResult::allowedIfHasPermission($account, 'view media'),
@@ -176,7 +177,7 @@ public function jsonapiMediaFilterAccess(EntityTypeInterface $entity_type, Accou
    * Implements hook_jsonapi_ENTITY_TYPE_filter_access() for 'node'.
    */
   #[Hook('jsonapi_node_filter_access')]
-  public function jsonapiNodeFilterAccess(EntityTypeInterface $entity_type, AccountInterface $account) {
+  public function jsonapiNodeFilterAccess(EntityTypeInterface $entity_type, AccountInterface $account): array {
     // @see \Drupal\node\NodeAccessControlHandler::access()
     if ($account->hasPermission('bypass node access')) {
       return [
@@ -211,7 +212,7 @@ public function jsonapiNodeFilterAccess(EntityTypeInterface $entity_type, Accoun
    * Implements hook_jsonapi_ENTITY_TYPE_filter_access() for 'shortcut'.
    */
   #[Hook('jsonapi_shortcut_filter_access')]
-  public function jsonapiShortcutFilterAccess(EntityTypeInterface $entity_type, AccountInterface $account) {
+  public function jsonapiShortcutFilterAccess(EntityTypeInterface $entity_type, AccountInterface $account): array {
     // @see \Drupal\shortcut\ShortcutAccessControlHandler::checkAccess()
     // \Drupal\jsonapi\Access\TemporaryQueryGuard adds the condition for
     // (shortcut_set = $shortcut_set_storage->getDisplayedToUser($current_user)),
@@ -228,7 +229,7 @@ public function jsonapiShortcutFilterAccess(EntityTypeInterface $entity_type, Ac
    * Implements hook_jsonapi_ENTITY_TYPE_filter_access() for 'taxonomy_term'.
    */
   #[Hook('jsonapi_taxonomy_term_filter_access')]
-  public function jsonapiTaxonomyTermFilterAccess(EntityTypeInterface $entity_type, AccountInterface $account) {
+  public function jsonapiTaxonomyTermFilterAccess(EntityTypeInterface $entity_type, AccountInterface $account): array {
     // @see \Drupal\taxonomy\TermAccessControlHandler::checkAccess()
     return [
       JSONAPI_FILTER_AMONG_ALL => AccessResult::allowedIfHasPermission($account, 'administer taxonomy'),
@@ -240,7 +241,7 @@ public function jsonapiTaxonomyTermFilterAccess(EntityTypeInterface $entity_type
    * Implements hook_jsonapi_ENTITY_TYPE_filter_access() for 'user'.
    */
   #[Hook('jsonapi_user_filter_access')]
-  public function jsonapiUserFilterAccess(EntityTypeInterface $entity_type, AccountInterface $account) {
+  public function jsonapiUserFilterAccess(EntityTypeInterface $entity_type, AccountInterface $account): array {
     // @see \Drupal\user\UserAccessControlHandler::checkAccess()
     // \Drupal\jsonapi\Access\TemporaryQueryGuard adds the condition for
     // (!isAnonymous()), so this does not have to.
@@ -254,7 +255,7 @@ public function jsonapiUserFilterAccess(EntityTypeInterface $entity_type, Accoun
    * Implements hook_jsonapi_ENTITY_TYPE_filter_access() for 'workspace'.
    */
   #[Hook('jsonapi_workspace_filter_access')]
-  public function jsonapiWorkspaceFilterAccess(EntityTypeInterface $entity_type, AccountInterface $account) {
+  public function jsonapiWorkspaceFilterAccess(EntityTypeInterface $entity_type, AccountInterface $account): array {
     // @see \Drupal\workspaces\WorkspaceAccessControlHandler::checkAccess()
     return [
       JSONAPI_FILTER_AMONG_ALL => AccessResult::allowedIfHasPermission($account, 'view any workspace'),
-- 
GitLab