phpstan level 3, fixed deprecations, code cleanup (#811)
This commit is contained in:
@@ -31,11 +31,18 @@ use Symfony\Component\Routing\Annotation\Route;
|
||||
class ActivityController extends AbstractController
|
||||
{
|
||||
/**
|
||||
* @return \App\Repository\ActivityRepository
|
||||
* @var ActivityRepository
|
||||
*/
|
||||
protected function getRepository()
|
||||
private $repository;
|
||||
|
||||
public function __construct(ActivityRepository $repository)
|
||||
{
|
||||
return $this->getDoctrine()->getRepository(Activity::class);
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
protected function getRepository(): ActivityRepository
|
||||
{
|
||||
return $this->repository;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -45,12 +45,11 @@ class InvoiceController extends AbstractController
|
||||
* @var TimesheetRepository
|
||||
*/
|
||||
protected $timesheetRepository;
|
||||
/**
|
||||
* @var UserDateTimeFactory
|
||||
*/
|
||||
protected $dateTimeFactory;
|
||||
|
||||
/**
|
||||
* @param ServiceInvoice $service
|
||||
* @param InvoiceTemplateRepository $invoice
|
||||
*/
|
||||
public function __construct(ServiceInvoice $service, InvoiceTemplateRepository $invoice, UserDateTimeFactory $dateTimeFactory)
|
||||
{
|
||||
$this->service = $service;
|
||||
@@ -222,7 +221,7 @@ class InvoiceController extends AbstractController
|
||||
* @Route(path="/template/page/{page}", requirements={"page": "[1-9]\d*"}, name="admin_invoice_template_paginated", methods={"GET", "POST"})
|
||||
* @Security("is_granted('view_invoice_template')")
|
||||
*
|
||||
* @param $page
|
||||
* @param int $page
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function listTemplateAction($page)
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Entity\Timesheet;
|
||||
use App\Entity\User;
|
||||
use App\Event\PrepareUserEvent;
|
||||
use App\Form\UserApiTokenType;
|
||||
@@ -67,9 +66,19 @@ class ProfileController extends AbstractController
|
||||
* @Route(path="/{username}", name="user_profile", methods={"GET"})
|
||||
* @Security("is_granted('view', profile)")
|
||||
*/
|
||||
public function indexAction(User $profile)
|
||||
public function indexAction(User $profile, TimesheetRepository $repository)
|
||||
{
|
||||
return $this->renderProfileView($profile, 'charts', 'user/stats.html.twig', []);
|
||||
$userStats = $repository->getUserStatistics($profile);
|
||||
$monthlyStats = $repository->getMonthlyStats($profile);
|
||||
|
||||
$viewVars = [
|
||||
'tab' => 'charts',
|
||||
'user' => $profile,
|
||||
'stats' => $userStats,
|
||||
'years' => $monthlyStats,
|
||||
];
|
||||
|
||||
return $this->render('user/stats.html.twig', $viewVars);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -271,23 +280,6 @@ class ProfileController extends AbstractController
|
||||
]);
|
||||
}
|
||||
|
||||
protected function renderProfileView(User $user, string $tab, string $template, array $vars)
|
||||
{
|
||||
/* @var $timesheetRepo TimesheetRepository */
|
||||
$timesheetRepo = $this->getDoctrine()->getRepository(Timesheet::class);
|
||||
$userStats = $timesheetRepo->getUserStatistics($user);
|
||||
$monthlyStats = $timesheetRepo->getMonthlyStats($user);
|
||||
|
||||
$viewVars = [
|
||||
'tab' => $tab,
|
||||
'user' => $user,
|
||||
'stats' => $userStats,
|
||||
'years' => $monthlyStats,
|
||||
];
|
||||
|
||||
return $this->render($template, array_merge($viewVars, $vars));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User $user
|
||||
* @return \Symfony\Component\Form\FormInterface
|
||||
|
||||
@@ -31,11 +31,18 @@ use Symfony\Component\Routing\Annotation\Route;
|
||||
class ProjectController extends AbstractController
|
||||
{
|
||||
/**
|
||||
* @return \App\Repository\ProjectRepository
|
||||
* @var ProjectRepository
|
||||
*/
|
||||
protected function getRepository()
|
||||
private $repository;
|
||||
|
||||
public function __construct(ProjectRepository $repository)
|
||||
{
|
||||
return $this->getDoctrine()->getRepository(Project::class);
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
protected function getRepository(): ProjectRepository
|
||||
{
|
||||
return $this->repository;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -64,7 +71,7 @@ class ProjectController extends AbstractController
|
||||
}
|
||||
|
||||
/* @var $entries Pagerfanta */
|
||||
$entries = $this->getDoctrine()->getRepository(Project::class)->findByQuery($query);
|
||||
$entries = $this->getRepository()->findByQuery($query);
|
||||
|
||||
return $this->render('project/index.html.twig', [
|
||||
'entries' => $entries,
|
||||
|
||||
@@ -17,6 +17,7 @@ use App\Form\Toolbar\TimesheetToolbarForm;
|
||||
use App\Repository\ActivityRepository;
|
||||
use App\Repository\ProjectRepository;
|
||||
use App\Repository\Query\TimesheetQuery;
|
||||
use App\Repository\TagRepository;
|
||||
use App\Repository\TimesheetRepository;
|
||||
use App\Timesheet\UserDateTimeFactory;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
@@ -35,15 +36,16 @@ abstract class TimesheetAbstractController extends AbstractController
|
||||
* @var TimesheetConfiguration
|
||||
*/
|
||||
protected $configuration;
|
||||
|
||||
/**
|
||||
* @param UserDateTimeFactory $dateTime
|
||||
* @param TimesheetConfiguration $configuration
|
||||
* @var TimesheetRepository
|
||||
*/
|
||||
public function __construct(UserDateTimeFactory $dateTime, TimesheetConfiguration $configuration)
|
||||
protected $repository;
|
||||
|
||||
public function __construct(UserDateTimeFactory $dateTime, TimesheetConfiguration $configuration, TimesheetRepository $repository)
|
||||
{
|
||||
$this->dateTime = $dateTime;
|
||||
$this->configuration = $configuration;
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -59,7 +61,7 @@ abstract class TimesheetAbstractController extends AbstractController
|
||||
*/
|
||||
protected function getRepository()
|
||||
{
|
||||
return $this->getDoctrine()->getRepository(Timesheet::class);
|
||||
return $this->repository;
|
||||
}
|
||||
|
||||
protected function index($page, Request $request, string $renderTemplate)
|
||||
@@ -86,9 +88,11 @@ abstract class TimesheetAbstractController extends AbstractController
|
||||
|
||||
$tags = $query->getTags(true);
|
||||
if (!empty($tags)) {
|
||||
/** @var TagRepository $tagRepo */
|
||||
$tagRepo = $this->getDoctrine()->getRepository(Tag::class);
|
||||
$query->setTags(
|
||||
new ArrayCollection(
|
||||
$this->getDoctrine()->getRepository(Tag::class)->findIdsByTagNameList(implode(',', $tags))
|
||||
$tagRepo->findIdsByTagNameList(implode(',', $tags))
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ class TimesheetTeamController extends TimesheetAbstractController
|
||||
* @Route(path="/page/{page}", requirements={"page": "[1-9]\d*"}, name="admin_timesheet_paginated", methods={"GET"})
|
||||
* @Security("is_granted('view_other_timesheet')")
|
||||
*
|
||||
* @param $page
|
||||
* @param int $page
|
||||
* @param Request $request
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
|
||||
@@ -9,11 +9,12 @@
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Entity\Timesheet;
|
||||
use App\Entity\User;
|
||||
use App\Form\Toolbar\UserToolbarForm;
|
||||
use App\Form\UserCreateType;
|
||||
use App\Repository\Query\UserQuery;
|
||||
use App\Repository\TimesheetRepository;
|
||||
use App\Repository\UserRepository;
|
||||
use App\Security\RolePermissionManager;
|
||||
use Pagerfanta\Pagerfanta;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
|
||||
@@ -33,21 +34,23 @@ class UserController extends AbstractController
|
||||
* @var UserPasswordEncoderInterface
|
||||
*/
|
||||
protected $encoder;
|
||||
|
||||
/**
|
||||
* @param UserPasswordEncoderInterface $encoder
|
||||
* @var UserRepository
|
||||
*/
|
||||
public function __construct(UserPasswordEncoderInterface $encoder)
|
||||
protected $repository;
|
||||
|
||||
public function __construct(UserPasswordEncoderInterface $encoder, UserRepository $repository)
|
||||
{
|
||||
$this->encoder = $encoder;
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \App\Repository\UserRepository
|
||||
* @return UserRepository
|
||||
*/
|
||||
protected function getRepository()
|
||||
{
|
||||
return $this->getDoctrine()->getRepository(User::class);
|
||||
return $this->repository;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -133,13 +136,14 @@ class UserController extends AbstractController
|
||||
*
|
||||
* @param User $userToDelete
|
||||
* @param Request $request
|
||||
* @param TimesheetRepository $repository
|
||||
* @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
|
||||
* @throws \Doctrine\ORM\NonUniqueResultException
|
||||
*/
|
||||
public function deleteAction(User $userToDelete, Request $request)
|
||||
public function deleteAction(User $userToDelete, Request $request, TimesheetRepository $repository)
|
||||
{
|
||||
// $userToDelete MUST not be called $user, as $user is always the current user!
|
||||
$stats = $this->getDoctrine()->getRepository(Timesheet::class)->getUserStatistics($userToDelete);
|
||||
$stats = $repository->getUserStatistics($userToDelete);
|
||||
|
||||
$deleteForm = $this->createFormBuilder(null, [
|
||||
'attr' => [
|
||||
|
||||
Reference in New Issue
Block a user