Skip to content

Markup context should not be nullable #1019

Description

@MakerTim

Ha team phpstan-drupal!

Today we got the following error:

TypeError: Drupal\\Component\\Utility\\Html::escape(): Argument #1 ($text) must be of type string, null given, called in /var/www/html/app/core/lib/Drupal/Component/Render/FormattableMarkup.php on line 238 in Drupal\\Component\\Utility\\Html::escape() (line 433 of /var/www/html/app/core/lib/Drupal/Component/Utility/Html.php

And a custom module was the cause, FormattableMarkup (and TranslatableMarkup) allows null in the $arguments array.
This should be illigal, since they put the value (straight) trough Html::escape, where the argument is typed to a non nullable string

tldr:
places that call Html::escape should be checked to be string/stringable
can we type-hint FormattableMarkup (and TranslatableMarkup) so we can staticly analyze these places

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions