From 8fbbc27f090a40deaf7a5f3fcf3145c694804c27 Mon Sep 17 00:00:00 2001 From: Art4 Date: Mon, 29 Jan 2024 22:58:53 +0100 Subject: [PATCH 01/10] install phpstan --- .gitignore | 5 +++- composer.json | 2 ++ composer.lock | 66 +++++++++++++++++++++++++++++++++++++++++++++-- phpstan.dist.neon | 8 ++++++ symfony.lock | 12 +++++++++ 5 files changed, 90 insertions(+), 3 deletions(-) create mode 100644 phpstan.dist.neon diff --git a/.gitignore b/.gitignore index 08cf2d70..0d871ae7 100644 --- a/.gitignore +++ b/.gitignore @@ -55,4 +55,7 @@ yarn-error.log docker.conf /documentation_jitsi_admin/node_modules/ -/secretStorage/.Halite* \ No newline at end of file +/secretStorage/.Halite* +###> phpstan/phpstan ### +phpstan.neon +###< phpstan/phpstan ### diff --git a/composer.json b/composer.json index c017668e..5e351bcd 100644 --- a/composer.json +++ b/composer.json @@ -58,6 +58,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.*", @@ -100,6 +101,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" ], diff --git a/composer.lock b/composer.lock index b4a7f090..8ae03eae 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "447dc6250d4e3163dc97da0c080908b5", + "content-hash": "6c3c4b68aa6d5b7c02d3521d52211224", "packages": [ { "name": "composer/package-versions-deprecated", @@ -10704,6 +10704,68 @@ }, "time": "2022-02-21T01:04:05+00:00" }, + { + "name": "phpstan/phpstan", + "version": "1.10.57", + "source": { + "type": "git", + "url": "https://github.com/phpstan/phpstan.git", + "reference": "1627b1d03446904aaa77593f370c5201d2ecc34e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/1627b1d03446904aaa77593f370c5201d2ecc34e", + "reference": "1627b1d03446904aaa77593f370c5201d2ecc34e", + "shasum": "" + }, + "require": { + "php": "^7.2|^8.0" + }, + "conflict": { + "phpstan/phpstan-shim": "*" + }, + "bin": [ + "phpstan", + "phpstan.phar" + ], + "type": "library", + "autoload": { + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "PHPStan - PHP Static Analysis Tool", + "keywords": [ + "dev", + "static analysis" + ], + "support": { + "docs": "https://phpstan.org/user-guide/getting-started", + "forum": "https://github.com/phpstan/phpstan/discussions", + "issues": "https://github.com/phpstan/phpstan/issues", + "security": "https://github.com/phpstan/phpstan/security/policy", + "source": "https://github.com/phpstan/phpstan-src" + }, + "funding": [ + { + "url": "https://github.com/ondrejmirtes", + "type": "github" + }, + { + "url": "https://github.com/phpstan", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/phpstan/phpstan", + "type": "tidelift" + } + ], + "time": "2024-01-24T11:51:34+00:00" + }, { "name": "phpunit/php-code-coverage", "version": "9.2.26", @@ -12622,5 +12684,5 @@ "ext-iconv": "*" }, "platform-dev": [], - "plugin-api-version": "2.2.0" + "plugin-api-version": "2.1.0" } diff --git a/phpstan.dist.neon b/phpstan.dist.neon new file mode 100644 index 00000000..73adfad9 --- /dev/null +++ b/phpstan.dist.neon @@ -0,0 +1,8 @@ +parameters: + level: 0 + paths: + - bin/ + - config/ + - public/ + - src/ + - tests/ diff --git a/symfony.lock b/symfony.lock index 467b8ba3..3de247f1 100644 --- a/symfony.lock +++ b/symfony.lock @@ -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" }, From 57071bbeb87dc59625b88701df3d1b5b8fd24238 Mon Sep 17 00:00:00 2001 From: Art4 Date: Mon, 29 Jan 2024 23:05:16 +0100 Subject: [PATCH 02/10] Fix error with missing user object --- src/Controller/KursController.php | 6 +++--- src/Service/SecurityService.php | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Controller/KursController.php b/src/Controller/KursController.php index f2535fff..cb5c87f5 100644 --- a/src/Controller/KursController.php +++ b/src/Controller/KursController.php @@ -90,7 +90,7 @@ public function editKurs( $team = $currentTeamService->getTeamFromSession($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'); } @@ -136,7 +136,7 @@ public function kursAnmelden( $team = $currentTeamService->getTeamFromSession($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'); } @@ -171,7 +171,7 @@ public function kursDeaktivieren( $team = $currentTeamService->getTeamFromSession($user); $kurs = $academyLessonRepository->find($request->get('id')); - if (!$securityService->teamArrayDataCheck($kurs, $team)) { + if (!$securityService->teamArrayDataCheck($kurs, $team, $user)) { return $this->redirectToRoute('akademie_admin'); } diff --git a/src/Service/SecurityService.php b/src/Service/SecurityService.php index d379fb16..9c573001 100644 --- a/src/Service/SecurityService.php +++ b/src/Service/SecurityService.php @@ -66,7 +66,7 @@ public function superAdminCheck(User $user): bool return false; } - public function teamArrayDataCheck($data, $team): bool + public function teamArrayDataCheck($data, $team, $user): bool { //Sicherheitsfunktion, dass ein Team vorhanden ist if ($team === null) { @@ -85,7 +85,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; } From 226e4cc9d1a02e74c2748762893915c034788dd5 Mon Sep 17 00:00:00 2001 From: Art4 Date: Mon, 29 Jan 2024 23:06:05 +0100 Subject: [PATCH 03/10] Use Entity instead of Proxy --- src/Service/TeamService.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Service/TeamService.php b/src/Service/TeamService.php index 9a96937b..9a62de2c 100644 --- a/src/Service/TeamService.php +++ b/src/Service/TeamService.php @@ -10,6 +10,7 @@ use App\Entity\AuditTomZiele; +use App\Entity\DatenweitergabeGrundlagen; use App\Entity\DatenweitergabeStand; use App\Entity\Produkte; use App\Entity\Team; @@ -19,7 +20,6 @@ use App\Entity\VVTRisiken; use App\Entity\VVTStatus; use Doctrine\ORM\EntityManagerInterface; -use Proxies\__CG__\App\Entity\DatenweitergabeGrundlagen; use Symfony\Component\Routing\Generator\UrlGeneratorInterface; use Symfony\Contracts\Translation\TranslatorInterface; From 337efd31fef8f9ce5c6dddd99fe751f2ace85d66 Mon Sep 17 00:00:00 2001 From: Art4 Date: Mon, 29 Jan 2024 23:06:18 +0100 Subject: [PATCH 04/10] Add missing return statement --- src/Service/VVTDatenkategorieService.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Service/VVTDatenkategorieService.php b/src/Service/VVTDatenkategorieService.php index 08e83cee..ad67e561 100644 --- a/src/Service/VVTDatenkategorieService.php +++ b/src/Service/VVTDatenkategorieService.php @@ -87,6 +87,7 @@ function findLatestKategorie(VVTDatenkategorie $VVTDatenkategorie): ?VVTDatenkat $act = $next; } + return null; } function newVVTDatenkategorie(Team $team, User $user) From 4f0f88a5f561d1d9dd518020bff5e02c18d7dc91 Mon Sep 17 00:00:00 2001 From: Art4 Date: Mon, 29 Jan 2024 23:12:05 +0100 Subject: [PATCH 05/10] Add undefined property $em; --- src/Service/AkademieService.php | 2 +- src/Service/AssignService.php | 2 +- src/Service/CronService.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Service/AkademieService.php b/src/Service/AkademieService.php index e406ea10..f628a2c0 100644 --- a/src/Service/AkademieService.php +++ b/src/Service/AkademieService.php @@ -18,7 +18,7 @@ class AkademieService { - + private EntityManagerInterface $em; private CurrentTeamService $currentTeamService; private NotificationService $notificationService; private Environment $twig; diff --git a/src/Service/AssignService.php b/src/Service/AssignService.php index 38302b50..d9d670bc 100644 --- a/src/Service/AssignService.php +++ b/src/Service/AssignService.php @@ -29,7 +29,7 @@ class AssignService { - + private EntityManagerInterface $em; private FormFactoryInterface $formBuilder; private NotificationService $notificationService; private Environment $twig; diff --git a/src/Service/CronService.php b/src/Service/CronService.php index d29e1962..96df0633 100644 --- a/src/Service/CronService.php +++ b/src/Service/CronService.php @@ -71,7 +71,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)]); From c39949437878f6ac1d676be10ebe09782b616f76 Mon Sep 17 00:00:00 2001 From: Art4 Date: Mon, 29 Jan 2024 23:30:47 +0100 Subject: [PATCH 06/10] Fix multiple errors --- src/Controller/FormsController.php | 2 +- src/Controller/LoginController.php | 1 + src/Controller/SoftwareController.php | 2 +- src/Entity/VVT.php | 7 +++++-- src/Repository/VVTDatenkategorieRepository.php | 1 - 5 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/Controller/FormsController.php b/src/Controller/FormsController.php index a080d569..8c2bfbe1 100644 --- a/src/Controller/FormsController.php +++ b/src/Controller/FormsController.php @@ -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', diff --git a/src/Controller/LoginController.php b/src/Controller/LoginController.php index 174642ba..a0ddeb1b 100644 --- a/src/Controller/LoginController.php +++ b/src/Controller/LoginController.php @@ -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; diff --git a/src/Controller/SoftwareController.php b/src/Controller/SoftwareController.php index d7d29237..67339f40 100644 --- a/src/Controller/SoftwareController.php +++ b/src/Controller/SoftwareController.php @@ -189,7 +189,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', [ diff --git a/src/Entity/VVT.php b/src/Entity/VVT.php index c741f382..ae34392d 100644 --- a/src/Entity/VVT.php +++ b/src/Entity/VVT.php @@ -168,7 +168,7 @@ class VVT private $source; /** - * @Encrypted() + * @Encrypted() */ #[ORM\Column(type: 'text', nullable: true)] private $loeschfrist; @@ -520,6 +520,8 @@ public function getActivDsfa() /** * @return Collection|VVTDsfa[] */ + // TODO: Move method into App\Repository\VVTRepository + /* public function getLatestDsfa() { return $this->createQueryBuilder('d') @@ -527,6 +529,7 @@ public function getLatestDsfa() ->getQuery() ->getResult(); } + */ public function getUser(): ?User { @@ -832,7 +835,7 @@ public function setLoeschfrist(?string $loeschfrist): self $this->loeschfrist = $loeschfrist; return $this; - } + } public function __clone() { diff --git a/src/Repository/VVTDatenkategorieRepository.php b/src/Repository/VVTDatenkategorieRepository.php index 45ed62ef..73cb05da 100644 --- a/src/Repository/VVTDatenkategorieRepository.php +++ b/src/Repository/VVTDatenkategorieRepository.php @@ -11,7 +11,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) From 38464f09828aa7e47d94d27191d5c6d29e043751 Mon Sep 17 00:00:00 2001 From: Art4 Date: Mon, 29 Jan 2024 23:40:09 +0100 Subject: [PATCH 07/10] Fix more phpstan errors --- src/Repository/FileRepository.php | 2 +- src/Security/KeycloakAuthenticator.php | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Repository/FileRepository.php b/src/Repository/FileRepository.php index d76fa060..3d62fd7d 100644 --- a/src/Repository/FileRepository.php +++ b/src/Repository/FileRepository.php @@ -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) diff --git a/src/Security/KeycloakAuthenticator.php b/src/Security/KeycloakAuthenticator.php index d81f78d4..5257004c 100644 --- a/src/Security/KeycloakAuthenticator.php +++ b/src/Security/KeycloakAuthenticator.php @@ -123,6 +123,7 @@ 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 { @@ -130,6 +131,8 @@ private function getEmailForKeycloakUser(ResourceOwnerInterface $keycloakUser): } catch (\Exception $e) { } } + + return ''; } private function getRolesForKeycloakUser(ResourceOwnerInterface $keycloakUser): array From b691aeeb86877ffbcb16aeb2206916cb93a57399 Mon Sep 17 00:00:00 2001 From: Art4 Date: Tue, 30 Jan 2024 00:03:05 +0100 Subject: [PATCH 08/10] set arguments for CronService via services.yaml --- config/services.yaml | 5 +++++ src/Service/CronService.php | 6 ++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/config/services.yaml b/config/services.yaml index 5a33a848..a3b4f331 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -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" ] diff --git a/src/Service/CronService.php b/src/Service/CronService.php index 96df0633..202340d7 100644 --- a/src/Service/CronService.php +++ b/src/Service/CronService.php @@ -26,6 +26,8 @@ public function __construct( private TranslatorInterface $translator, private NotificationService $notificationService, private Environment $environment, + private string $cronIPAdress, + private string $cronToken, ) { } @@ -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, @@ -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'), From 2a76114e9344fc57b8953e5cc7f4fd0ba524638e Mon Sep 17 00:00:00 2001 From: Art4 Date: Tue, 30 Jan 2024 10:43:23 +0100 Subject: [PATCH 09/10] Fix services.yaml --- config/services.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/services.yaml b/config/services.yaml index a3b4f331..14a503ab 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -38,8 +38,8 @@ services: App\Service\CronService: arguments: - $cronIPAdress: '%cronIPAdress%': - $cronToken: '%cronToken%': + $cronIPAdress: '%cronIPAdress%' + $cronToken: '%cronToken%' app.menu.service: class: App\Service\MenuService From 462ee2de40672eacb4e14b4214cb9d53b2e6e716 Mon Sep 17 00:00:00 2001 From: Art4 Date: Wed, 28 Feb 2024 22:21:44 +0100 Subject: [PATCH 10/10] Fix 2 more errors --- src/Controller/TeamController.php | 3 ++- src/Entity/Preset.php | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Controller/TeamController.php b/src/Controller/TeamController.php index 116d67ee..53bd677a 100644 --- a/src/Controller/TeamController.php +++ b/src/Controller/TeamController.php @@ -123,6 +123,7 @@ public function create( Request $request, SecurityService $securityService, TeamRepository $teamRepository, + CurrentTeamService $currentTeamService, ): Response { $user = $this->getUser(); @@ -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'); } diff --git a/src/Entity/Preset.php b/src/Entity/Preset.php index 1f386a31..22365dee 100644 --- a/src/Entity/Preset.php +++ b/src/Entity/Preset.php @@ -12,6 +12,8 @@ abstract class Preset #[ORM\Column(type: 'boolean')] protected $inherited = false; + protected $ignoredInTeams; + public function isInherited(): bool { return $this->inherited;