Commit aed91d68 authored by Felix Herrmann's avatar Felix Herrmann
Browse files

Merge branch 'fix/run-php-cs-fixer' into 'task/be-functionality'

Run php-cs-fixer, update composer.json and add empty test directories

See merge request services/voting.typo3.org/extensions/election!23
parents c814efd6 e212e105
/Documentation-GENERATED-temp
.Build
composer.lock
<?php
$extensionKey = basename(__DIR__);
$finder = PhpCsFixer\Finder::create()
->in([
__DIR__ . '/Classes/',
__DIR__ . '/Tests/',
__DIR__ . '/Configuration/TCA/'
])
->exclude(__DIR__ . '/.Build/');
$date = date('Y');
$authors = 'Oliver Eglseder, Stefan Busemann, Christoph Pascher, Felix Herrmann, Wolf Utz';
$header = <<<EOF
This file is part of the "$extensionKey" Extension for TYPO3 CMS.
For the full copyright and license information, please read the
LICENSE.txt file that was distributed with this source code.
(c) $date TYPO3 Association $authors
EOF;
return PhpCsFixer\Config::create()
->setUsingCache(false)
->setRules([
'@PSR1' => true,
'@PSR2' => true,
'@Symfony' => true,
'header_comment' => [
'header' => $header,
'location' => 'after_open',
'separate' => 'both',
'commentType' => 'PHPDoc',
],
'no_useless_else' => true,
'no_useless_return' => true,
'no_unused_imports' => true,
'ordered_class_elements' => true,
'ordered_imports' => true,
'phpdoc_order' => true,
'phpdoc_summary' => false,
'blank_line_after_opening_tag' => false,
'concat_space' => ['spacing' => 'one'],
'array_syntax' => ['syntax' => 'short'],
'yoda_style' => true,
'declare_strict_types' => true,
'psr4' => true,
'no_php4_constructor' => true,
'no_short_echo_tag' => true,
'semicolon_after_instruction' => true,
'align_multiline_comment' => true,
'general_phpdoc_annotation_remove' => ['annotations' => ["author", "package"]],
'phpdoc_add_missing_param_annotation' => ['only_untyped' => false],
])
->setFinder($finder);
<?php
/**
* This file is part of the "election" Extension for TYPO3 CMS.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* (c) 2021 TYPO3 Association Oliver Eglseder, Stefan Busemann, Christoph Pascher, Felix Herrmann, Wolf Utz
*/
declare(strict_types=1);
namespace T3o\Election;
class Constants
......
<?php
namespace T3o\Election\Controller;
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
/**
* This file is part of the "election" Extension for TYPO3 CMS.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
* (c) 2021 TYPO3 Association Oliver Eglseder, Stefan Busemann, Christoph Pascher, Felix Herrmann, Wolf Utz
*/
declare(strict_types=1);
namespace T3o\Election\Controller;
use T3o\Election\Domain\Model\Configuration;
use T3o\Election\Domain\Repository\ConfigurationRepository;
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
use TYPO3\CMS\Core\Messaging\AbstractMessage;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
use TYPO3\CMS\Extbase\Mvc\View\ViewInterface;
use TYPO3\CMS\Extbase\Property\TypeConverter\DateTimeConverter;
use T3o\Election\Domain\Model\Configuration;
use T3o\Election\Domain\Repository\ConfigurationRepository;
use TYPO3\CMS\Extbase\Utility\DebuggerUtility;
abstract class AbstractBeController extends ActionController
{
......@@ -40,11 +38,6 @@ abstract class AbstractBeController extends ActionController
*/
protected $configurationRepository;
/**
* AbstractBeController constructor.
*
* @param ConfigurationRepository $configurationRepository
*/
public function __construct(ConfigurationRepository $configurationRepository)
{
$this->configurationRepository = $configurationRepository;
......@@ -59,29 +52,17 @@ abstract class AbstractBeController extends ActionController
$this->configuration = $this->configurationRepository->findCurrent();
}
/**
* @param ViewInterface $view
*/
public function initializeView(ViewInterface $view)
{
$view->assign('backendUserData', $this->backendUser->user);
$view->assign('configuration', $this->configuration);
}
/**
* @return BackendUserAuthentication
* @SuppressWarnings(PHPMD.Superglobals)
*/
protected static function getBackendUserAuthentication()
{
return $GLOBALS['BE_USER'];
}
/**
* @param string $messageBody
* @param string $messageTitle
* @param int $severity
* @param bool $storeInSession
* @param int $severity
* @param bool $storeInSession
*/
public function addFlashMessage(
$messageBody,
......@@ -95,9 +76,18 @@ abstract class AbstractBeController extends ActionController
parent::addFlashMessage($messageBody, $messageTitle, $severity, $storeInSession);
}
/**
* @return BackendUserAuthentication
* @SuppressWarnings(PHPMD.Superglobals)
*/
protected static function getBackendUserAuthentication()
{
return $GLOBALS['BE_USER'];
}
/**
* @param $argument
* @param array $properties
*
* @throws \TYPO3\CMS\Extbase\Mvc\Exception\NoSuchArgumentException
*/
protected function setDateTimeConverterOptions($argument, array $properties)
......@@ -114,18 +104,20 @@ abstract class AbstractBeController extends ActionController
/**
* @param int $requiredUserGroup UID of the user group
*
* @return bool
*/
protected function backendUserHasUserGroup($requiredUserGroup=0)
protected function backendUserHasUserGroup($requiredUserGroup = 0)
{
if (Configuration::AUTH_NONE === $requiredUserGroup) {
return true;
}
foreach ($this->backendUser->userGroups as $userGroup) {
if ((int)$userGroup['uid'] === $requiredUserGroup) {
if ((int) $userGroup['uid'] === $requiredUserGroup) {
return true;
}
}
return false;
}
}
<?php
namespace T3o\Election\Controller;
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
/**
* This file is part of the "election" Extension for TYPO3 CMS.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
* (c) 2021 TYPO3 Association Oliver Eglseder, Stefan Busemann, Christoph Pascher, Felix Herrmann, Wolf Utz
*/
declare(strict_types=1);
namespace T3o\Election\Controller;
use TYPO3\CMS\Core\Messaging\AbstractMessage;
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
......@@ -40,7 +38,7 @@ abstract class AbstractProtectedBeController extends AbstractBeController
protected function errorAction()
{
$this->clearCacheOnError();
$message = "";
$message = '';
foreach ($this->arguments->validate()->getFlattenedErrors() as $propertyPath => $errors) {
foreach ($errors as $error) {
$message .= PHP_EOL . 'Error for ' . $propertyPath . ': ' . $error->render();
......@@ -48,16 +46,16 @@ abstract class AbstractProtectedBeController extends AbstractBeController
}
$errorFlashMessage = $this->getErrorFlashMessage();
if ($errorFlashMessage !== false) {
if (false !== $errorFlashMessage) {
$errorFlashMessageObject = new \TYPO3\CMS\Core\Messaging\FlashMessage(
$errorFlashMessage . " " . $message,
$errorFlashMessage . ' ' . $message,
'',
\TYPO3\CMS\Core\Messaging\FlashMessage::ERROR
);
$this->controllerContext->getFlashMessageQueue()->enqueue($errorFlashMessageObject);
}
$referringRequest = $this->request->getReferringRequest();
if ($referringRequest !== null) {
if (null !== $referringRequest) {
$originalRequest = clone $this->request;
$this->request->setOriginalRequest($originalRequest);
$this->request->setOriginalRequestMappingResults($this->arguments->validate());
......
<?php
namespace T3o\Election\Controller;
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
/**
* This file is part of the "election" Extension for TYPO3 CMS.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
* (c) 2021 TYPO3 Association Oliver Eglseder, Stefan Busemann, Christoph Pascher, Felix Herrmann, Wolf Utz
*/
declare(strict_types=1);
namespace T3o\Election\Controller;
use T3o\Election\Domain\Model\Configuration;
use T3o\Election\Domain\Repository\ConfigurationRepository;
use TYPO3\CMS\Extbase\Domain\Repository\BackendUserGroupRepository;
use TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager;
/**
* Class BeConfigurationController
*/
class BeConfigurationController extends AbstractProtectedBeController
{
const CONTROLLER_NAME = 'BeConfiguration';
......@@ -51,9 +46,6 @@ class BeConfigurationController extends AbstractProtectedBeController
$this->view->assign('beUserGroups', $this->backendUserGroupRepository->findAll());
}
/**
* @param Configuration $configuration
*/
public function updateAction(Configuration $configuration)
{
$this->configurationRepository->update($configuration);
......
<?php
namespace T3o\Election\Controller;
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
/**
* This file is part of the "election" Extension for TYPO3 CMS.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
* (c) 2021 TYPO3 Association Oliver Eglseder, Stefan Busemann, Christoph Pascher, Felix Herrmann, Wolf Utz
*/
declare(strict_types=1);
namespace T3o\Election\Controller;
use T3o\Election\Domain\Repository\ConfigurationRepository;
use TYPO3\CMS\Core\Messaging\AbstractMessage;
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
use T3o\Election\Domain\Repository\ElectionCircularRepository;
use T3o\Election\Domain\Repository\ElectorImportRepository;
use T3o\Election\Domain\Repository\ElectionRepository;
use T3o\Election\Domain\Repository\ElectorImportRepository;
use TYPO3\CMS\Core\Messaging\AbstractMessage;
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
/**
* Dashboard controller
*/
class BeDashboardController extends AbstractBeController
{
const CONTROLLER_NAME = 'BeDashboard';
......@@ -43,9 +38,6 @@ class BeDashboardController extends AbstractBeController
$this->electionRepository = $electionRepository;
}
/**
*
*/
public function indexAction()
{
$this->view->assignMultiple(
......@@ -107,7 +99,6 @@ class BeDashboardController extends AbstractBeController
AbstractMessage::WARNING
);
}
}
/**
......
<?php
namespace T3o\Election\Controller;
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
/**
* This file is part of the "election" Extension for TYPO3 CMS.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
* (c) 2021 TYPO3 Association Oliver Eglseder, Stefan Busemann, Christoph Pascher, Felix Herrmann, Wolf Utz
*/
use T3o\Election\Domain\Repository\ConfigurationRepository;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\DatabaseConnection;
use TYPO3\CMS\Core\Utility\GeneralUtility;
declare(strict_types=1);
namespace T3o\Election\Controller;
use T3o\Election\Domain\Model\ElectionCircular;
use T3o\Election\Domain\Model\Elector;
use T3o\Election\Service\CircularService;
use T3o\Election\Service\ElectionInvitationService;
use T3o\Election\Utility\MailUtility;
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\Utility\MailUtility;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Utility\GeneralUtility;
/**
* Class BeConfigurationController
*/
class BeElectionCircularController extends AbstractProtectedBeController
{
const CONTROLLER_NAME = 'BeElectionCircular';
......@@ -63,62 +57,41 @@ class BeElectionCircularController extends AbstractProtectedBeController
$this->electionRepository = $electionRepository;
}
/**
*
*/
public function listAction()
{
$this->view->assign('electionCirculars', $this->electionCircularRepository->findAll());
}
/**
*
*/
public function newAction()
{
$this->view->assign('electionCircular', $this->objectManager->get(ElectionCircular::class));
$this->view->assign('elections', $this->electionRepository->findAll());
}
/**
* @param ElectionCircular $electionCircular
*/
public function createAction(ElectionCircular $electionCircular)
{
$this->electionCircularRepository->add($electionCircular);
$this->redirect(self::ACTION_LIST);
}
/**
* @param ElectionCircular $electionCircular
*/
public function editAction(ElectionCircular $electionCircular)
{
$this->view->assign('electionCircular', $electionCircular);
$this->view->assign('elections', $this->electionRepository->findAll());
}
/**
* @param ElectionCircular $electionCircular
*/
public function updateAction(ElectionCircular $electionCircular)
{
$this->electionCircularRepository->update($electionCircular);
$this->redirect(self::ACTION_LIST);
}
/**
* @param ElectionCircular $electionCircular
*/
public function deleteAction(ElectionCircular $electionCircular)
{
$this->electionCircularRepository->remove($electionCircular);
$this->redirect(self::ACTION_LIST);
}
/**
* @param ElectionCircular $electionCircular
*/
public function previewAction(ElectionCircular $electionCircular)
{
$this->view->assign('isPluginInstalled', $this->isPluginInstalled());
......@@ -126,7 +99,6 @@ class BeElectionCircularController extends AbstractProtectedBeController
}
/**
* @param ElectionCircular $electionCircular
* @param string $email
*/
public function testSendAction(ElectionCircular $electionCircular, $email)
......@@ -150,17 +122,11 @@ class BeElectionCircularController extends AbstractProtectedBeController
);
}
/**
* @param ElectionCircular $electionCircular
*/
public function sendPreviewAction(ElectionCircular $electionCircular)
{
$this->view->assign('electionCircular', $electionCircular);
}
/**
* @param ElectionCircular $electionCircular
*/
public function sendAction(ElectionCircular $electionCircular)
{
$electionInvitationService = $this->objectManager->get(ElectionInvitationService::class);
......@@ -173,24 +139,6 @@ class BeElectionCircularController extends AbstractProtectedBeController
);
}
/**
* @return bool
*/
protected function isPluginInstalled()
{
$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);
return $count > 0;
}
/**
* @return string
*/
......@@ -213,6 +161,23 @@ class BeElectionCircularController extends AbstractProtectedBeController
);
}
/**
* @return bool
*/
protected function isPluginInstalled()
{
$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);
return $count > 0;
}
/**
* @return int
*/
......
<?php
namespace T3o\Election\Controller;
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
/**
* This file is part of the "election" Extension for TYPO3 CMS.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
* (c) 2021 TYPO3 Association Oliver Eglseder, Stefan Busemann, Christoph Pascher, Felix Herrmann, Wolf Utz
*/
declare(strict_types=1);
namespace T3o\Election\Controller;
use T3o\Election\Domain\Model\Election;
use T3o\Election\Domain\Repository\ConfigurationRepository;
use T3o\Election\Domain\Repository\ElectionRepository;
use T3o\Election\Domain\Repository\ElectorateRepository;
use T3o\Election\Domain\Repository\NomineeRepository;
/**
* Class BeConfigurationController
*/
class BeElectionController extends AbstractProtectedBeController
{
const CONTROLLER_NAME = 'BeElection';
......@@ -47,7 +43,7 @@ class BeElectionController extends AbstractProtectedBeController
/**
* @var NomineeRepository
*/
protected $nomineeRepository ;
protected $nomineeRepository;
public function __construct(
ElectionRepository $electionRepository,
......@@ -61,17 +57,11 @@ class BeElectionController extends AbstractProtectedBeController
$this->nomineeRepository = $nomineeRepository;
}
/**
*
*/
public function listAction()
{
$this->view->assign('elections', $this->electionRepository->findAll());
}
/**
*
*/
public function newAction()
{
$this->view->assign('election', $this->objectManager->get(Election::class));
......@@ -79,9 +69,6 @@ class BeElectionController extends AbstractProtectedBeController
$this->view->assign('nominees', $this->nomineeRepository->findAll());
}
/**
* @param Election $election
*/
public function editAction(Election $election)
{
$this->view->assign('election', $election);
......@@ -89,52 +76,34 @@ class BeElectionController extends AbstractProtectedBeController
$this->view->assign('nominees', $this->nomineeRepository->findAll());