From 6fd51ee86a5a773b2777360ee224d26cbada4102 Mon Sep 17 00:00:00 2001 From: Dave Long Date: Fri, 27 Oct 2023 23:05:09 +0100 Subject: [PATCH] Issue #3359001 by Spokje, smustgrave, catch: Fix PHPStan L1 errors "Function \Foo\Bar\baz invoked with X parameters, 0 required." --- .../comment/src/CommentLinkBuilder.php | 2 +- .../tests/src/Unit/CommentLinkBuilderTest.php | 2 +- .../src/Plugin/Action/BatchUserAction.php | 3 ++- .../src/Unit/Plugin/Block/ViewsBlockTest.php | 2 +- .../Unit/Routing/ViewPageControllerTest.php | 2 +- core/phpstan-baseline.neon | 25 ------------------- .../Tests/Component/Datetime/TimeTest.php | 2 +- 7 files changed, 7 insertions(+), 31 deletions(-) diff --git a/core/modules/comment/src/CommentLinkBuilder.php b/core/modules/comment/src/CommentLinkBuilder.php index 4725f882379..b7a12faab19 100644 --- a/core/modules/comment/src/CommentLinkBuilder.php +++ b/core/modules/comment/src/CommentLinkBuilder.php @@ -198,7 +198,7 @@ class CommentLinkBuilder implements CommentLinkBuilderInterface { $entity_links['comment__' . $field_name]['#attached']['library'][] = 'comment/drupal.node-new-comments-link'; // Embed the metadata for the "X new comments" link (if any) on this // entity. - $entity_links['comment__' . $field_name]['#attached']['drupalSettings']['history']['lastReadTimestamps'][$entity->id()] = (int) history_read($entity->id()); + $entity_links['comment__' . $field_name]['#attached']['drupalSettings']['history']['lastReadTimestamps'][$entity->id()] = history_read($entity->id()); $new_comments = $this->commentManager->getCountNewComments($entity); if ($new_comments > 0) { $page_number = $this->entityTypeManager diff --git a/core/modules/comment/tests/src/Unit/CommentLinkBuilderTest.php b/core/modules/comment/tests/src/Unit/CommentLinkBuilderTest.php index 1b00a4ff026..8bfe6f072a9 100644 --- a/core/modules/comment/tests/src/Unit/CommentLinkBuilderTest.php +++ b/core/modules/comment/tests/src/Unit/CommentLinkBuilderTest.php @@ -325,7 +325,7 @@ namespace Drupal\comment; if (!function_exists('history_read')) { - function history_read() { + function history_read($nid) { return 0; } diff --git a/core/modules/views/tests/modules/user_batch_action_test/src/Plugin/Action/BatchUserAction.php b/core/modules/views/tests/modules/user_batch_action_test/src/Plugin/Action/BatchUserAction.php index 9e58ca8abeb..c494903ecac 100644 --- a/core/modules/views/tests/modules/user_batch_action_test/src/Plugin/Action/BatchUserAction.php +++ b/core/modules/views/tests/modules/user_batch_action_test/src/Plugin/Action/BatchUserAction.php @@ -48,7 +48,8 @@ class BatchUserAction extends ActionBase { /** * {@inheritdoc} */ - public function execute(ContentEntityInterface $entity = NULL) { + public function execute($entity = NULL) { + assert($entity instanceof ContentEntityInterface); $this->executeMultiple([$entity]); } diff --git a/core/modules/views/tests/src/Unit/Plugin/Block/ViewsBlockTest.php b/core/modules/views/tests/src/Unit/Plugin/Block/ViewsBlockTest.php index 796c3c87a37..ed0deb1868a 100644 --- a/core/modules/views/tests/src/Unit/Plugin/Block/ViewsBlockTest.php +++ b/core/modules/views/tests/src/Unit/Plugin/Block/ViewsBlockTest.php @@ -205,7 +205,7 @@ namespace Drupal\views\Plugin\Block; if (!function_exists('views_add_contextual_links')) { - function views_add_contextual_links() { + function views_add_contextual_links(&$render_element, $location, $display_id, array $view_element = NULL) { } } diff --git a/core/modules/views/tests/src/Unit/Routing/ViewPageControllerTest.php b/core/modules/views/tests/src/Unit/Routing/ViewPageControllerTest.php index 935fd655b89..841fe19c477 100644 --- a/core/modules/views/tests/src/Unit/Routing/ViewPageControllerTest.php +++ b/core/modules/views/tests/src/Unit/Routing/ViewPageControllerTest.php @@ -188,7 +188,7 @@ namespace Drupal\views\Routing; if (!function_exists('views_add_contextual_links')) { - function views_add_contextual_links() { + function views_add_contextual_links(&$render_element, $location, $display_id, array $view_element = NULL) { } } diff --git a/core/phpstan-baseline.neon b/core/phpstan-baseline.neon index f0059260781..7b72c276ebb 100644 --- a/core/phpstan-baseline.neon +++ b/core/phpstan-baseline.neon @@ -68,11 +68,6 @@ parameters: count: 1 path: lib/Drupal/Component/Datetime/DateTimePlus.php - - - message: "#^Function Drupal\\\\Component\\\\Datetime\\\\microtime invoked with 1 parameter, 0 required\\.$#" - count: 1 - path: lib/Drupal/Component/Datetime/Time.php - - message: """ #^Usage of deprecated trait Drupal\\\\Component\\\\DependencyInjection\\\\ServiceIdHashTrait in class Drupal\\\\Component\\\\DependencyInjection\\\\Container\\: @@ -984,16 +979,6 @@ parameters: count: 1 path: modules/comment/src/CommentForm.php - - - message: "#^Function Drupal\\\\comment\\\\history_read invoked with 1 parameter, 0 required\\.$#" - count: 1 - path: modules/comment/src/CommentLinkBuilder.php - - - - message: "#^Function Drupal\\\\comment\\\\history_read invoked with 1 parameter, 0 required\\.$#" - count: 1 - path: modules/comment/src/CommentManager.php - - message: "#^Call to deprecated constant REQUEST_TIME\\: Deprecated in drupal\\:8\\.3\\.0 and is removed from drupal\\:11\\.0\\.0\\. Use \\\\Drupal\\:\\:time\\(\\)\\-\\>getRequestTime\\(\\); $#" count: 2 @@ -2345,11 +2330,6 @@ parameters: count: 1 path: modules/views/src/Form/ViewsFormMainForm.php - - - message: "#^Function Drupal\\\\views\\\\Plugin\\\\Block\\\\views_add_contextual_links invoked with 3 parameters, 0 required\\.$#" - count: 1 - path: modules/views/src/Plugin/Block/ViewsBlockBase.php - - message: "#^Variable \\$display in isset\\(\\) always exists and is not nullable\\.$#" count: 1 @@ -2600,11 +2580,6 @@ parameters: count: 1 path: modules/views/src/Plugin/views/wizard/WizardPluginBase.php - - - message: "#^Function Drupal\\\\views\\\\Routing\\\\views_add_contextual_links invoked with 4 parameters, 0 required\\.$#" - count: 1 - path: modules/views/src/Routing/ViewPageController.php - - message: "#^Call to deprecated constant REQUEST_TIME\\: Deprecated in drupal\\:8\\.3\\.0 and is removed from drupal\\:11\\.0\\.0\\. Use \\\\Drupal\\:\\:time\\(\\)\\-\\>getRequestTime\\(\\); $#" count: 1 diff --git a/core/tests/Drupal/Tests/Component/Datetime/TimeTest.php b/core/tests/Drupal/Tests/Component/Datetime/TimeTest.php index b9aa8016550..f5de7d97082 100644 --- a/core/tests/Drupal/Tests/Component/Datetime/TimeTest.php +++ b/core/tests/Drupal/Tests/Component/Datetime/TimeTest.php @@ -141,6 +141,6 @@ function time() { * * @return float */ -function microtime() { +function microtime(bool $as_float = FALSE) { return 1234567.89; }