Skip to content

Commit

Permalink
[TASK] Implement type strictness
Browse files Browse the repository at this point in the history
  • Loading branch information
NamelessCoder committed Jan 13, 2023
1 parent 4d3fb52 commit 4af29f6
Show file tree
Hide file tree
Showing 210 changed files with 816 additions and 2,978 deletions.
380 changes: 75 additions & 305 deletions Classes/Asset.php

Large diffs are not rendered by default.

211 changes: 51 additions & 160 deletions Classes/Service/AssetService.php

Large diffs are not rendered by default.

109 changes: 24 additions & 85 deletions Classes/Service/PageService.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,22 +60,13 @@ public function readPageRepositoryConstant(string $constantName)
return constant($class . '::' . $constantName);
}

/**
* @param integer $pageUid
* @param array $excludePages
* @param boolean $includeNotInMenu
* @param boolean $includeMenuSeparator
* @param boolean $disableGroupAccessCheck
*
* @return array
*/
public function getMenu(
$pageUid,
int $pageUid,
array $excludePages = [],
$includeNotInMenu = false,
$includeMenuSeparator = false,
$disableGroupAccessCheck = false
) {
bool $includeNotInMenu = false,
bool $includeMenuSeparator = false,
bool $disableGroupAccessCheck = false
): array {
$pageRepository = $this->getPageRepository();
$pageConstraints = $this->getPageConstraints($excludePages, $includeNotInMenu, $includeMenuSeparator);
$cacheKey = md5($pageUid . $pageConstraints . (integer) $disableGroupAccessCheck);
Expand All @@ -95,12 +86,7 @@ function ($page) {
return static::$cachedMenus[$cacheKey];
}

/**
* @param integer $pageUid
* @param boolean $disableGroupAccessCheck
* @return array
*/
public function getPage($pageUid, $disableGroupAccessCheck = false)
public function getPage(int $pageUid, bool $disableGroupAccessCheck = false): array
{
$cacheKey = md5($pageUid . (integer) $disableGroupAccessCheck);
if (false === isset(static::$cachedPages[$cacheKey])) {
Expand All @@ -110,14 +96,11 @@ public function getPage($pageUid, $disableGroupAccessCheck = false)
return static::$cachedPages[$cacheKey];
}

/**
* @param integer $pageUid
* @param boolean $reverse
* @param boolean $disableGroupAccessCheck
* @return array
*/
public function getRootLine($pageUid = null, $reverse = false, $disableGroupAccessCheck = false)
{
public function getRootLine(
?int $pageUid = null,
bool $reverse = false,
bool $disableGroupAccessCheck = false
): array {
if (null === $pageUid) {
$pageUid = $GLOBALS['TSFE']->id;
}
Expand All @@ -143,18 +126,11 @@ public function getRootLine($pageUid = null, $reverse = false, $disableGroupAcce
return static::$cachedRootlines[$cacheKey];
}

/**
* @param array $excludePages
* @param boolean $includeNotInMenu
* @param boolean $includeMenuSeparator
*
* @return string
*/
protected function getPageConstraints(
array $excludePages = [],
$includeNotInMenu = false,
$includeMenuSeparator = false
) {
bool $includeNotInMenu = false,
bool $includeMenuSeparator = false
): string {
$constraints = [];

$constraints[] = 'doktype NOT IN ('
Expand All @@ -181,12 +157,9 @@ protected function getPageConstraints(
}

/**
* @param array|integer $page
* @param integer $languageUid
* @param boolean $normalWhenNoLanguage
* @return boolean
* @param array|integer|null $page
*/
public function hidePageForLanguageUid($page = null, $languageUid = -1, $normalWhenNoLanguage = true)
public function hidePageForLanguageUid($page = null, int $languageUid = -1, bool $normalWhenNoLanguage = true): bool
{
if (is_array($page)) {
$pageUid = $page['uid'];
Expand Down Expand Up @@ -258,13 +231,7 @@ class_exists(\TYPO3\CMS\Core\Domain\Repository\PageRepository::class)
return $instance;
}

/**
* @param array $page
* @param boolean $forceAbsoluteUrl
*
* @return string
*/
public function getItemLink(array $page, $forceAbsoluteUrl = false)
public function getItemLink(array $page, bool $forceAbsoluteUrl = false): string
{
if ((integer) $page['doktype'] === $this->readPageRepositoryConstant('DOKTYPE_LINK')) {
$parameter = $this->getPageRepository()->getExtURL($page);
Expand All @@ -284,20 +251,12 @@ public function getItemLink(array $page, $forceAbsoluteUrl = false)
return $GLOBALS['TSFE']->cObj->typoLink('', $config);
}

/**
* @param array $page
* @return boolean
*/
public function isAccessProtected(array $page)
public function isAccessProtected(array $page): bool
{
return (0 !== (integer) $page['fe_group']);
}

/**
* @param array $page
* @return boolean
*/
public function isAccessGranted(array $page)
public function isAccessGranted(array $page): bool
{
if (!$this->isAccessProtected($page)) {
return true;
Expand All @@ -321,21 +280,12 @@ public function isAccessGranted(array $page)
return false;
}

/**
* @param integer $pageUid
* @return boolean
*/
public function isCurrent($pageUid)
public function isCurrent(int $pageUid): bool
{
return ((integer) $pageUid === (integer) $GLOBALS['TSFE']->id);
}

/**
* @param integer $pageUid
* @param boolean $showAccessProtected
* @return boolean
*/
public function isActive($pageUid, $showAccessProtected = false)
public function isActive(int $pageUid, bool $showAccessProtected = false): bool
{
$rootLineData = $this->getRootLine(null, false, $showAccessProtected);
foreach ($rootLineData as $page) {
Expand All @@ -347,11 +297,7 @@ public function isActive($pageUid, $showAccessProtected = false)
return false;
}

/**
* @param array $arguments
* @return boolean
*/
public function shouldUseShortcutTarget(array $arguments)
public function shouldUseShortcutTarget(array $arguments): bool
{
$useShortcutTarget = (boolean) $arguments['useShortcutData'];
if ($arguments['useShortcutTarget'] !== null) {
Expand All @@ -361,11 +307,7 @@ public function shouldUseShortcutTarget(array $arguments)
return $useShortcutTarget;
}

/**
* @param array $arguments
* @return boolean
*/
public function shouldUseShortcutUid(array $arguments)
public function shouldUseShortcutUid(array $arguments): bool
{
$useShortcutUid = (boolean) $arguments['useShortcutData'];
if ($arguments['useShortcutUid'] !== null) {
Expand All @@ -379,11 +321,8 @@ public function shouldUseShortcutUid(array $arguments)
* Determines the target page record for the provided page record
* if it is configured as a shortcut in any of the possible modes.
* Returns NULL otherwise.
*
* @param array $page
* @return NULL|array
*/
public function getShortcutTargetPage(array $page)
public function getShortcutTargetPage(array $page): ?array
{
if ((integer) $page['doktype'] !== $this->readPageRepositoryConstant('DOKTYPE_SHORTCUT')) {
return null;
Expand Down
41 changes: 8 additions & 33 deletions Classes/Traits/ArrayConsumingViewHelperTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use TYPO3\CMS\Core\Utility\ArrayUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Persistence\QueryResultInterface;
use TYPO3Fluid\Fluid\Core\ViewHelper\Exception;

/**
* Class ArrayConsumingViewHelperTrait
Expand All @@ -28,15 +27,14 @@
*/
trait ArrayConsumingViewHelperTrait
{

/**
* Override of VhsViewHelperTrait equivalent. Does what
* that function does, but also ensures an array return.
*
* @param string $argumentName
* @return mixed
*/
protected function getArgumentFromArgumentsOrTagContentAndConvertToArray($argumentName)
protected function getArgumentFromArgumentsOrTagContentAndConvertToArray(string $argumentName)
{
return static::getArgumentFromArgumentsOrTagContentAndConvertToArrayStatic(
$this->arguments,
Expand All @@ -49,15 +47,11 @@ protected function getArgumentFromArgumentsOrTagContentAndConvertToArray($argume
* Override of VhsViewHelperTrait equivalent. Does what
* that function does, but also ensures an array return.
*
* @param array $arguments
* @param string $argumentName
* @param \Closure $renderChildrenClosure
*
* @return mixed
*/
protected static function getArgumentFromArgumentsOrTagContentAndConvertToArrayStatic(
array $arguments,
$argumentName,
string $argumentName,
\Closure $renderChildrenClosure
) {
if (!isset($arguments[$argumentName])) {
Expand All @@ -70,24 +64,16 @@ protected static function getArgumentFromArgumentsOrTagContentAndConvertToArrayS

/**
* @param \Traversable|string $candidate
* @param boolean $useKeys
*
* @return array
* @throws Exception
*/
protected function arrayFromArrayOrTraversableOrCSV($candidate, $useKeys = true)
protected function arrayFromArrayOrTraversableOrCSV($candidate, bool $useKeys = true): array
{
return static::arrayFromArrayOrTraversableOrCSVStatic($candidate, $useKeys);
}

/**
* @param mixed $candidate
* @param boolean $useKeys
*
* @return array
* @throws Exception
*/
protected static function arrayFromArrayOrTraversableOrCSVStatic($candidate, $useKeys = true)
protected static function arrayFromArrayOrTraversableOrCSVStatic($candidate, bool $useKeys = true): array
{
if ($candidate instanceof QueryResultInterface) {
return $candidate->toArray();
Expand All @@ -105,33 +91,22 @@ protected static function arrayFromArrayOrTraversableOrCSVStatic($candidate, $us
return [];
}

/**
* @param array $array1
* @param array $array2
* @return array
*/
protected function mergeArrays($array1, $array2)
protected function mergeArrays(array $array1, array $array2): array
{
return static::mergeArraysStatic($array1, $array2);
}

/**
* @param array $array1
* @param array $array2
* @return array
*/
protected static function mergeArraysStatic($array1, $array2)
protected static function mergeArraysStatic(array $array1, array $array2): array
{
ArrayUtility::mergeRecursiveWithOverrule($array1, $array2);
return $array1;
}

/**
* @param mixed $subject
* @return boolean
*/
protected static function assertIsArrayOrIterator($subject)
protected static function assertIsArrayOrIterator($subject): bool
{
return (boolean) (true === is_array($subject) || true === $subject instanceof \Traversable);
return is_array($subject) || $subject instanceof \Traversable;
}
}
5 changes: 1 addition & 4 deletions Classes/Traits/PageRecordViewHelperTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,11 @@
*/
trait PageRecordViewHelperTrait
{

/**
* Registers all page record related arguments required
* to handle access restrictions and shortcuts.
*
* @return void
*/
protected function registerPageRecordArguments()
protected function registerPageRecordArguments(): void
{
$this->registerArgument(
'showAccessProtected',
Expand Down
6 changes: 2 additions & 4 deletions Classes/Traits/PageRendererTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,9 @@
trait PageRendererTrait
{
/**
* Provides a shared (singleton) instance of PageRenderer
*
* @return PageRenderer
* Provides a shared (singleton) instance of PageRenderer.
*/
protected static function getPageRenderer()
protected static function getPageRenderer(): PageRenderer
{
/** @var PageRenderer $pageRenderer */
$pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
Expand Down
32 changes: 5 additions & 27 deletions Classes/Traits/SlideViewHelperTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,8 @@ trait SlideViewHelperTrait
* Default initialisation of arguments - will be used
* if the implementing ViewHelper does not itself define
* this method.
*
* @return void
*/
public function initializeArguments()
public function initializeArguments(): void
{
$this->registerSlideArguments();
}
Expand All @@ -43,11 +41,8 @@ public function initializeArguments()
* Register the "limit", "slide", "slideCollect" and "slideCollectReverse"
* arguments which are consumed by getSlideRecords.
* Should be used inside registerArguments().
*
* @return void
* @api
*/
protected function registerSlideArguments()
protected function registerSlideArguments(): void
{
$this->registerArgument('limit', 'integer', 'Optional limit to the total number of records to render');
$this->registerArgument(
Expand Down Expand Up @@ -78,33 +73,16 @@ protected function registerSlideArguments()
);
}

/**
* @return PageService
*/
protected function getPageService()
protected function getPageService(): PageService
{
/** @var PageService $pageService */
$pageService = GeneralUtility::makeInstance(PageService::class);
return $pageService;
}

/**
* Get a number of records from a page for sliding
*
* @param integer $pageUid PID to get the records from
* @param integer $limit number of records to get at maximum
*/
abstract protected function getSlideRecordsFromPage($pageUid, $limit);
abstract protected function getSlideRecordsFromPage(int $pageUid, ?int $limit): array;

/**
* Get records, optionally sliding up the page rootline
*
* @param integer $pageUid
* @param integer $limit
* @return array
* @api
*/
protected function getSlideRecords($pageUid, $limit = null)
protected function getSlideRecords(int $pageUid, ?int $limit = null): array
{
if (null === $limit && false === empty($this->arguments['limit'])) {
$limit = (integer) $this->arguments['limit'];
Expand Down

0 comments on commit 4af29f6

Please sign in to comment.