Skip to content

Commit

Permalink
[TASK] Fix phpstan checkFunctionArgumentTypes errors in ext:core Auth…
Browse files Browse the repository at this point in the history
…entication

This patch fixes incompatible type usage in function arguments
and is preparatory work for introducing native type hints and
strict mode in all core files.

Releases: master, 10.4
Resolves: #92268
Change-Id: Ic8b6ce1a310181167728d3edd930dcfc18351266
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/65826
Reviewed-by: Oliver Klee <typo3-coding@oliverklee.de>
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Benni Mack <benni@typo3.org>
  • Loading branch information
alexanderschnitzler authored and bmack committed Sep 23, 2020
1 parent 1a32e1e commit b5cf1fa
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
Expand Up @@ -1048,7 +1048,7 @@ public function removeCookie($cookieName)
$cookieDomain = $this->getCookieDomain();
// If no cookie domain is set, use the base path
$cookiePath = $cookieDomain ? '/' : GeneralUtility::getIndpEnv('TYPO3_SITE_PATH');
setcookie($cookieName, null, -1, $cookiePath, $cookieDomain);
setcookie($cookieName, '', -1, $cookiePath, $cookieDomain);
}

/**
Expand Down Expand Up @@ -1342,7 +1342,7 @@ public function getAuthInfoArray()
$authInfo['db_user']['checkPidList'] = $this->checkPid_value;
$authInfo['db_user']['check_pid_clause'] = $expressionBuilder->in(
'pid',
GeneralUtility::intExplode(',', $this->checkPid_value)
GeneralUtility::intExplode(',', (string)$this->checkPid_value)
);
} else {
$authInfo['db_user']['checkPidList'] = '';
Expand Down
Expand Up @@ -320,7 +320,7 @@ public function getSubGroups($grList, $idList, &$groups)
// Get row:
$row = $groupRows[$uid];
// Must be an array and $uid should not be in the idList, because then it is somewhere previously in the grouplist
if (is_array($row) && !GeneralUtility::inList($idList, $uid) && trim($row['subgroup'])) {
if (is_array($row) && !GeneralUtility::inList($idList, (string)$uid) && trim($row['subgroup'])) {
// Make integer list
$theList = implode(',', GeneralUtility::intExplode(',', $row['subgroup']));
// Call recursively, pass along list of already processed groups so they are not processed again.
Expand Down
Expand Up @@ -339,7 +339,7 @@ public function isMemberOfGroup($groupId)
{
$groupId = (int)$groupId;
if ($this->groupList && $groupId) {
return GeneralUtility::inList($this->groupList, $groupId);
return GeneralUtility::inList($this->groupList, (string)$groupId);
}
return false;
}
Expand Down Expand Up @@ -745,7 +745,7 @@ public function checkLanguageAccess($langValue)
if (trim($this->groupData['allowed_languages']) !== '') {
$langValue = (int)$langValue;
// Language must either be explicitly allowed OR the lang Value be "-1" (all languages)
if ($langValue != -1 && !$this->check('allowed_languages', $langValue)) {
if ($langValue != -1 && !$this->check('allowed_languages', (string)$langValue)) {
return false;
}
}
Expand Down Expand Up @@ -802,7 +802,7 @@ public function checkFullLanguagesAccess($table, $record)
* The function takes an ID (int) or row (array) as second argument.
*
* @param string $table Table name
* @param mixed $idOrRow If integer, then this is the ID of the record. If Array this just represents fields in the record.
* @param int|array $idOrRow If integer, then this is the ID of the record. If Array this just represents fields in the record.
* @param bool $newRecord Set, if testing a new (non-existing) record array. Will disable certain checks that doesn't make much sense in that context.
* @param bool $deletedRecord Set, if testing a deleted record array.
* @param bool $checkFullLanguageAccess Set, whenever access to all translations of the record is required
Expand Down Expand Up @@ -1297,7 +1297,7 @@ public function initializeWebmountsForElementBrowser()
{
$alternativeWebmountPoint = (int)$this->getSessionData('pageTree_temporaryMountPoint');
if ($alternativeWebmountPoint) {
$alternativeWebmountPoint = GeneralUtility::intExplode(',', $alternativeWebmountPoint);
$alternativeWebmountPoint = GeneralUtility::intExplode(',', (string)$alternativeWebmountPoint);
$this->setWebmounts($alternativeWebmountPoint);
return;
}
Expand Down
6 changes: 5 additions & 1 deletion typo3/sysext/core/Classes/Authentication/IpLocker.php
Expand Up @@ -79,6 +79,9 @@ protected function getIpLockPart(string $ipAddress, int $numberOfParts, int $max

$numberOfParts = MathUtility::forceIntegerInRange($numberOfParts, 1, $maxParts);
$ipParts = explode($delimiter, $ipAddress);
if ($ipParts === false) {
return $ipAddress;
}
for ($a = $maxParts; $a > $numberOfParts; $a--) {
$ipPartValue = $delimiter === '.' ? '0' : str_pad('', strlen($ipParts[$a - 1]), '0');
$ipParts[$a - 1] = $ipPartValue;
Expand All @@ -103,7 +106,8 @@ protected function getIpLockPartForIpv6Address(string $ipAddress): string
}

// inet_pton also takes care of IPv4-mapped addresses (see https://en.wikipedia.org/wiki/IPv6_address#Representation)
$expandedAddress = rtrim(chunk_split(unpack('H*hex', inet_pton($ipAddress))['hex'], 4, ':'), ':');
$unpacked = unpack('H*hex', (string)inet_pton($ipAddress)) ?: [];
$expandedAddress = rtrim(chunk_split($unpacked['hex'] ?? '', 4, ':'), ':');
return $this->getIpLockPart($expandedAddress, $this->lockIPv6PartCount, 8, ':');
}

Expand Down

0 comments on commit b5cf1fa

Please sign in to comment.