Skip to content

Commit

Permalink
[TASK] Fix the return type annotation of getIndpEnv
Browse files Browse the repository at this point in the history
GeneralUtility::getIndpEnv can also return values other than string,
e.g., PATH_INFO might return null, and TYPO3_SSL will return a
bool. Also, _ARRAY will return an array of all possible scalar
values.

The return type annotation needs to correctly reflect that in order
for static type analysis to be able to work correctly when this
function is called.

Resolves: #97020
Releases: main, 11.5
Change-Id: Ibb24f1a3451c6598452402fc7a7b0a96c66bbd01
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/73734
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
  • Loading branch information
oliverklee authored and lolli42 committed Feb 27, 2022
1 parent 8e5e574 commit bed06ae
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 12 deletions.
10 changes: 0 additions & 10 deletions Build/phpstan/phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -1445,11 +1445,6 @@ parameters:
count: 1
path: ../../typo3/sysext/core/Classes/Locking/SemaphoreLockStrategy.php

-
message: "#^Parameter \\#1 \\$data of method TYPO3\\\\CMS\\\\Core\\\\Log\\\\LogRecord\\:\\:addData\\(\\) expects array, string given\\.$#"
count: 1
path: ../../typo3/sysext/core/Classes/Log/Processor/WebProcessor.php

-
message: "#^Negated boolean expression is always false\\.$#"
count: 1
Expand Down Expand Up @@ -2625,11 +2620,6 @@ parameters:
count: 1
path: ../../typo3/sysext/core/Tests/Unit/Log/Fixtures/WriterFixture.php

-
message: "#^Argument of an invalid type string supplied for foreach, only iterables are supported\\.$#"
count: 1
path: ../../typo3/sysext/core/Tests/Unit/Log/Processor/WebProcessorTest.php

-
message: "#^Call to an undefined method org\\\\bovigo\\\\vfs\\\\vfsStreamContent\\:\\:hasChild\\(\\)\\.$#"
count: 1
Expand Down
4 changes: 2 additions & 2 deletions typo3/sysext/core/Classes/Utility/GeneralUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class GeneralUtility
protected static $finalClassNameCache = [];

/**
* @var array<string, mixed>
* @var array<string, string|bool|array<string, string|bool|null>|null>
*/
protected static $indpEnvCache = [];

Expand Down Expand Up @@ -2402,7 +2402,7 @@ public static function setIndpEnv($envName, $value)
* This should be used instead of getEnv() and $_SERVER/ENV_VARS to get reliable values for all situations.
*
* @param string $getEnvName Name of the "environment variable"/"server variable" you wish to use. Valid values are SCRIPT_NAME, SCRIPT_FILENAME, REQUEST_URI, PATH_INFO, REMOTE_ADDR, REMOTE_HOST, HTTP_REFERER, HTTP_HOST, HTTP_USER_AGENT, HTTP_ACCEPT_LANGUAGE, QUERY_STRING, TYPO3_DOCUMENT_ROOT, TYPO3_HOST_ONLY, TYPO3_HOST_ONLY, TYPO3_REQUEST_HOST, TYPO3_REQUEST_URL, TYPO3_REQUEST_SCRIPT, TYPO3_REQUEST_DIR, TYPO3_SITE_URL, _ARRAY
* @return string Value based on the input key, independent of server/os environment.
* @return string|bool|array<string, string|bool|null>|null Value based on the input key, independent of server/OS environment.
* @throws \UnexpectedValueException
*/
public static function getIndpEnv($getEnvName)
Expand Down

0 comments on commit bed06ae

Please sign in to comment.