Skip to content

Commit 915a8b2

Browse files
alexanderschnitzlermschwemer
authored andcommitted
[BUGFIX] Avoid method calls on null with use of null safe operators
`FrontendUtility::getCurrentPageIdentifier()` and `FrontendUtility::getSysLanguageUid()` received a guard clause a while ago to prevent calling `getAttribute()` on a null request. While this solves issues with a nullable request, there are still potential issues with calling a method on a null return value of `getAttribute()` The use of null-safe operators resolve this issue and make the guard clauses superfluous. Fixes: #1358
1 parent af4c06d commit 915a8b2

1 file changed

Lines changed: 2 additions & 8 deletions

File tree

Classes/Utility/FrontendUtility.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,21 +37,15 @@ public static function getStoragePage(int $pid = 0): int
3737
*/
3838
public static function getCurrentPageIdentifier(): int
3939
{
40-
if (self::getRequest() !== null) {
41-
return self::getRequest()->getAttribute('frontend.page.information')->getId() ?? 0;
42-
}
43-
return 0;
40+
return self::getRequest()?->getAttribute('frontend.page.information')?->getId() ?? 0;
4441
}
4542

4643
/**
4744
* Get configured frontend language
4845
*/
4946
public static function getSysLanguageUid(): int
5047
{
51-
if (self::getRequest() !== null) {
52-
return self::getRequest()->getAttribute('language')->getLanguageId();
53-
}
54-
return 0;
48+
return self::getRequest()?->getAttribute('language')?->getLanguageId() ?? 0;
5549
}
5650

5751
public static function getPluginName(): string

0 commit comments

Comments
 (0)