Skip to content

Commit

Permalink
Merge pull request #243 from Art4/phpstan
Browse files Browse the repository at this point in the history
Add PHPStan and fix 61 errors
  • Loading branch information
holema authored Mar 21, 2024
2 parents 4665c33 + 462ee2d commit 1fc2e49
Show file tree
Hide file tree
Showing 22 changed files with 123 additions and 19 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,7 @@ yarn-error.log
docker.conf

/documentation_jitsi_admin/node_modules/
/secretStorage/.Halite*
/secretStorage/.Halite*
###> phpstan/phpstan ###
phpstan.neon
###< phpstan/phpstan ###
2 changes: 2 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"vich/uploader-bundle": "^1.13"
},
"require-dev": {
"phpstan/phpstan": "^1.10",
"phpunit/phpunit": "^9.5",
"symfony/browser-kit": "6.2.*",
"symfony/css-selector": "6.2.*",
Expand Down Expand Up @@ -102,6 +103,7 @@
"cache:clear": "symfony-cmd",
"assets:install %PUBLIC_DIR%": "symfony-cmd"
},
"phpstan": "php vendor/bin/phpstan analyze -c phpstan.dist.neon",
"post-install-cmd": [
"@auto-scripts"
],
Expand Down
66 changes: 64 additions & 2 deletions composer.lock

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

5 changes: 5 additions & 0 deletions config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ services:
# add more service definitions when explicit configuration is needed
# please note that last definitions always *replace* previous ones

App\Service\CronService:
arguments:
$cronIPAdress: '%cronIPAdress%'
$cronToken: '%cronToken%'

