Skip to content

Commit

Permalink
[TASK] Correct return types, properties and parameters
Browse files Browse the repository at this point in the history
Resolve PHPStan reported issues till level 5 as preperation for future upgrades
  • Loading branch information
Riiiad committed Oct 7, 2024
1 parent 911b57e commit 95558ac
Show file tree
Hide file tree
Showing 20 changed files with 81 additions and 54 deletions.
6 changes: 3 additions & 3 deletions Classes/Controller/PollController.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class PollController extends ActionController

protected PersistenceManagerInterface $persistenceManager;

public function injectPersistenceManager(PersistenceManagerInterface $persistenceManager)
public function injectPersistenceManager(PersistenceManagerInterface $persistenceManager): void
{
$this->persistenceManager = $persistenceManager;
}
Expand Down Expand Up @@ -616,7 +616,7 @@ public function createAction(
BasePoll $poll,
bool $publishDirectly,
bool $acceptTerms = false
) {
): void {
if ($poll->isSimplePoll()) {
$this->pollPermission->isAllowed($poll, 'newSimplePoll', true);
} else {
Expand Down Expand Up @@ -650,7 +650,7 @@ public function createAction(
AbstractMessage::OK
);
if ($publishDirectly) {
return (new ForwardResponse('publish'))
(new ForwardResponse('publish'))
->withControllerName('Poll')
->withExtensionName('t3oodle')
->withArguments(['poll' => $poll]);
Expand Down
8 changes: 5 additions & 3 deletions Classes/Domain/Model/BasePoll.php
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ public function removeOption(Option $optionToRemove): void
*
* @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage $options
*/
public function getOptions($skipMarkedToDeleted = false): \TYPO3\CMS\Extbase\Persistence\ObjectStorage
public function getOptions(bool $skipMarkedToDeleted = false): \TYPO3\CMS\Extbase\Persistence\ObjectStorage
{
if ($skipMarkedToDeleted) {
/** @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage $options */
Expand Down Expand Up @@ -482,7 +482,7 @@ public function removeVote(Vote $voteToRemove): void
}

/**
* @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage|Vote[]
* @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\FGTCLB\T3oodle\Domain\Model\Vote>
*/
public function getVotes(): \TYPO3\CMS\Extbase\Persistence\ObjectStorage
{
Expand Down Expand Up @@ -625,7 +625,9 @@ public function areOptionsModified(): bool

return false;
}

/**
* @return \FGTCLB\T3oodle\Domain\Model\Option[]
*/
public function getAvailableOptions(): array
{
if (!$this->getSettingMaxVotesPerOption()) {
Expand Down
27 changes: 21 additions & 6 deletions Classes/Domain/Repository/PollRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use FGTCLB\T3oodle\Service\UserService;
use FGTCLB\T3oodle\Utility\UserIdentUtility;
use Psr\EventDispatcher\EventDispatcherInterface;
use TYPO3\CMS\Core\Database\Connection;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Object\ObjectManagerInterface;
Expand All @@ -26,8 +27,9 @@ class PollRepository extends \TYPO3\CMS\Extbase\Persistence\Repository
protected $eventDispatcher;

private UserService $userService;

/**
* @var string[] Show unpublished first, then order by publishDate
* @var array<non-empty-string, 'ASC'|'DESC'> Show unpublished first, then order by publishDate
*/
protected $defaultOrderings = [
'isPublished' => 'ASC',
Expand Down Expand Up @@ -83,7 +85,7 @@ public function findPolls(
$andConstraints[] = $query->equals('isPublished', true);
}

if (!empty($orConstraints)) {
if ($orConstraints !== []) {
$andConstraints[] = $query->logicalOr($orConstraints);
}

Expand All @@ -108,13 +110,26 @@ public function getPollTypeByUid(int $poll): string
{
/** @var ConnectionPool $pool */
$pool = GeneralUtility::makeInstance(ConnectionPool::class);
$result = $pool->getQueryBuilderForTable('tx_t3oodle_domain_model_poll')
$queryBuilder = $pool->getQueryBuilderForTable('tx_t3oodle_domain_model_poll');
$result = $queryBuilder
->select('type')
->from('tx_t3oodle_domain_model_poll')
->where('uid = ' . $poll)
->execute()
->fetch();
->where($queryBuilder->expr()->eq(
'uid',
$queryBuilder->createNamedParameter($poll, Connection::PARAM_INT)
))
->executeQuery()
->fetchAssociative();

return $result['type'];
}

public function countBySlug(string $slug): int
{
$query = $this->createQuery();
return $query
->matching($query->equals('slug', $slug))
->execute()
->count();
}
}
2 changes: 1 addition & 1 deletion Classes/Event/EditSuggestionEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ final class EditSuggestionEvent
private array $settings;
private PollController $caller;

public function __construct(Option $option, SuggestionDto $suggestionDto, array $settings, ViewInterface $view, PollController $caller)
public function __construct(Option $option, SuggestionDto $suggestionDto, array $settings, $view, PollController $caller)
{
$this->option = $option;
$this->suggestionDto = $suggestionDto;
Expand Down
2 changes: 1 addition & 1 deletion Classes/Event/NewPollEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ final class NewPollEvent
private ViewInterface $view;
private PollController $caller;

public function __construct(Poll $poll, bool $publishDirectly, array $newOptions, array $settings, ViewInterface $view, PollController $caller)
public function __construct(Poll $poll, bool $publishDirectly, array $newOptions, array $settings, $view, PollController $caller)
{
$this->poll = $poll;
$this->publishDirectly = $publishDirectly;
Expand Down
2 changes: 1 addition & 1 deletion Classes/Event/NewSuggestionEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ final class NewSuggestionEvent
private PollController $caller;
private SuggestionDto $suggestionDto;

public function __construct(Poll $poll, SuggestionDto $suggestionDto, array $settings, ViewInterface $view, PollController $caller)
public function __construct(Poll $poll, SuggestionDto $suggestionDto, array $settings, $view, PollController $caller)
{
$this->poll = $poll;
$this->suggestionDto = $suggestionDto;
Expand Down
4 changes: 2 additions & 2 deletions Classes/Event/Permission/PermissionCheckEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ final class PermissionCheckEvent
private ?array $arguments = [];
private mixed $caller;

public function __construct(bool $currentStatus, ?array $arguments, $caller)
public function __construct(bool $currentStatus, ?array $arguments, mixed $caller)
{
$this->currentStatus = $currentStatus;
$this->arguments = $arguments;
Expand All @@ -22,7 +22,7 @@ public function getCurrentStatus(): bool
return $this->currentStatus;
}

public function setCurrentStatus($status): void
public function setCurrentStatus(bool $status = null): void
{
$status ?? $this->currentStatus;
}
Expand Down
8 changes: 4 additions & 4 deletions Classes/Event/PollRepository/FindPollsEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

final class FindPollsEvent
{
private $constraints;
private $query;
private $caller;
private array $constraints;
private QueryInterface $query;
private PollRepository $caller;

public function __construct(
array $constraints,
Expand All @@ -32,7 +32,7 @@ public function getQuery(): QueryInterface
{
return $this->query;
}
public function setConstraints($constraints): void
public function setConstraints(array $constraints): void
{
$this->constraints = $constraints;
}
Expand Down
2 changes: 1 addition & 1 deletion Classes/Event/ShowPollEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function getView(): ViewInterface
return $this->view;
}

public function getCaller()
public function getCaller(): PollController
{
return $this->caller;
}
Expand Down
5 changes: 5 additions & 0 deletions Classes/Event/VotePollEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,9 @@ public function getCaller(): PollController
{
return $this->caller;
}

public function getSettings(): array
{
return $this->settings;
}
}
5 changes: 4 additions & 1 deletion Classes/EventListener/UpdatePollSlugListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,10 @@ public function beforeUpdate(
*/
protected function updatePollSlug(BasePoll $poll): void
{
$slugUtility = GeneralUtility::makeInstance(SlugUtility::class, 'tx_t3oodle_domain_model_poll', 'slug');
$slugUtility = new SlugUtility(
'tx_t3oodle_domain_model_poll',
'slug'
);

// Create slug and update created entity
if ($poll->getVisibility() === \FGTCLB\T3oodle\Domain\Enumeration\Visibility::NOT_LISTED) {
Expand Down
10 changes: 8 additions & 2 deletions Classes/Traits/Model/DynamicUserProperties.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* | (c) 2020-2021 Armin Vieweg <[email protected]>
*/
use FGTCLB\T3oodle\Utility\SettingsUtility;
use TYPO3\CMS\Core\Database\Connection;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Domain\Model\FrontendUser;

Expand Down Expand Up @@ -69,8 +70,13 @@ private function getUserRow(int $uid): ?array
self::$userRowCache[$uid] = $queryBuilder
->select('uid', self::$typoscriptSettings['frontendUserNameField'])
->from('fe_users')
->where($queryBuilder->expr()->eq('uid', $uid))
->execute()->fetch(\PDO::FETCH_ASSOC);
->where($queryBuilder->expr()->eq(
'uid',
$queryBuilder->createNamedParameter($uid, Connection::PARAM_INT)
))
->setMaxResults(1)
->executeQuery()
->fetchAssociative();

return self::$userRowCache[$uid];
}
Expand Down
17 changes: 1 addition & 16 deletions Classes/Utility/SlugUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,10 @@

class SlugUtility
{
/**
* @var string
*/
private $tableName;

/**
* @var string
*/
private $fieldName;

/**
* @var SlugHelper
*/
private $slugHelper;
private SlugHelper $slugHelper;

public function __construct(string $tableName, string $fieldName)
{
$this->tableName = $tableName;
$this->fieldName = $fieldName;
$this->slugHelper = GeneralUtility::makeInstance(
SlugHelper::class,
$tableName,
Expand Down
3 changes: 2 additions & 1 deletion Classes/Utility/TranslateUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ final class TranslateUtility
public static function translate(string $key, array $arguments = [], string $default = ''): string
{
$translation = LocalizationUtility::translate($key, self::EXTENSION_NAME, $arguments);
if (!$translation || empty($translation)) {

if (!$translation) {
return $default;
}

Expand Down
2 changes: 1 addition & 1 deletion Classes/ViewHelpers/GetOptionValueViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class GetOptionValueViewHelper extends AbstractViewHelper
{
use CompileWithRenderStatic;

public function initializeArguments()
public function initializeArguments(): void
{
$this->registerArgument('vote', 'object', 'Vote object', false);
$this->registerArgument('option', 'object', 'Option object', true);
Expand Down
4 changes: 2 additions & 2 deletions Classes/ViewHelpers/Math/AddViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class AddViewHelper extends AbstractViewHelper
{
use CompileWithRenderStatic;

public function initializeArguments()
public function initializeArguments(): void
{
$this->registerArgument('subject', 'int', 'Subject');
$this->registerArgument('number', 'int', 'Number to add to subject', true);
Expand All @@ -27,7 +27,7 @@ public static function renderStatic(
array $arguments,
\Closure $renderChildrenClosure,
RenderingContextInterface $renderingContext
) {
): int {
$subject = $arguments['subject'] ?? $renderChildrenClosure();

return (int)$subject + (int)$arguments['number'];
Expand Down
4 changes: 2 additions & 2 deletions Classes/ViewHelpers/PermissionViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class PermissionViewHelper extends AbstractViewHelper
*/
private static $permission;

public function initializeArguments()
public function initializeArguments(): void
{
$this->registerArgument('permissionClassName', 'string', '', false, PollPermission::class);
$this->registerArgument('poll', 'object', 'Poll object', false);
Expand All @@ -55,7 +55,7 @@ public static function renderStatic(
array $arguments,
\Closure $renderChildrenClosure,
RenderingContextInterface $renderingContext
) {
): bool {
self::init($arguments, $renderingContext);

$poll = $arguments['poll'] ?? $renderChildrenClosure();
Expand Down
4 changes: 2 additions & 2 deletions Classes/ViewHelpers/Schedule/ParseDayOptionViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class ParseDayOptionViewHelper extends AbstractViewHelper
{
use CompileWithRenderStatic;

public function initializeArguments()
public function initializeArguments(): void
{
$this->registerArgument('value', 'string', 'Date with option as string', false);
}
Expand All @@ -27,7 +27,7 @@ public static function renderStatic(
array $arguments,
\Closure $renderChildrenClosure,
RenderingContextInterface $renderingContext
) {
): array {
$value = $arguments['value'] ?? (string)$renderChildrenClosure();

return ScheduleOptionUtility::parseOptionName($value);
Expand Down
4 changes: 2 additions & 2 deletions Classes/ViewHelpers/Schedule/SplitDayOptionsViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class SplitDayOptionsViewHelper extends AbstractViewHelper
{
use CompileWithRenderStatic;

public function initializeArguments()
public function initializeArguments(): void
{
$this->registerArgument('get', 'string', '"dates" or "options" allowed', true);
$this->registerArgument('options', 'array', 'Iterable with options', false);
Expand All @@ -30,7 +30,7 @@ public static function renderStatic(
array $arguments,
\Closure $renderChildrenClosure,
RenderingContextInterface $renderingContext
) {
): array {
$options = $arguments['options'] ?? $renderChildrenClosure();
if (!$options || !is_iterable($options)) {
throw new \InvalidArgumentException(
Expand Down
16 changes: 13 additions & 3 deletions Classes/ViewHelpers/SvgViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class SvgViewHelper extends AbstractViewHelper
*/
protected static $cache = [];

public function initializeArguments()
public function initializeArguments(): void
{
$this->registerArgument('path', 'string', 'SVG path, relative to Resources/Public/', true);
$this->registerArgument('size', 'string', 'SVG size in pixel', false, '');
Expand All @@ -37,12 +37,22 @@ public function initializeArguments()
$this->registerArgument('title', 'string', 'Optional title', false, '');
}

/**
* Return array element by key.
*
* @param array $arguments
* @param \Closure $renderChildrenClosure
* @param RenderingContextInterface $renderingContext
* @throws \RuntimeException
* @return string
*/
public static function renderStatic(
array $arguments,
\Closure $renderChildrenClosure,
RenderingContextInterface $renderingContext
) {
$extensionName = $renderingContext->getControllerContext()->getRequest()->getControllerExtensionName();
): string {
$request = $renderingContext->getRequest();
$extensionName = $request->getControllerExtensionName();
$uri = 'EXT:' . GeneralUtility::camelCaseToLowerCaseUnderscored($extensionName) . '/Resources/Public/' .
$arguments['path'];
$path = GeneralUtility::getFileAbsFileName($uri);
Expand Down

0 comments on commit 95558ac

Please sign in to comment.