From ba0294bc21533aa8f8825ffe398536975684362a Mon Sep 17 00:00:00 2001 From: Larry Garfield <larry@garfieldtech.com> Date: Tue, 7 Jun 2022 17:39:35 -0500 Subject: [PATCH] [BUGFIX] Work around type issues in Fluid MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fluid's TagBuilder::getAttribute() is doc-typed as returning `string`, but the description says it returns `?string`. That meant PHPStan believes the `$file !== null` check is unnecessary, when it actually is. The TagBuilder class is not in core, though, but in the typo3fluid vendored package, so it cannot be corrected from here. However, the `$attributes` array is already requested above, and then href/src is removed from it anyway because it's the same piece of data. So just reading off of the array we already have and doing missing-value handling there ourselves resolves the PHPStan issue, is slightly more consistent with what the next line does (the unset() call), and is ever so slightly faster as it skips a method call. Resolves: #97743 Releases: main Change-Id: I4b24eebdfded4c02c5d59eac2ee00d1cc036d0da Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/74828 Tested-by: core-ci <typo3@b13.com> Tested-by: Simon Schaufelberger <simonschaufi+typo3@gmail.com> Tested-by: Felix P. <f.pachowsky@neusta.de> Tested-by: Henning Liebe <h.liebe@neusta.de> Tested-by: Vanessa Räbiger <vmartens91@gmail.com> Tested-by: Stefan Bürk <stefan@buerk.tech> Reviewed-by: Simon Schaufelberger <simonschaufi+typo3@gmail.com> Reviewed-by: Felix P. <f.pachowsky@neusta.de> Reviewed-by: Henning Liebe <h.liebe@neusta.de> Reviewed-by: Vanessa Räbiger <vmartens91@gmail.com> Reviewed-by: Stefan Bürk <stefan@buerk.tech> --- Build/phpstan/phpstan-baseline.neon | 10 ---------- .../fluid/Classes/ViewHelpers/Asset/CssViewHelper.php | 2 +- .../Classes/ViewHelpers/Asset/ScriptViewHelper.php | 2 +- 3 files changed, 2 insertions(+), 12 deletions(-) diff --git a/Build/phpstan/phpstan-baseline.neon b/Build/phpstan/phpstan-baseline.neon index e82b9b5ebba4..567c1e159720 100644 --- a/Build/phpstan/phpstan-baseline.neon +++ b/Build/phpstan/phpstan-baseline.neon @@ -2705,16 +2705,6 @@ parameters: count: 1 path: ../../typo3/sysext/fluid/Classes/View/TemplatePaths.php - - - message: "#^Else branch is unreachable because previous condition is always true\\.$#" - count: 1 - path: ../../typo3/sysext/fluid/Classes/ViewHelpers/Asset/CssViewHelper.php - - - - message: "#^Else branch is unreachable because previous condition is always true\\.$#" - count: 1 - path: ../../typo3/sysext/fluid/Classes/ViewHelpers/Asset/ScriptViewHelper.php - - message: "#^Parameter \\#2 \\$attributeValue of method TYPO3Fluid\\\\Fluid\\\\Core\\\\ViewHelper\\\\TagBuilder\\:\\:addAttribute\\(\\) expects array\\|string\\|Traversable\\|null, TYPO3\\\\CMS\\\\Core\\\\Http\\\\Uri given\\.$#" count: 1 diff --git a/typo3/sysext/fluid/Classes/ViewHelpers/Asset/CssViewHelper.php b/typo3/sysext/fluid/Classes/ViewHelpers/Asset/CssViewHelper.php index 2be90bda4af0..3de645353f40 100644 --- a/typo3/sysext/fluid/Classes/ViewHelpers/Asset/CssViewHelper.php +++ b/typo3/sysext/fluid/Classes/ViewHelpers/Asset/CssViewHelper.php @@ -116,7 +116,7 @@ final class CssViewHelper extends AbstractTagBasedViewHelper $attributes['disabled'] = 'disabled'; } - $file = $this->tag->getAttribute('href'); + $file = $attributes['href'] ?? null; unset($attributes['href']); $options = [ 'priority' => $this->arguments['priority'], diff --git a/typo3/sysext/fluid/Classes/ViewHelpers/Asset/ScriptViewHelper.php b/typo3/sysext/fluid/Classes/ViewHelpers/Asset/ScriptViewHelper.php index 29a02d175006..30ef679863c8 100644 --- a/typo3/sysext/fluid/Classes/ViewHelpers/Asset/ScriptViewHelper.php +++ b/typo3/sysext/fluid/Classes/ViewHelpers/Asset/ScriptViewHelper.php @@ -112,7 +112,7 @@ final class ScriptViewHelper extends AbstractTagBasedViewHelper } } - $src = $this->tag->getAttribute('src'); + $src = $attributes['src'] ?? null; unset($attributes['src']); $options = [ 'priority' => $this->arguments['priority'], -- GitLab