app.menu.service:
class: App\Service\MenuService
arguments: [ "@knp_menu.factory" ]
Expand Down
8 changes: 8 additions & 0 deletions phpstan.dist.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
parameters:
level: 0
paths:
- bin/
- config/
- public/
- src/
- tests/
2 changes: 1 addition & 1 deletion src/Controller/FormsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ public function editFormulare(
$this->em->persist($newForms);
$this->em->persist($forms);
$this->em->flush();
$this->addSuccess($this->translator->trans(id: 'save.successful', domain: 'general'));
$this->addSuccessMessage($this->translator->trans(id: 'save.successful', domain: 'general'));

return $this->redirectToRoute(
'forms_edit',
Expand Down
6 changes: 3 additions & 3 deletions src/Controller/KursController.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public function editKurs(
$team = $currentTeamService->getCurrentTeam($user);
$kurs = $academyLessonRepository->find($request->get('id'));

if ($securityService->teamArrayDataCheck($kurs, $team) === false) {
if ($securityService->teamArrayDataCheck($kurs, $team, $user) === false) {
return $this->redirectToRoute('akademie_admin');
}

Expand Down Expand Up @@ -136,7 +136,7 @@ public function kursAnmelden(
$team = $currentTeamService->getCurrentTeam($user);
$kurs = $academyLessonRepository->find($request->get('id'));

if ($securityService->teamArrayDataCheck($kurs, $team) === false) {
if ($securityService->teamArrayDataCheck($kurs, $team, $user) === false) {
return $this->redirectToRoute('akademie_admin');
}

Expand Down Expand Up @@ -171,7 +171,7 @@ public function kursDeaktivieren(
$team = $currentTeamService->getCurrentTeam($user);
$kurs = $academyLessonRepository->find($request->get('id'));

if (!$securityService->teamArrayDataCheck($kurs, $team)) {
if (!$securityService->teamArrayDataCheck($kurs, $team, $user)) {
return $this->redirectToRoute('akademie_admin');
}

Expand Down
1 change: 1 addition & 0 deletions src/Controller/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

use KnpU\OAuth2ClientBundle\Client\ClientRegistry;
use KnpU\OAuth2ClientBundle\Client\Provider\Auth0Client;
use League\OAuth2\Client\Provider\Exception\IdentityProviderException;
use Stevenmaguire\OAuth2\Client\Provider\Keycloak;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/SoftwareController.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ public function deleteConfig(
if ($securityService->teamDataCheck($config->getSoftware(), $team) && $securityService->adminCheck($user, $team)) {
$this->em->remove($config);
$this->em->flush();
$this->addSuccess($this->translator->trans(id: 'config.delete', domain: 'software'));
$this->addSuccessMessage($this->translator->trans(id: 'config.delete', domain: 'software'));
return $this->redirectToRoute(
'software_edit',
[
Expand Down
3 changes: 2 additions & 1 deletion src/Controller/TeamController.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ public function create(
Request $request,
SecurityService $securityService,
TeamRepository $teamRepository,
CurrentTeamService $currentTeamService,
): Response
{
$user = $this->getUser();
Expand Down Expand Up @@ -157,7 +158,7 @@ public function create(
$this->addSuccessMessage($this->translator->trans(id: 'team.created', domain: 'team'));

if ($_ENV['APP_DEMO']) {
$teamService->switchToTeam((string) $nTeam->getId());
$currentTeamService->switchToTeam((string) $nTeam->getId());
return $this->redirectToRoute('dashboard');
}

Expand Down
2 changes: 2 additions & 0 deletions src/Entity/Preset.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ abstract class Preset
#[ORM\Column(type: 'boolean')]
protected $inherited = false;

protected $ignoredInTeams;

public function isInherited(): bool
{
return $this->inherited;
Expand Down
3 changes: 3 additions & 0 deletions src/Entity/VVT.php
Original file line number Diff line number Diff line change
Expand Up @@ -524,13 +524,16 @@ public function getActivDsfa()
/**
* @return Collection|VVTDsfa[]
*/
// TODO: Move method into App\Repository\VVTRepository
/*
public function getLatestDsfa()
{
return $this->createQueryBuilder('d')
->orderBy('d.createdAt', 'DESC')
->getQuery()
->getResult();
}
*/

public function getUser(): ?User
{
Expand Down
2 changes: 1 addition & 1 deletion src/Repository/FileRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace App\Repository;

use App\Entity\File;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
use Symfony\Component\HttpFoundation\File\File;

/**
* @method File|null find($id, $lockMode = null, $lockVersion = null)
Expand Down
1 change: 0 additions & 1 deletion src/Repository/VVTDatenkategorieRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use App\Entity\VVTDatenkategorie;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
use function Doctrine\ORM\QueryBuilder;

/**
* @method VVTDatenkategorie|null find($id, $lockMode = null, $lockVersion = null)
Expand Down
3 changes: 3 additions & 0 deletions src/Security/KeycloakAuthenticator.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,16 @@ private function getTeamsFromKeycloakGroups(ResourceOwnerInterface $keycloakUser

private function getEmailForKeycloakUser(ResourceOwnerInterface $keycloakUser): string {
try {
// FIXME: ResourceOwnerInterface cannot have method getEmail()
return $keycloakUser->getEmail();
} catch (\Exception $e) {
try {
return $keycloakUser->toArray()['preferred_username'];
} catch (\Exception $e) {
}
}

return '';
}

private function getRolesForKeycloakUser(ResourceOwnerInterface $keycloakUser): array
Expand Down
2 changes: 1 addition & 1 deletion src/Service/AkademieService.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

class AkademieService
{

private EntityManagerInterface $em;
private CurrentTeamService $currentTeamService;
private NotificationService $notificationService;
private Environment $twig;
Expand Down
2 changes: 1 addition & 1 deletion src/Service/AssignService.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

class AssignService
{

private EntityManagerInterface $em;
private FormFactoryInterface $formBuilder;
private NotificationService $notificationService;
private Environment $twig;
Expand Down
8 changes: 5 additions & 3 deletions src/Service/CronService.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public function __construct(
private TranslatorInterface $translator,
private NotificationService $notificationService,
private Environment $environment,
private string $cronIPAdress,
private string $cronToken,
)
{
}
Expand All @@ -34,7 +36,7 @@ function check($request)
{
$message = false;

if ($request->get('token') !== $this->getParameter('cronToken')) {
if ($request->get('token') !== $this->cronToken) {
$message =
[
'error' => true,
Expand All @@ -45,7 +47,7 @@ function check($request)
$this->logger->error($message['hinweis'], $message);
}

if ($this->getParameter('cronIPAdress') !== $request->getClientIp()) {
if ($this->cronIPAdress !== $request->getClientIp()) {
$message = [
'error' => true,
'hinweis' => $this->translator->trans(id: 'cron.ip.unauthorized', domain: 'service'),
Expand All @@ -71,7 +73,7 @@ public function sendEmailsForAcademy()
if (!$buchung->getInvitation()) {
$content = $this->environment->render('email/neuerKurs.html.twig', ['buchung' => $buchung, 'team' => $buchung->getUser()->getTeams()->get(0)]);
$buchung->setInvitation(true);
$em->persist($buchung);
$this->em->persist($buchung);
++$countNeu;
} else {
$content = $this->environment->render('email/errinnerungKurs.html.twig', ['buchung' => $buchung, 'team' => $buchung->getUser()->getTeams()->get(0)]);
Expand Down
4 changes: 2 additions & 2 deletions src/Service/SecurityService.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public function superAdminCheck(User $user): bool
return false;
}

public function teamArrayDataCheck($data, $team): bool
public function teamArrayDataCheck($data, $team, $user): bool
{
if (!$this->teamCheck($team)) {
return false;
Expand All @@ -96,7 +96,7 @@ public function teamArrayDataCheck($data, $team): bool
'typ' => 'LOGIN',
'error' => true,
'hinweis' => $this->translator->trans(id: 'error.userNotFoundInArray', domain: 'general'),
'user' => $this->getUser()->getUsername()];
'user' => $user->getUsername()];
$this->logger->error($message['typ'], $message);
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Service/TeamService.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@


use App\Entity\AuditTomZiele;
use App\Entity\DatenweitergabeGrundlagen;
use App\Entity\DatenweitergabeStand;
use App\Entity\Produkte;
use App\Entity\Team;
Expand All @@ -27,7 +28,6 @@
use App\Repository\VVTRisikenRepository;
use App\Repository\VVTStatusRepository;
use Doctrine\ORM\EntityManagerInterface;
use Proxies\__CG__\App\Entity\DatenweitergabeGrundlagen;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Contracts\Translation\TranslatorInterface;

Expand Down
1 change: 1 addition & 0 deletions src/Service/VVTDatenkategorieService.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ function findLatestKategorie(VVTDatenkategorie $VVTDatenkategorie): ?VVTDatenkat
$act = $next;
}

return null;
}

function newVVTDatenkategorie(Team $team, User $user)
Expand Down
12 changes: 12 additions & 0 deletions symfony.lock
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,18 @@
"phpstan/phpdoc-parser": {
"version": "1.2.0"
},
"phpstan/phpstan": {
"version": "1.10",
"recipe": {
"repo": "github.com/symfony/recipes-contrib",
"branch": "main",
"version": "1.0",
"ref": "5e490cc197fb6bb1ae22e5abbc531ddc633b6767"
},
"files": [
"phpstan.dist.neon"
]
},
"phpunit/php-code-coverage": {
"version": "9.2.10"
},
Expand Down

0 comments on commit 1fc2e49

Please sign in to comment.