* use php-cs-fixer instead of phpcodesniffer * updated scrutinizer config * adjusted code yules to all files * updated CONTRIBUTING guidelines
This commit is contained in:
@@ -17,14 +17,14 @@ use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||
*/
|
||||
abstract class AbstractController extends Controller
|
||||
{
|
||||
const FLASH_SUCCESS = 'success';
|
||||
const FLASH_WARNING = 'warning';
|
||||
const FLASH_ERROR = 'error';
|
||||
public const FLASH_SUCCESS = 'success';
|
||||
public const FLASH_WARNING = 'warning';
|
||||
public const FLASH_ERROR = 'error';
|
||||
|
||||
const DOMAIN_FLASH = 'flashmessages';
|
||||
const DOMAIN_ERROR = 'exceptions';
|
||||
public const DOMAIN_FLASH = 'flashmessages';
|
||||
public const DOMAIN_ERROR = 'exceptions';
|
||||
|
||||
const ROLE_ADMIN = 'ROLE_ADMIN';
|
||||
public const ROLE_ADMIN = 'ROLE_ADMIN';
|
||||
|
||||
/**
|
||||
* @return object|\Symfony\Component\Translation\DataCollectorTranslator|\Symfony\Component\Translation\IdentityTranslator
|
||||
@@ -37,8 +37,8 @@ abstract class AbstractController extends Controller
|
||||
/**
|
||||
* A translated helper for denyAccessUnlessGranted()
|
||||
*
|
||||
* @param $attributes
|
||||
* @param null $subject
|
||||
* @param mixed $attributes
|
||||
* @param mixed $subject
|
||||
* @param string $translation
|
||||
* @param array $parameter
|
||||
* @throws AccessDeniedException
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
namespace App\Controller;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
|
||||
use App\Entity\Activity;
|
||||
use App\Repository\ActivityRepository;
|
||||
@@ -22,7 +21,6 @@ use App\Repository\ActivityRepository;
|
||||
*/
|
||||
class ActivityController extends Controller
|
||||
{
|
||||
|
||||
/**
|
||||
* @return ActivityRepository
|
||||
*/
|
||||
|
||||
@@ -30,7 +30,6 @@ use App\Repository\Query\ActivityQuery;
|
||||
*/
|
||||
class ActivityController extends AbstractController
|
||||
{
|
||||
|
||||
/**
|
||||
* @return \App\Repository\ActivityRepository
|
||||
*/
|
||||
@@ -116,7 +115,7 @@ class ActivityController extends AbstractController
|
||||
|
||||
$deleteForm->handleRequest($request);
|
||||
|
||||
if ($stats->getRecordAmount() == 0 || ($deleteForm->isSubmitted() && $deleteForm->isValid())) {
|
||||
if (0 == $stats->getRecordAmount() || ($deleteForm->isSubmitted() && $deleteForm->isValid())) {
|
||||
$entityManager = $this->getDoctrine()->getManager();
|
||||
$entityManager->remove($activity);
|
||||
$entityManager->flush();
|
||||
|
||||
@@ -29,7 +29,6 @@ use App\Repository\Query\CustomerQuery;
|
||||
*/
|
||||
class CustomerController extends AbstractController
|
||||
{
|
||||
|
||||
/**
|
||||
* @return \App\Repository\CustomerRepository
|
||||
*/
|
||||
@@ -133,7 +132,7 @@ class CustomerController extends AbstractController
|
||||
|
||||
$deleteForm->handleRequest($request);
|
||||
|
||||
if ($stats->getRecordAmount() == 0 || ($deleteForm->isSubmitted() && $deleteForm->isValid())) {
|
||||
if (0 == $stats->getRecordAmount() || ($deleteForm->isSubmitted() && $deleteForm->isValid())) {
|
||||
$entityManager = $this->getDoctrine()->getManager();
|
||||
$entityManager->remove($customer);
|
||||
$entityManager->flush();
|
||||
|
||||
@@ -31,7 +31,6 @@ use App\Repository\Query\ProjectQuery;
|
||||
*/
|
||||
class ProjectController extends AbstractController
|
||||
{
|
||||
|
||||
/**
|
||||
* @return \App\Repository\ProjectRepository
|
||||
*/
|
||||
@@ -110,7 +109,7 @@ class ProjectController extends AbstractController
|
||||
|
||||
$deleteForm->handleRequest($request);
|
||||
|
||||
if ($stats->getRecordAmount() == 0 || ($deleteForm->isSubmitted() && $deleteForm->isValid())) {
|
||||
if (0 == $stats->getRecordAmount() || ($deleteForm->isSubmitted() && $deleteForm->isValid())) {
|
||||
$entityManager = $this->getDoctrine()->getManager();
|
||||
$entityManager->remove($project);
|
||||
$entityManager->flush();
|
||||
|
||||
@@ -133,9 +133,15 @@ class TimesheetController extends AbstractController
|
||||
*/
|
||||
public function deleteAction(Timesheet $entry, Request $request)
|
||||
{
|
||||
$entityManager = $this->getDoctrine()->getManager();
|
||||
$entityManager->remove($entry);
|
||||
$entityManager->flush();
|
||||
try {
|
||||
$entityManager = $this->getDoctrine()->getManager();
|
||||
$entityManager->remove($entry);
|
||||
$entityManager->flush();
|
||||
|
||||
$this->flashSuccess('action.deleted_successfully');
|
||||
} catch (\Exception $ex) {
|
||||
$this->flashError('action.deleted.error', ['%reason%' => $ex->getMessage()]);
|
||||
}
|
||||
|
||||
return $this->redirectToRoute('admin_timesheet_paginated', ['page' => $request->get('page')]);
|
||||
}
|
||||
|
||||
@@ -29,7 +29,6 @@ use Symfony\Component\HttpFoundation\Request;
|
||||
*/
|
||||
class UserController extends AbstractController
|
||||
{
|
||||
|
||||
/**
|
||||
* @Route("/", defaults={"page": 1}, name="admin_user")
|
||||
* @Route("/page/{page}", requirements={"page": "[1-9]\d*"}, name="admin_user_paginated")
|
||||
|
||||
@@ -105,7 +105,7 @@ class DashboardController extends Controller
|
||||
//"{{ widgets.info_box_counter('stats.amountThisMonth', timesheetGlobal.amountThisMonth|money, 'money', 'green') }}",
|
||||
"{{ widgets.info_box_counter('stats.durationTotal', timesheetGlobal.durationTotal|duration(true), 'hourglass-o', 'yellow') }}",
|
||||
//"{{ widgets.info_box_counter('stats.amountTotal', timesheetGlobal.amountTotal|money, 'money', 'red') }}",
|
||||
"{{ widgets.info_box_counter('stats.activeRecordings', timesheetGlobal.activeCurrently, 'hourglass-o', 'red', path('admin_timesheet', {'state': ".TimesheetQuery::STATE_RUNNING."})) }}",
|
||||
"{{ widgets.info_box_counter('stats.activeRecordings', timesheetGlobal.activeCurrently, 'hourglass-o', 'red', path('admin_timesheet', {'state': " . TimesheetQuery::STATE_RUNNING . '})) }}',
|
||||
],
|
||||
];
|
||||
|
||||
|
||||
@@ -23,9 +23,8 @@ use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
|
||||
*/
|
||||
class HelpController extends Controller
|
||||
{
|
||||
|
||||
const README = 'README';
|
||||
const DOCS_DIR = 'var/docs/';
|
||||
public const README = 'README';
|
||||
public const DOCS_DIR = 'var/docs/';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
@@ -49,10 +48,10 @@ class HelpController extends Controller
|
||||
* @param string $chapter
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function indexAction(?string $chapter)
|
||||
public function indexAction(string $chapter)
|
||||
{
|
||||
$breadcrumb = [self::README];
|
||||
if ($chapter !== self::README) {
|
||||
if (self::README !== $chapter) {
|
||||
$breadcrumb[] = $chapter;
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ use App\Model\InvoiceModel;
|
||||
use App\Repository\Query\BaseQuery;
|
||||
use App\Repository\Query\InvoiceQuery;
|
||||
use App\Repository\Query\TimesheetQuery;
|
||||
use App\Repository\TimesheetRepository;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
|
||||
@@ -31,7 +32,6 @@ use Symfony\Component\HttpFoundation\Request;
|
||||
*/
|
||||
class InvoiceController extends AbstractController
|
||||
{
|
||||
|
||||
/**
|
||||
* @var ServiceInvoice
|
||||
*/
|
||||
@@ -97,11 +97,13 @@ class InvoiceController extends AbstractController
|
||||
$query = $form->getData();
|
||||
$query->setResultType(TimesheetQuery::RESULT_TYPE_QUERYBUILDER);
|
||||
|
||||
if ($query->getCustomer() !== null) {
|
||||
if (null !== $query->getCustomer()) {
|
||||
$query->getBegin()->setTime(0, 0, 0);
|
||||
$query->getEnd()->setTime(23, 59, 59);
|
||||
|
||||
$queryBuilder = $this->getDoctrine()->getRepository(Timesheet::class)->findByQuery($query);
|
||||
/* @var TimesheetRepository $timeRepo */
|
||||
$timeRepo = $this->getDoctrine()->getRepository(Timesheet::class);
|
||||
$queryBuilder = $timeRepo->findByQuery($query);
|
||||
$entries = $queryBuilder->getQuery()->getResult();
|
||||
}
|
||||
}
|
||||
@@ -114,12 +116,12 @@ class InvoiceController extends AbstractController
|
||||
$action = null;
|
||||
if ($query->getTemplate() !== null) {
|
||||
$generator = $this->service->getNumberGeneratorByName($query->getTemplate()->getNumberGenerator());
|
||||
if ($generator === null) {
|
||||
if (null === $generator) {
|
||||
throw new \Exception('Unknown number generator: ' . $query->getTemplate()->getNumberGenerator());
|
||||
}
|
||||
|
||||
$calculator = $this->service->getCalculatorByName($query->getTemplate()->getCalculator());
|
||||
if ($calculator === null) {
|
||||
if (null === $calculator) {
|
||||
throw new \Exception('Unknown invoice calculator: ' . $query->getTemplate()->getCalculator());
|
||||
}
|
||||
|
||||
@@ -144,12 +146,12 @@ class InvoiceController extends AbstractController
|
||||
* TODO permission
|
||||
*
|
||||
* @param $page
|
||||
* @param Request $request
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function listTemplateAction($page, Request $request)
|
||||
public function listTemplateAction($page)
|
||||
{
|
||||
$templates = $this->getRepository()->findByQuery(new BaseQuery());
|
||||
|
||||
return $this->render('invoice/templates.html.twig', [
|
||||
'entries' => $templates,
|
||||
'page' => $page,
|
||||
@@ -186,6 +188,7 @@ class InvoiceController extends AbstractController
|
||||
if (!$this->getRepository()->hasTemplate()) {
|
||||
$this->flashWarning('invoice.first_template');
|
||||
}
|
||||
|
||||
return $this->renderTemplateForm(new InvoiceTemplate(), $request);
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController as SymfonyAbstractController;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
|
||||
@@ -18,7 +18,7 @@ use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
|
||||
* Controller used to manage the application security.
|
||||
* See http://symfony.com/doc/current/cookbook/security/form_login_setup.html.
|
||||
*/
|
||||
class SecurityController extends AbstractController
|
||||
class SecurityController extends SymfonyAbstractController
|
||||
{
|
||||
/**
|
||||
* @Route("/login", name="security_login")
|
||||
@@ -30,6 +30,7 @@ class SecurityController extends AbstractController
|
||||
'error' => $helper->getLastAuthenticationError(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* This is the route the user can use to logout.
|
||||
*
|
||||
|
||||
@@ -95,10 +95,9 @@ class TimesheetController extends AbstractController
|
||||
* @Security("is_granted('stop', entry)")
|
||||
*
|
||||
* @param Timesheet $entry
|
||||
* @param Request $request
|
||||
* @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function stopAction(Timesheet $entry, Request $request)
|
||||
public function stopAction(Timesheet $entry)
|
||||
{
|
||||
return $this->stop($entry, 'timesheet');
|
||||
}
|
||||
@@ -110,10 +109,9 @@ class TimesheetController extends AbstractController
|
||||
* @Method({"GET", "POST"})
|
||||
* @Security("is_granted('start', activity)")
|
||||
*
|
||||
* @param Request $request
|
||||
* @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function startAction(Activity $activity, Request $request)
|
||||
public function startAction(Activity $activity)
|
||||
{
|
||||
$user = $this->getUser();
|
||||
|
||||
@@ -170,9 +168,15 @@ class TimesheetController extends AbstractController
|
||||
*/
|
||||
public function deleteAction(Timesheet $entry, Request $request)
|
||||
{
|
||||
$entityManager = $this->getDoctrine()->getManager();
|
||||
$entityManager->remove($entry);
|
||||
$entityManager->flush();
|
||||
try {
|
||||
$entityManager = $this->getDoctrine()->getManager();
|
||||
$entityManager->remove($entry);
|
||||
$entityManager->flush();
|
||||
|
||||
$this->flashSuccess('action.deleted_successfully');
|
||||
} catch (\Exception $ex) {
|
||||
$this->flashError('action.deleted.error', ['%reason%' => $ex->getMessage()]);
|
||||
}
|
||||
|
||||
return $this->redirectToRoute('timesheet_paginated', ['page' => $request->get('page')]);
|
||||
}
|
||||
|
||||
@@ -10,15 +10,17 @@
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Entity\Timesheet;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use App\Repository\TimesheetRepository;
|
||||
use Doctrine\Common\Persistence\ManagerRegistry;
|
||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
/**
|
||||
* Helper functions for Timesheet controller
|
||||
*/
|
||||
trait TimesheetControllerTrait
|
||||
{
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
@@ -164,4 +166,45 @@ trait TimesheetControllerTrait
|
||||
* @return \Symfony\Component\Form\FormInterface
|
||||
*/
|
||||
abstract protected function getEditForm(Timesheet $entry, $page);
|
||||
|
||||
/**
|
||||
* Adds a "successful" flash message to the stack.
|
||||
*
|
||||
* @param string $translationKey
|
||||
* @param array $parameter
|
||||
*/
|
||||
abstract protected function flashSuccess($translationKey, $parameter = []);
|
||||
|
||||
/**
|
||||
* Adds a "error" flash message to the stack.
|
||||
*
|
||||
* @param $translationKey
|
||||
* @param array $parameter
|
||||
*/
|
||||
abstract protected function flashError($translationKey, $parameter = []);
|
||||
|
||||
/**
|
||||
* Shortcut to return the Doctrine Registry service.
|
||||
*
|
||||
* @throws \LogicException If DoctrineBundle is not available
|
||||
*/
|
||||
abstract protected function getDoctrine(): ManagerRegistry;
|
||||
|
||||
/**
|
||||
* Returns a RedirectResponse to the given route with the given parameters.
|
||||
*/
|
||||
abstract protected function redirectToRoute(string $route, array $parameters = [], int $status = 302): RedirectResponse;
|
||||
|
||||
/**
|
||||
* Renders a view.
|
||||
*/
|
||||
abstract protected function render(string $view, array $parameters = [], Response $response = null): Response;
|
||||
|
||||
/**
|
||||
* Get a user from the Security Token Storage.
|
||||
*
|
||||
* @return mixed
|
||||
* @throws \LogicException If SecurityBundle is not available
|
||||
*/
|
||||
abstract protected function getUser();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user