Commit 8c1f5e5e authored by Wolf-Peter Utz's avatar Wolf-Peter Utz Committed by Felix Herrmann
Browse files

Add php 7.2 support (type hints)

parent 9ce92688
......@@ -47,29 +47,26 @@ abstract class AbstractBeController extends ActionController
/**
* Sets the current configuration
*/
public function initializeObject()
public function initializeObject(): void
{
$this->configuration = $this->configurationRepository->findCurrent();
}
public function initializeView(ViewInterface $view)
public function initializeView(ViewInterface $view): void
{
$view->assign('backendUserData', $this->backendUser->user);
$view->assign('configuration', $this->configuration);
}
/**
* @param string $messageBody
* @param string $messageTitle
* @param int $severity
* @param bool $storeInSession
* {@inheritDoc}
*/
public function addFlashMessage(
$messageBody,
$messageTitle = '',
$severity = AbstractMessage::OK,
$storeInSession = true
) {
): void {
if (null === $this->controllerContext) {
$this->controllerContext = $this->buildControllerContext();
}
......@@ -77,20 +74,14 @@ abstract class AbstractBeController extends ActionController
}
/**
* @return BackendUserAuthentication
* @SuppressWarnings(PHPMD.Superglobals)
*/
protected static function getBackendUserAuthentication()
protected static function getBackendUserAuthentication(): BackendUserAuthentication
{
return $GLOBALS['BE_USER'];
}
/**
* @param $argument
*
* @throws \TYPO3\CMS\Extbase\Mvc\Exception\NoSuchArgumentException
*/
protected function setDateTimeConverterOptions($argument, array $properties)
protected function setDateTimeConverterOptions(string $argument, array $properties): void
{
$propertyMappingConfiguration = $this->arguments->getArgument($argument)->getPropertyMappingConfiguration();
foreach ($properties as $property) {
......@@ -102,12 +93,7 @@ abstract class AbstractBeController extends ActionController
}
}
/**
* @param int $requiredUserGroup UID of the user group
*
* @return bool
*/
protected function backendUserHasUserGroup($requiredUserGroup = 0)
protected function backendUserHasUserGroup(int $requiredUserGroup = 0): bool
{
if (Configuration::AUTH_NONE === $requiredUserGroup) {
return true;
......
......@@ -18,7 +18,7 @@ use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
abstract class AbstractProtectedBeController extends AbstractBeController
{
protected function initializeAction()
protected function initializeAction(): void
{
if (!$this->backendUserHasUserGroup($this->getRequiredUserGroup())) {
$this->addFlashMessage(
......@@ -30,12 +30,9 @@ abstract class AbstractProtectedBeController extends AbstractBeController
}
}
/**
* @return int
*/
abstract protected function getRequiredUserGroup();
abstract protected function getRequiredUserGroup(): int;
protected function errorAction()
protected function errorAction(): string
{
$this->clearCacheOnError();
$message = '';
......
......@@ -20,9 +20,11 @@ use TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager;
class BeConfigurationController extends AbstractProtectedBeController
{
const CONTROLLER_NAME = 'BeConfiguration';
const ACTION_EDIT = 'edit';
const ACTION_UPDATE = 'update';
public const CONTROLLER_NAME = 'BeConfiguration';
public const ACTION_EDIT = 'edit';
public const ACTION_UPDATE = 'update';
/**
* @var BackendUserGroupRepository
......@@ -37,7 +39,7 @@ class BeConfigurationController extends AbstractProtectedBeController
$this->backendUserGroupRepository = $backendUserGroupRepository;
}
public function editAction()
public function editAction(): void
{
if (null === $this->configuration) {
$this->configuration = new Configuration();
......@@ -46,25 +48,19 @@ class BeConfigurationController extends AbstractProtectedBeController
$this->view->assign('beUserGroups', $this->backendUserGroupRepository->findAll());
}
public function updateAction(Configuration $configuration)
public function updateAction(Configuration $configuration): void
{
$this->configurationRepository->update($configuration);
$this->objectManager->get(PersistenceManager::class)->persistAll();
$this->redirect(BeDashboardController::ACTION_INDEX, BeDashboardController::CONTROLLER_NAME);
}
/**
* @return string
*/
public static function getActionsForModuleConfiguration()
public static function getActionsForModuleConfiguration(): string
{
return implode(',', [self::ACTION_EDIT, self::ACTION_UPDATE]);
}
/**
* @return int
*/
protected function getRequiredUserGroup()
protected function getRequiredUserGroup(): int
{
if (null === $this->configuration) {
return Configuration::AUTH_NONE;
......
......@@ -22,8 +22,9 @@ use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
class BeDashboardController extends AbstractBeController
{
const CONTROLLER_NAME = 'BeDashboard';
const ACTION_INDEX = 'index';
public const CONTROLLER_NAME = 'BeDashboard';
public const ACTION_INDEX = 'index';
/**
* @var ElectionRepository
......@@ -38,7 +39,7 @@ class BeDashboardController extends AbstractBeController
$this->electionRepository = $electionRepository;
}
public function indexAction()
public function indexAction(): void
{
$this->view->assignMultiple(
[
......@@ -101,10 +102,7 @@ class BeDashboardController extends AbstractBeController
}
}
/**
* @return string
*/
public static function getActionsForModuleConfiguration()
public static function getActionsForModuleConfiguration(): string
{
return self::ACTION_INDEX;
}
......
......@@ -18,24 +18,34 @@ use T3o\Election\Domain\Model\Elector;
use T3o\Election\Domain\Repository\ConfigurationRepository;
use T3o\Election\Domain\Repository\ElectionCircularRepository;
use T3o\Election\Domain\Repository\ElectionRepository;
use T3o\Election\Service\ElectionInvitationService;
use T3o\Election\Domain\Service\ElectionInvitationService;
use T3o\Election\Utility\MailUtility;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Utility\GeneralUtility;
class BeElectionCircularController extends AbstractProtectedBeController
{
const CONTROLLER_NAME = 'BeElectionCircular';
const ACTION_LIST = 'list';
const ACTION_NEW = 'new';
const ACTION_CREATE = 'create';
const ACTION_EDIT = 'edit';
const ACTION_UPDATE = 'update';
const ACTION_DELETE = 'delete';
const ACTION_PREVIEW = 'preview';
const ACTION_TEST_SEND = 'testSend';
const ACTION_SEND = 'send';
const ACTION_SEND_PREVIEW = 'sendPreview';
public const CONTROLLER_NAME = 'BeElectionCircular';
public const ACTION_LIST = 'list';
public const ACTION_NEW = 'new';
public const ACTION_CREATE = 'create';
public const ACTION_EDIT = 'edit';
public const ACTION_UPDATE = 'update';
public const ACTION_DELETE = 'delete';
public const ACTION_PREVIEW = 'preview';
public const ACTION_TEST_SEND = 'testSend';
public const ACTION_SEND = 'send';
public const ACTION_SEND_PREVIEW = 'sendPreview';
/**
* @var ElectionCircularRepository
......@@ -57,51 +67,48 @@ class BeElectionCircularController extends AbstractProtectedBeController
$this->electionRepository = $electionRepository;
}
public function listAction()
public function listAction(): void
{
$this->view->assign('electionCirculars', $this->electionCircularRepository->findAll());
}
public function newAction()
public function newAction(): void
{
$this->view->assign('electionCircular', $this->objectManager->get(ElectionCircular::class));
$this->view->assign('elections', $this->electionRepository->findAll());
}
public function createAction(ElectionCircular $electionCircular)
public function createAction(ElectionCircular $electionCircular): void
{
$this->electionCircularRepository->add($electionCircular);
$this->redirect(self::ACTION_LIST);
}
public function editAction(ElectionCircular $electionCircular)
public function editAction(ElectionCircular $electionCircular): void
{
$this->view->assign('electionCircular', $electionCircular);
$this->view->assign('elections', $this->electionRepository->findAll());
}
public function updateAction(ElectionCircular $electionCircular)
public function updateAction(ElectionCircular $electionCircular): void
{
$this->electionCircularRepository->update($electionCircular);
$this->redirect(self::ACTION_LIST);
}
public function deleteAction(ElectionCircular $electionCircular)
public function deleteAction(ElectionCircular $electionCircular): void
{
$this->electionCircularRepository->remove($electionCircular);
$this->redirect(self::ACTION_LIST);
}
public function previewAction(ElectionCircular $electionCircular)
public function previewAction(ElectionCircular $electionCircular): void
{
$this->view->assign('isPluginInstalled', $this->isPluginInstalled());
$this->view->assign('electionCircular', $electionCircular);
}
/**
* @param string $email
*/
public function testSendAction(ElectionCircular $electionCircular, $email)
public function testSendAction(ElectionCircular $electionCircular, string $email): void
{
$elector = new Elector();
$elector->setFirstName('[FIRST NAME]');
......@@ -122,12 +129,12 @@ class BeElectionCircularController extends AbstractProtectedBeController
);
}
public function sendPreviewAction(ElectionCircular $electionCircular)
public function sendPreviewAction(ElectionCircular $electionCircular): void
{
$this->view->assign('electionCircular', $electionCircular);
}
public function sendAction(ElectionCircular $electionCircular)
public function sendAction(ElectionCircular $electionCircular): void
{
$electionInvitationService = $this->objectManager->get(ElectionInvitationService::class);
$electionInvitationService->inviteElectors($this->configuration, $electionCircular);
......@@ -139,10 +146,7 @@ class BeElectionCircularController extends AbstractProtectedBeController
);
}
/**
* @return string
*/
public static function getActionsForModuleConfiguration()
public static function getActionsForModuleConfiguration(): string
{
return implode(
',',
......@@ -161,16 +165,12 @@ class BeElectionCircularController extends AbstractProtectedBeController
);
}
/**
* @return bool
*/
protected function isPluginInstalled()
protected function isPluginInstalled(): bool
{
$where['CType'] = 'list';
$where['list_type'] = 'election_pi1';
$where['hidden'] = 0;
// todo check also for enable fields
//$extendedDeleteClause = BackendUtility::BEenableFields('tt_content');
$count = $this->getDatabaseConnection()
->getConnectionForTable('tt_content')
->count('uid', 'tt_content', $where);
......@@ -178,19 +178,16 @@ class BeElectionCircularController extends AbstractProtectedBeController
return $count > 0;
}
/**
* @return int
*/
protected function getRequiredUserGroup()
protected function getRequiredUserGroup(): int
{
return $this->configuration->getElectionManagerGroup();
}
/**
* @return ConnectionPool
*/
protected function getDatabaseConnection()
protected function getDatabaseConnection(): ConnectionPool
{
return GeneralUtility::makeInstance(ConnectionPool::class);
/** @var ConnectionPool $pool */
$pool = GeneralUtility::makeInstance(ConnectionPool::class);
return $pool;
}
}
......@@ -21,14 +21,21 @@ use T3o\Election\Domain\Repository\NomineeRepository;
class BeElectionController extends AbstractProtectedBeController
{
const CONTROLLER_NAME = 'BeElection';
const ACTION_LIST = 'list';
const ACTION_NEW = 'new';
const ACTION_CREATE = 'create';
const ACTION_EDIT = 'edit';
const ACTION_UPDATE = 'update';
const ACTION_DELETE = 'delete';
const ACTION_SUMMARY = 'summary';
public const CONTROLLER_NAME = 'BeElection';
public const ACTION_LIST = 'list';
public const ACTION_NEW = 'new';
public const ACTION_CREATE = 'create';
public const ACTION_EDIT = 'edit';
public const ACTION_UPDATE = 'update';
public const ACTION_DELETE = 'delete';
public const ACTION_SUMMARY = 'summary';
/**
* @var ElectionRepository
......@@ -57,62 +64,59 @@ class BeElectionController extends AbstractProtectedBeController
$this->nomineeRepository = $nomineeRepository;
}
public function listAction()
public function listAction(): void
{
$this->view->assign('elections', $this->electionRepository->findAll());
}
public function newAction()
public function newAction(): void
{
$this->view->assign('election', $this->objectManager->get(Election::class));
$this->view->assign('electorates', $this->electorateRepository->findAll());
$this->view->assign('nominees', $this->nomineeRepository->findAll());
}
public function editAction(Election $election)
public function editAction(Election $election): void
{
$this->view->assign('election', $election);
$this->view->assign('electorates', $this->electorateRepository->findAll());
$this->view->assign('nominees', $this->nomineeRepository->findAll());
}
public function deleteAction(Election $election)
public function deleteAction(Election $election): void
{
$this->electionRepository->remove($election);
$this->redirect(self::ACTION_LIST);
}
public function initializeUpdateAction()
public function initializeUpdateAction(): void
{
$this->setDateTimeConverterOptions('election', ['startDate', 'endDate']);
}
public function updateAction(Election $election)
public function updateAction(Election $election): void
{
$this->electionRepository->update($election);
$this->redirect(self::ACTION_LIST);
}
public function initializeCreateAction()
public function initializeCreateAction(): void
{
$this->setDateTimeConverterOptions('election', ['startDate', 'endDate']);
}
public function createAction(Election $election)
public function createAction(Election $election): void
{
$this->electionRepository->add($election);
$this->redirect(self::ACTION_LIST);
}
public function summaryAction(Election $election)
public function summaryAction(Election $election): void
{
$this->view->assign('election', $election);
}
/**
* @return string
*/
public static function getActionsForModuleConfiguration()
public static function getActionsForModuleConfiguration(): string
{
return implode(
',',
......@@ -128,10 +132,7 @@ class BeElectionController extends AbstractProtectedBeController
);
}
/**
* @return int
*/
protected function getRequiredUserGroup()
protected function getRequiredUserGroup(): int
{
return $this->configuration->getElectionManagerGroup();
}
......
......@@ -17,12 +17,13 @@ use T3o\Election\Domain\Model\Dto\ElectorImport as ElectorImportDto;
use T3o\Election\Domain\Model\Election;
use T3o\Election\Domain\Model\ElectionInvitation;
use T3o\Election\Domain\Model\Elector;
use T3o\Election\Domain\Model\Electorate;
use T3o\Election\Domain\Model\ElectorImport;
use T3o\Election\Domain\Repository\ConfigurationRepository;
use T3o\Election\Domain\Repository\ElectorateRepository;
use T3o\Election\Domain\Repository\ElectorImportRepository;
use T3o\Election\Domain\Repository\ElectorRepository;
use T3o\Election\Service\ElectionInvitationService;
use T3o\Election\Domain\Service\ElectionInvitationService;
use T3o\Election\Utility\CsvUtility;
use T3o\Election\Utility\FileUtility;
use TYPO3\CMS\Core\Messaging\AbstractMessage;
......@@ -30,19 +31,31 @@ use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
class BeElectorController extends AbstractProtectedBeController
{
const CONTROLLER_NAME = 'BeElector';
const ACTION_NEW = 'new';
const ACTION_CREATE = 'create';
const ACTION_EDIT = 'edit';
const ACTION_UPDATE = 'update';
const ACTION_DELETE = 'delete';
const ACTION_LIST = 'list';
const ACTION_IMPORT = 'import';
const ACTION_EXPORT = 'export';
const ACTION_UPLOAD = 'upload';
const ACTION_PROCESS_IMPORT = 'processImport';
const ACTION_OVERWRITE_ALL = 'overwriteAll';
const ACTION_RESEND_ELECTION_INVITATION = 'resendElectionInvitation';
public const CONTROLLER_NAME = 'BeElector';
public const ACTION_NEW = 'new';
public const ACTION_CREATE = 'create';
public const ACTION_EDIT = 'edit';
public const ACTION_UPDATE = 'update';
public const ACTION_DELETE = 'delete';
public const ACTION_LIST = 'list';
public const ACTION_IMPORT = 'import';
public const ACTION_EXPORT = 'export';
public const ACTION_UPLOAD = 'upload';
public const ACTION_PROCESS_IMPORT = 'processImport';
public const ACTION_OVERWRITE_ALL = 'overwriteAll';
public const ACTION_RESEND_ELECTION_INVITATION = 'resendElectionInvitation';
/**
* @var ElectorateRepository
......@@ -71,50 +84,50 @@ class BeElectorController extends AbstractProtectedBeController
$this->electorImportRepository = $electorImportRepository;
}
public function newAction()
public function newAction(): void
{
$this->view->assign('elector', $this->objectManager->get(Elector::class));
$this->view->assign('electorates', $this->electorateRepository->findAll());
}
public function createAction(Elector $elector)
public function createAction(Elector $elector): void
{
$this->electorRepository->add($elector);
$this->redirect(self::ACTION_LIST);
}
public function editAction(Elector $elector)
public function editAction(Elector $elector): void
{
$this->view->assign('elector', $elector);
$this->view->assign('electorates', $this->electorateRepository->findAll());
}
public function updateAction(Elector $elector)
public function updateAction(Elector $elector): void
{
$this->electorRepository->update($elector);
$this->redirect(self::ACTION_LIST);
}
public function deleteAction(Elector $elector)
public function deleteAction(Elector $elector): void
{
$this->electorRepository->remove($elector);
$this->redirect(self::ACTION_LIST);
}
/**
* @param Election|null $election Optional Election which any imported Elector will be assigned to
* @param Electorate|null $election Optional Election which any imported Elector will be assigned to
*/
public function importAction(Election $election = null)
public function importAction(?Electorate $election = null): void
{
$this->view->assign('electorImport', new ElectorImportDto($election, $this->electorateRepository->findAll()));
}
public function listAction()
public function listAction(): void
{
$this->view->assign('electors', $this->electorRepository->findAll());
}
public function exportAction()
public function exportAction(): void
{
FileUtility::pushFile(
$this->objectManager->get(CsvUtility::class)->convertFromArray(
......@@ -124,7 +137,7 @@ class BeElectorController extends AbstractProtectedBeController
);
}
public function uploadAction(ElectorImportDto $electorImportDto)
public function uploadAction(ElectorImportDto $electorImportDto): void
{
if (FileUtility::isUploadedFileGood($electorImportDto->getImportInformation())) {
$this->electorImportRepository->removeAll();
......@@ -140,12 +153,12 @@ class BeElectorController extends AbstractProtectedBeController
$this->redirect(self::ACTION_PROCESS_IMPORT);
}
public function processImportAction()