Fix PHPStan issues

This commit is contained in:
Daniel Siepmann 2021-12-13 09:09:13 +01:00
parent b430993655
commit 0d0c64f419
13 changed files with 94 additions and 161 deletions

View file

@ -111,6 +111,9 @@ class DateController extends AbstractController
public function searchAction(): void
{
$arguments = GeneralUtility::_GET('tx_events_datelist') ?? [];
if (is_array($arguments) === false) {
$arguments = [];
}
if (isset($arguments['events_search'])) {
$arguments += $arguments['events_search'];
unset($arguments['events_search']);
@ -144,7 +147,7 @@ class DateController extends AbstractController
protected function createDemandFromSearch(): DateDemand
{
$arguments = $this->request->getArguments() ?? [];
$arguments = $this->request->getArguments();
if (isset($arguments['events_search'])) {
$arguments += $arguments['events_search'];
unset($arguments['events_search']);

View file

@ -48,7 +48,11 @@ class DateRepository extends Repository
$categories = $demand->getCategories();
if ($categories) {
$categoryConstraints = $this->createCategoryConstraint($query, $categories, $demand->getIncludeSubCategories());
$categoryConstraints = $this->createCategoryConstraint(
$query,
$categories,
$demand->getIncludeSubCategories()
);
if ($demand->getCategoryCombination() === 'or') {
$constraints['categories'] = $query->logicalOr($categoryConstraints);
} else {
@ -96,6 +100,12 @@ class DateRepository extends Repository
'full',
new \DateTimeImmutable()
);
if (!$now instanceof \DateTimeImmutable) {
throw new \UnexpectedValueException(
'Could not retrieve now as DateTimeImmutable, got "' . gettype($now) . '".',
1639382648
);
}
$now = $now->modify('midnight');
$constraints['nowAndFuture'] = $query->logicalOr([
$query->greaterThanOrEqual('start', $now),
@ -148,8 +158,11 @@ class DateRepository extends Repository
return $query->logicalOr($constraints);
}
protected function createCategoryConstraint(QueryInterface $query, string $categories, bool $includeSubCategories = false): array
{
protected function createCategoryConstraint(
QueryInterface $query,
string $categories,
bool $includeSubCategories = false
): array {
$constraints = [];
if ($includeSubCategories) {
@ -178,7 +191,10 @@ class DateRepository extends Repository
'tx_events_domain_model_date',
'tx_events_domain_model_event',
'event',
$queryBuilder->expr()->eq('tx_events_domain_model_date.event', $queryBuilder->quoteIdentifier('event.uid'))
$queryBuilder->expr()->eq(
'tx_events_domain_model_date.event',
$queryBuilder->quoteIdentifier('event.uid')
)
)->where(
$queryBuilder->expr()->like('event.title', $queryBuilder->createNamedParameter('%' . $search . '%'))
)->orderBy('tx_events_domain_model_date.start');

View file

@ -106,6 +106,9 @@ class EventRepository extends Repository
return $result;
}
/**
* @return ConstraintInterface[]
*/
private function getConstraints(QueryInterface $query, EventDemand $demand): array
{
$constraints = [];

View file

@ -66,7 +66,13 @@ class AddSpecialProperties
) {
/** @var Date $date */
$date = $event->getObject();
$date->_setProperty('originalDate', $this->getOriginalDate($date->_getProperty('_localizedUid')));
$localizedUid = $date->_getProperty('_localizedUid');
if (is_numeric($localizedUid) === false) {
return;
}
$date->_setProperty('originalDate', $this->getOriginalDate((int) $localizedUid));
}
}

View file

@ -31,12 +31,12 @@ class CategoryService
* @param int $counter
* @return string comma separated list of category ids
*/
public function getChildrenCategories($idList, int $counter = 0)
public function getChildrenCategories($idList, int $counter = 0): string
{
$cacheIdentifier = sha1('children' . $idList);
$entry = $this->cache->get($cacheIdentifier);
if (!$entry) {
if (!$entry || is_string($entry) === false) {
$entry = $this->getChildrenCategoriesRecursive($idList, $counter);
$this->cache->set($cacheIdentifier, $entry);
}
@ -68,9 +68,10 @@ class CategoryService
$res = $queryBuilder
->select('uid')
->from('sys_category')
->where(
$queryBuilder->expr()->in('parent', $queryBuilder->createNamedParameter(explode(',', $idList), Connection::PARAM_INT_ARRAY))
)
->where($queryBuilder->expr()->in(
'parent',
$queryBuilder->createNamedParameter(explode(',', $idList), Connection::PARAM_INT_ARRAY)
))
->execute();
while ($row = $res->fetch()) {
@ -101,9 +102,10 @@ class CategoryService
$rows = $queryBuilder
->select('uid')
->from('sys_category')
->where(
$queryBuilder->expr()->in('uid', $queryBuilder->createNamedParameter(explode(',', $idList), Connection::PARAM_INT_ARRAY))
)
->where($queryBuilder->expr()->in(
'uid',
$queryBuilder->createNamedParameter(explode(',', $idList), Connection::PARAM_INT_ARRAY)
))
->execute()
->fetchAll();
foreach ($rows as $row) {

View file

@ -75,14 +75,14 @@ class Database
public function getPastDates(): array
{
$queryBuilder = $this->connectionPool
->getConnectionForTable(static::DATE_TABLE)
->getConnectionForTable(self::DATE_TABLE)
->createQueryBuilder();
$queryBuilder->getRestrictions()->removeAll();
$midnightToday = new \DateTimeImmutable('midnight today');
$records = $queryBuilder->select('uid')
->from(static::DATE_TABLE)
->from(self::DATE_TABLE)
->where($queryBuilder->expr()->lte(
'end',
$queryBuilder->createNamedParameter($midnightToday->format('Y-m-d H:i:s'))
@ -98,9 +98,9 @@ class Database
public function deleteDates(int ...$uids): void
{
$queryBuilder = $this->connectionPool
->getQueryBuilderForTable(static::DATE_TABLE);
->getQueryBuilderForTable(self::DATE_TABLE);
$queryBuilder->delete(static::DATE_TABLE)
$queryBuilder->delete(self::DATE_TABLE)
->where('uid in (:uids)')
->setParameter(':uids', $uids, Connection::PARAM_INT_ARRAY)
->execute();
@ -109,21 +109,21 @@ class Database
public function deleteEventsWithoutDates(): void
{
$queryBuilder = $this->connectionPool
->getConnectionForTable(static::EVENT_TABLE)
->getConnectionForTable(self::EVENT_TABLE)
->createQueryBuilder();
$queryBuilder->getRestrictions()->removeAll();
$recordUids = $queryBuilder->select('event.uid')
->from(static::EVENT_TABLE, 'event')
->leftJoin('event', static::DATE_TABLE, 'date', $queryBuilder->expr()->eq('date.event', 'event.uid'))
->from(self::EVENT_TABLE, 'event')
->leftJoin('event', self::DATE_TABLE, 'date', $queryBuilder->expr()->eq('date.event', 'event.uid'))
->where($queryBuilder->expr()->isNull('date.uid'))
->execute()
->fetchAll(\PDO::FETCH_COLUMN);
$dataStructure = [static::EVENT_TABLE => []];
$dataStructure = [self::EVENT_TABLE => []];
foreach ($recordUids as $recordUid) {
$dataStructure[static::EVENT_TABLE][$recordUid] = ['delete' => 1];
$dataStructure[self::EVENT_TABLE][$recordUid] = ['delete' => 1];
}
$dataHandler = clone $this->dataHandler;

View file

@ -24,7 +24,6 @@ namespace Wrm\Events\Service\Cleanup;
use TYPO3\CMS\Core\Database\Connection;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\Query\QueryBuilder;
use TYPO3\CMS\Core\Resource\ResourceStorage;
use TYPO3\CMS\Core\Resource\StorageRepository;
class Files
@ -47,12 +46,12 @@ class Files
$this->storageRepository = $storageRepository;
}
public function deleteAll()
public function deleteAll(): void
{
$this->delete($this->getFilesFromDb());
}
public function deleteDangling()
public function deleteDangling(): void
{
$this->delete($this->getFilesFromDb(function (QueryBuilder $queryBuilder) {
$queryBuilder->leftJoin(
@ -107,7 +106,7 @@ class Files
{
$storage = $this->storageRepository->findByUid($storageUid);
if ($storage->hasFile($filePath) === false) {
if ($storage === null || $storage->hasFile($filePath) === false) {
return;
}

View file

@ -168,6 +168,10 @@ class DataProcessingForModels implements SingletonInterface
}
$configuration = ArrayUtility::getValueByPath($settings, 'dataProcessing.' . $className, '.');
if (is_array($configuration) === false) {
return [];
}
$configuration = $this->typoScriptService->convertPlainArrayToTypoScriptArray($configuration);
return [
'dataProcessing.' => $configuration,

View file

@ -1,7 +1,5 @@
<?php
defined('TYPO3') or die();
(function (string $extKey, string $table) {
\TYPO3\CMS\Core\Utility\ArrayUtility::mergeRecursiveWithOverrule($GLOBALS['TCA'][$table], [
'columns' => [

View file

@ -1,71 +1,55 @@
<?php
defined('TYPO3') or die();
call_user_func(function () {
(function (string $extKey, string $table) {
/* Search Plugin */
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerPlugin(
'Events',
'DateSearch',
'Events: Date Search',
'EXT:events/Resources/Public/Icons/Extension.svg'
);
$GLOBALS['TCA']['tt_content']['types']['list']['subtypes_addlist']['events_datesearch'] = 'pi_flexform';
$GLOBALS['TCA'][$table]['types']['list']['subtypes_addlist']['events_datesearch'] = 'pi_flexform';
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addPiFlexFormValue(
'events_datesearch',
'FILE:EXT:events/Configuration/FlexForms/DateSearch.xml'
);
/* Date List Plugin */
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerPlugin(
'Events',
'DateList',
'Events: Date List',
'EXT:events/Resources/Public/Icons/Extension.svg'
);
$GLOBALS['TCA']['tt_content']['types']['list']['subtypes_addlist']['events_datelist'] = 'pi_flexform';
$GLOBALS['TCA'][$table]['types']['list']['subtypes_addlist']['events_datelist'] = 'pi_flexform';
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addPiFlexFormValue(
'events_datelist',
'FILE:EXT:events/Configuration/FlexForms/DateList.xml'
);
/* Date Show Plugin */
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerPlugin(
'Events',
'DateShow',
'Events: Date Show',
'EXT:events/Resources/Public/Icons/Extension.svg'
);
$GLOBALS['TCA']['tt_content']['types']['list']['subtypes_addlist']['events_dateshow'] = 'pi_flexform';
$GLOBALS['TCA'][$table]['types']['list']['subtypes_addlist']['events_dateshow'] = 'pi_flexform';
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addPiFlexFormValue(
'events_dateshow',
'FILE:EXT:events/Configuration/FlexForms/DateShow.xml'
);
/* Event Selected Plugin */
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerPlugin(
'Events',
'Selected',
'Events: Show selected',
'EXT:events/Resources/Public/Icons/Extension.svg'
);
$GLOBALS['TCA']['tt_content']['types']['list']['subtypes_addlist']['events_selected'] = 'pi_flexform';
$GLOBALS['TCA'][$table]['types']['list']['subtypes_addlist']['events_selected'] = 'pi_flexform';
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addPiFlexFormValue(
'events_selected',
'FILE:EXT:events/Configuration/FlexForms/Selected.xml'
);
});
})('events', 'tt_content');

View file

@ -1,16 +1,16 @@
<?php
defined('TYPO3') or die();
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::makeCategorizable(
'events',
'tx_events_domain_model_event',
'categories',
[
'label' => 'Categories',
'fieldConfiguration' => [
'minitems' => 0,
'multiple' => true,
(function (string $extKey, string $table) {
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::makeCategorizable(
$extKey,
$table,
'categories',
[
'label' => 'Categories',
'fieldConfiguration' => [
'minitems' => 0,
'multiple' => true,
]
]
]
);
);
})('events', 'tx_events_domain_model_event');

View file

@ -1,7 +1,5 @@
<?php
defined('TYPO3_MODE') or die();
$l10nPathGeneral = 'LLL:EXT:core/Resources/Private/Language/locallang_general.xlf';
$l10nPathLang = 'LLL:EXT:lang/locallang_core.xlf';
$l10nPathFE = 'LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf';

View file

@ -1,45 +1,5 @@
parameters:
ignoreErrors:
-
message: "#^Cannot access offset 'considerDate' on mixed\\.$#"
count: 1
path: Classes/Controller/DateController.php
-
message: "#^Cannot access offset 'end' on mixed\\.$#"
count: 1
path: Classes/Controller/DateController.php
-
message: "#^Cannot access offset 'events_search' on mixed\\.$#"
count: 2
path: Classes/Controller/DateController.php
-
message: "#^Cannot access offset 'region' on mixed\\.$#"
count: 1
path: Classes/Controller/DateController.php
-
message: "#^Cannot access offset 'searchword' on mixed\\.$#"
count: 1
path: Classes/Controller/DateController.php
-
message: "#^Cannot access offset 'start' on mixed\\.$#"
count: 1
path: Classes/Controller/DateController.php
-
message: "#^Expression on left side of \\?\\? is not nullable\\.$#"
count: 1
path: Classes/Controller/DateController.php
-
message: "#^Parameter \\#1 \\$submittedValues of static method Wrm\\\\Events\\\\Domain\\\\Model\\\\Dto\\\\DateDemand\\:\\:createFromRequestValues\\(\\) expects array, mixed given\\.$#"
count: 1
path: Classes/Controller/DateController.php
-
message: "#^Cannot call method fetchAll\\(\\) on Doctrine\\\\DBAL\\\\Driver\\\\ResultStatement\\|int\\.$#"
count: 1
@ -60,11 +20,6 @@ parameters:
count: 1
path: Classes/Extbase/AddSpecialProperties.php
-
message: "#^Parameter \\#1 \\$uidOfReferencedDate of method Wrm\\\\Events\\\\Extbase\\\\AddSpecialProperties\\:\\:getOriginalDate\\(\\) expects int, mixed given\\.$#"
count: 1
path: Classes/Extbase/AddSpecialProperties.php
-
message: "#^Cannot access offset 'uid' on mixed\\.$#"
count: 3
@ -80,11 +35,6 @@ parameters:
count: 1
path: Classes/Service/CategoryService.php
-
message: "#^Method Wrm\\\\Events\\\\Service\\\\CategoryService\\:\\:getChildrenCategories\\(\\) should return string but returns mixed\\.$#"
count: 1
path: Classes/Service/CategoryService.php
-
message: "#^Parameter \\#1 \\$idList of method Wrm\\\\Events\\\\Service\\\\CategoryService\\:\\:getChildrenCategoriesRecursive\\(\\) expects string, mixed given\\.$#"
count: 1
@ -100,16 +50,6 @@ parameters:
count: 1
path: Classes/Service/Cleanup/Database.php
-
message: "#^Unsafe access to private constant Wrm\\\\Events\\\\Service\\\\Cleanup\\\\Database\\:\\:DATE_TABLE through static\\:\\:\\.$#"
count: 5
path: Classes/Service/Cleanup/Database.php
-
message: "#^Unsafe access to private constant Wrm\\\\Events\\\\Service\\\\Cleanup\\\\Database\\:\\:EVENT_TABLE through static\\:\\:\\.$#"
count: 4
path: Classes/Service/Cleanup/Database.php
-
message: "#^Call to method deleteFile\\(\\) on an unknown class TYPO3\\\\CMS\\\\Core\\\\Resource\\\\Storage\\.$#"
count: 1
@ -130,21 +70,6 @@ parameters:
count: 1
path: Classes/Service/Cleanup/Files.php
-
message: "#^Method Wrm\\\\Events\\\\Service\\\\Cleanup\\\\Files\\:\\:deleteAll\\(\\) has no return type specified\\.$#"
count: 1
path: Classes/Service/Cleanup/Files.php
-
message: "#^Method Wrm\\\\Events\\\\Service\\\\Cleanup\\\\Files\\:\\:deleteDangling\\(\\) has no return type specified\\.$#"
count: 1
path: Classes/Service/Cleanup/Files.php
-
message: "#^Parameter \\#1 \\$plainArray of method TYPO3\\\\CMS\\\\Core\\\\TypoScript\\\\TypoScriptService\\:\\:convertPlainArrayToTypoScriptArray\\(\\) expects array, mixed given\\.$#"
count: 1
path: Classes/Service/DataProcessingForModels.php
-
message: "#^Access to an undefined property Wrm\\\\Events\\\\Service\\\\DestinationDataImportService\\:\\:\\$sysCategoriesPid\\.$#"
count: 2
@ -330,6 +255,21 @@ parameters:
count: 2
path: Classes/Service/DestinationDataImportService.php
-
message: "#^Parameter \\#1 \\$value of function count expects array\\|Countable, mixed given\\.$#"
count: 1
path: Classes/Service/DestinationDataImportService.php
-
message: "#^Parameter \\#2 \\$baseTimestamp of function strtotime expects int\\|null, int\\|false given\\.$#"
count: 1
path: Classes/Service/DestinationDataImportService.php
-
message: "#^Parameter \\#2 \\$minute of method DateTime\\:\\:setTime\\(\\) expects int, string given\\.$#"
count: 4
path: Classes/Service/DestinationDataImportService.php
-
message: "#^Parameter \\#1 \\$var of function count expects array\\|Countable, mixed given\\.$#"
count: 1
@ -425,23 +365,3 @@ parameters:
count: 1
path: Classes/Service/DestinationDataImportService.php
-
message: "#^Right side of \\|\\| is always false\\.$#"
count: 1
path: Configuration/TCA/Overrides/sys_category.php
-
message: "#^Right side of \\|\\| is always false\\.$#"
count: 1
path: Configuration/TCA/Overrides/tt_content.php
-
message: "#^Right side of \\|\\| is always false\\.$#"
count: 1
path: Configuration/TCA/Overrides/tx_events_domain_model_event.php
-
message: "#^Right side of \\|\\| is always false\\.$#"
count: 1
path: Configuration/TCA/tx_events_domain_model_event.php