Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Phpstan level 2 #245

Open
wants to merge 15 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
},
"require-dev": {
"phpstan/phpstan": "^1.10",
"phpstan/phpstan-doctrine": "^1.3",
"phpunit/phpunit": "^9.5",
"symfony/browser-kit": "6.2.*",
"symfony/css-selector": "6.2.*",
Expand Down
74 changes: 73 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion phpstan.dist.neon
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
parameters:
level: 1
level: 2
paths:
- bin/
- config/
- public/
- src/
- tests/
includes:
- vendor/phpstan/phpstan-doctrine/extension.neon
6 changes: 6 additions & 0 deletions src/Command/ConnectDefaultToTeamsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
use App\Entity\Team;
use App\Service\ConnectDefaultToTeamsService;
use Doctrine\ORM\EntityManagerInterface;
use LogicException;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\ProgressBar;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\ConsoleOutputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;

Expand All @@ -36,6 +38,10 @@ protected function configure()

protected function execute(InputInterface $input, OutputInterface $output): int
{
if (!$output instanceof ConsoleOutputInterface) {
throw new LogicException('This command accepts only an instance of "ConsoleOutputInterface".');
}

$io = new SymfonyStyle($input, $output);
$teams = $this->em->getRepository(Team::class)->findAll();
$io->success(sprintf('We will connect %d Teams', sizeof($teams)));
Expand Down
2 changes: 2 additions & 0 deletions src/Command/TeamNewCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use App\Service\ConnectDefaultToTeamsService;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\QuestionHelper;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
Expand Down Expand Up @@ -36,6 +37,7 @@ public function __construct(EntityManagerInterface $entityManager, ConnectDefaul
protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);
/** @var QuestionHelper $helper */
$helper = $this->getHelper('question');
$team = new Team();
$question = new Question('Team name (identical to keycloak group name if keycloak groups are used): ', 'TestCompany');
Expand Down
34 changes: 21 additions & 13 deletions src/Controller/AkademieController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

namespace App\Controller;

use App\DataTypes\ParticipationStateTypes;
use App\Entity\AkademieBuchungen;
use App\Entity\Participation;
use App\Entity\User;
use App\Repository\AkademieBuchungenRepository;
use App\Service\SecurityService;
use DateTime;
Expand All @@ -19,8 +18,6 @@
#[Route(path: '/akademie', name: 'akademie')]
class AkademieController extends BaseController
{


public function __construct(
private readonly TranslatorInterface $translator,
private EntityManagerInterface $em,
Expand All @@ -35,11 +32,13 @@ public function academyLesson(
AkademieBuchungenRepository $academyBillingRepository,
): Response
{
$team = $this->getUser()->getAkademieUser();
/** @var User $user */
$user = $this->getUser();
$team = $user->getAkademieUser();
$today = new DateTime();
$buchung = $academyBillingRepository->find($request->get('kurs'));

if (!$securityService->teamCheck($team) || $buchung->getUser() !== $this->getUser()) {
if (!$securityService->teamCheck($team) || $buchung->getUser() !== $user) {
return $this->redirectToRoute('akademie');
}

Expand Down Expand Up @@ -68,7 +67,10 @@ public function academyLessonCertificate(
DompdfWrapper $wrapper,
): Response
{
if ($billing->getUser() !== $this->getUser()) {
/** @var User $user */
$user = $this->getUser();

if ($billing->getUser() !== $user) {
return $this->redirectToRoute('akademie');
}

Expand All @@ -77,8 +79,8 @@ public function academyLessonCertificate(
// Retrieve the HTML generated in our twig file
$html = $this->renderView('bericht/zertifikatAkademie.html.twig', [
'daten' => $billing,
'team' => $this->getUser()->getAkademieUser(),
'user' => $this->getUser(),
'team' => $user->getAkademieUser(),
'user' => $user,
]);

//Generate PDF File for Download
Expand All @@ -98,12 +100,15 @@ public function academyLessonFinish(
AkademieBuchungenRepository $academyBillingRepository,
): Response
{
$team = $this->getUser()->getAkademieUser();
/** @var User $user */
$user = $this->getUser();

$team = $user->getAkademieUser();

$today = new DateTime();
$buchung = $academyBillingRepository->findOneBy(['finishedID' => $request->get('id')]);

if (!$securityService->teamCheck($team) || $buchung->getUser() !== $this->getUser()) {
if (!$securityService->teamCheck($team) || $buchung->getUser() !== $user) {
return $this->redirectToRoute('akademie');
}

Expand Down Expand Up @@ -134,13 +139,16 @@ public function index(
AkademieBuchungenRepository $bookingRepository
): Response
{
$team = $this->getUser()->getAkademieUser();
/** @var User $user */
$user = $this->getUser();

$team = $user->getAkademieUser();

if (!$securityService->teamCheck($team)) {
return $this->redirectToRoute('dashboard');
}

$bookings = $bookingRepository->findMyBuchungenByUser($this->getUser());
$bookings = $bookingRepository->findMyBuchungenByUser($user);
return $this->render('akademie/index.html.twig', [
'buchungen' => $bookings,
'currentTeam' => $team,
Expand Down
21 changes: 12 additions & 9 deletions src/Controller/BerichtController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

namespace App\Controller;

use App\Entity\User;
use App\Form\Type\ReportExportType;
use App\Repository\AkademieBuchungenRepository;
use App\Repository\AuditTomRepository;
Expand Down Expand Up @@ -148,6 +149,7 @@ public function reportAcademy(
SecurityService $securityService,
): Response
{
/** @var User $user */
$user = $this->getUser();
$team = $user->getAkademieUser();

Expand All @@ -159,7 +161,7 @@ public function reportAcademy(

return $this->render('bericht/akademie.html.twig', [
'daten' => $daten,
'team' => $this->getUser()->getAkademieUser()
'team' => $user->getAkademieUser()
]);
}

Expand All @@ -172,7 +174,6 @@ public function reportAudit(
SecurityService $securityService,
)
{

$req = $request->get('id');

$team = $currentTeamService->getCurrentTeam($this->getUser());
Expand Down Expand Up @@ -530,29 +531,31 @@ public function reportRequest(
SecurityService $securityService,
)
{

$id = $request->get('id');
$team = $currentTeamService->getCurrentTeam($this->getUser());
$clientRequests = [];

if ($id) {
$clientRequest = $clientRequestRepository->findBy(['id'=>$id]);
$title = $this->translator->trans(id: 'report.about.clientRequestBy', domain: 'bericht') . ' ' . $clientRequest->getName();
$clientRequests = $clientRequestRepository->findBy(['id'=>$id]);

$requestName = (count($clientRequests) > 0) ? $clientRequests[0]->getName() : '';
$title = $this->translator->trans(id: 'report.about.clientRequestBy', domain: 'bericht') . ' ' . $requestName;
} else {
$clientRequest = $clientRequestRepository->findBy(['team' => $team, 'activ' => true], ['createdAt' => 'DESC']);
$clientRequests = $clientRequestRepository->findBy(['team' => $team, 'activ' => true], ['createdAt' => 'DESC']);
$title = $this->translator->trans(id: 'report.about.clientRequest', domain: 'bericht');
}

if (count($clientRequest) < 1) {
if (count($clientRequests) === 0) {
return $this->redirectNoReport();
}

if (!$securityService->checkTeamAccessToData($team, $clientRequest[0])) {
if (!$securityService->checkTeamAccessToData($team, $clientRequests[0])) {
return $this->redirectToRoute('dashboard');
}

// Retrieve the HTML generated in our twig file
$html = $this->renderView('bericht/request.html.twig', [
'daten' => $clientRequest,
'daten' => $clientRequests,
'titel' => $title,
'team' => $team,
'all' => $request->get('all'),
Expand Down
20 changes: 11 additions & 9 deletions src/Controller/ClientRequestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
namespace App\Controller;

use App\Entity\Team;
use App\Entity\User;
use App\Form\Type\ClientRequesCommentType;
use App\Form\Type\ClientRequestInternalNoteType;
use App\Form\Type\ClientRequestInternalType;
use App\Form\Type\ClientRequestType;
use App\Form\Type\ClientRequestViewType;
use App\Repository\ClientRequestRepository;
Expand All @@ -24,13 +24,10 @@

class ClientRequestController extends BaseController
{


public function __construct(
private readonly TranslatorInterface $translator,
private EntityManagerInterface $em,
)
{
) {
}

#[Route(path: '/client-requests', name: 'client_requests')]
Expand Down Expand Up @@ -83,8 +80,10 @@ public function clientRequestComment(
ClientRequestRepository $clientRequestRepository,
): Response
{
/** @var User $user */
$user = $this->getUser();
$clientRequest = $clientRequestRepository->find($request->get('clientRequest'));
$team = $currentTeamService->getCurrentTeam($this->getUser());
$team = $currentTeamService->getCurrentTeam($user);
if ($securityService->teamDataCheck($clientRequest, $team) === false) {
return $this->redirectToRoute('client_requests');
}
Expand All @@ -93,7 +92,7 @@ public function clientRequestComment(
$form->handleRequest($request);

if ($form->isSubmitted() && $form->isValid()) {
$clientRequestService->newComment($clientRequest, $form->getData()['comment'], $team->getKeycloakGroup() . ' > ' . $this->getUser()->getUsername(), 1);
$clientRequestService->newComment($clientRequest, $form->getData()['comment'], $team->getKeycloakGroup() . ' > ' . $user->getUsername(), 1);
$this->addSuccessMessage($this->translator->trans(id: 'save.comment', domain: 'general'));
}

Expand All @@ -110,11 +109,13 @@ public function closeRequest(
): Response
{
$clientRequest = $clientRequestRepository->find($request->get('id'));

/** @var User $user */
$user = $this->getUser();
$team = $currentTeamService->getCurrentTeam($user);

if ($securityService->teamDataCheck($clientRequest, $team) && $securityService->adminCheck($user, $team)) {
$clientRequestService->closeRequest($clientRequest, $this->getUser());
$clientRequestService->closeRequest($clientRequest, $user);

return $this->redirectToRoute('client_requests_show', ['id' => $clientRequest->getId()]);
}
Expand All @@ -133,6 +134,7 @@ public function editClientRequests(
ClientRequestRepository $clientRequestRepository,
)
{
/** @var User $user */
$user = $this->getUser();
$team = $currentTeamService->getCurrentTeam($user);
$clientRequest = $clientRequestRepository->find($request->get('id'));
Expand Down Expand Up @@ -161,7 +163,7 @@ public function editClientRequests(
$this->em->persist($clientRequest);
$this->em->flush();

$clientRequestService->newComment($clientRequest, $content, $team->getKeycloakGroup() . ' > ' . $this->getUser()->getUsername(), 1);
$clientRequestService->newComment($clientRequest, $content, $team->getKeycloakGroup() . ' > ' . $user->getUsername(), 1);

$this->addSuccessMessage($this->translator->trans(id: 'save.changeSuccessful', domain: 'general'));
return $this->redirectToRoute('client_requests_show', ['id' => $clientRequest->getId()]);
Expand Down
Loading