From dcd889d16a423118f720aa1a71bbd2240fb54a4b Mon Sep 17 00:00:00 2001 From: Sebastian Date: Wed, 11 Sep 2024 13:37:20 +0200 Subject: [PATCH] lint --- src/Command/ImportGamificationCommand.php | 9 ++++---- src/Command/PseudonymizeLoginCommand.php | 7 +++--- src/Controller/Api/GamificationController.php | 16 ++++++-------- .../GamificationPersonProfileMapper.php | 4 ++-- src/DTO/Model/Gamification/GoalDTO.php | 1 - src/DTO/Model/Gamification/LevelDTO.php | 1 - .../Gamification/PersonGamificationDTO.php | 1 - .../GamificationPersonProfile.php | 2 +- src/Entity/Gamification/Level.php | 2 -- .../Gamification/LoginRepository.php | 5 +++-- .../Security/PermissionRepository.php | 2 -- src/Service/Gamification/LoginService.php | 9 ++++---- .../PersonGamificationService.php | 22 +++++++++++-------- .../Gamification/QuapGamificationService.php | 6 ++--- 14 files changed, 43 insertions(+), 44 deletions(-) diff --git a/src/Command/ImportGamificationCommand.php b/src/Command/ImportGamificationCommand.php index 3692fc9..a4c488e 100644 --- a/src/Command/ImportGamificationCommand.php +++ b/src/Command/ImportGamificationCommand.php @@ -14,7 +14,6 @@ class ImportGamificationCommand extends StatisticsCommand { - /** @var EntityManagerInterface $em */ private EntityManagerInterface $em; @@ -45,7 +44,7 @@ protected function configure() protected function execute(InputInterface $input, OutputInterface $output): int { - $start = microtime( true); + $start = microtime(true); $json = json_decode(file_get_contents($this->pathToJson), true); $this->em->getConnection()->executeQuery('DELETE FROM gamification_person_profile'); @@ -68,7 +67,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int return 0; } - protected function importLevels(array $jsonLevels, OutputInterface $output) { + protected function importLevels(array $jsonLevels, OutputInterface $output) + { foreach ($jsonLevels as $jsonLevel) { $level = $this->levelRepository->findOneBy(["key" => $jsonLevel["key"]]); if (is_null($level)) { @@ -90,7 +90,8 @@ protected function importLevels(array $jsonLevels, OutputInterface $output) { $this->em->flush(); } - protected function importGoals(array $jsonGoals, OutputInterface $output) { + protected function importGoals(array $jsonGoals, OutputInterface $output) + { foreach ($jsonGoals as $jsonGoal) { $goal = $this->goalRepository->findOneBy(['key' => $jsonGoal['key']]); if (is_null($goal)) { diff --git a/src/Command/PseudonymizeLoginCommand.php b/src/Command/PseudonymizeLoginCommand.php index 0e2e0be..86294ed 100644 --- a/src/Command/PseudonymizeLoginCommand.php +++ b/src/Command/PseudonymizeLoginCommand.php @@ -13,7 +13,6 @@ class PseudonymizeLoginCommand extends StatisticsCommand { - private LoginRepository $loginRepository; private float $duration; @@ -34,8 +33,10 @@ protected function configure() protected function execute(InputInterface $input, OutputInterface $output): int { - $start = microtime( true); - $pseudonymizedLogins = $this->loginRepository->pseudonymizeAllOlderThan18Months(function ($personId) { return hash('sha256', $personId);}); // sha256 is mostly collision free and currently irreversible, sufficient for our purposes. + $start = microtime(true); + $pseudonymizedLogins = $this->loginRepository->pseudonymizeAllOlderThan18Months(function ($personId) { + return hash('sha256', $personId); + }); // sha256 is mostly collision free and currently irreversible, sufficient for our purposes. $log = $input->getOption('log'); if ($log) { $output->writeln('Following Logins (id) have been pseudonymized:'); diff --git a/src/Controller/Api/GamificationController.php b/src/Controller/Api/GamificationController.php index 4153451..c8b87be 100644 --- a/src/Controller/Api/GamificationController.php +++ b/src/Controller/Api/GamificationController.php @@ -43,8 +43,7 @@ public function postGroupChange( public function usedCardLayer( Request $request, PersonGamificationService $personGamificationService - ) - { + ) { $personGamificationService->genericGoalProgress($this->getUser(), 'card'); return new Response('', 200); } @@ -52,8 +51,7 @@ public function usedCardLayer( public function usedDataFilter( Request $request, PersonGamificationService $personGamificationService - ) - { + ) { $personGamificationService->genericGoalProgress($this->getUser(), 'data'); return new Response('', 200); } @@ -61,15 +59,15 @@ public function usedDataFilter( public function usedTimeFilter( Request $request, PersonGamificationService $personGamificationService - ) - { + ) { $personGamificationService->genericGoalProgress($this->getUser(), 'time'); return new Response('', 200); } - public function getUserProfile(Request $request, - PersonGamificationService $personGamificationService) - { + public function getUserProfile( + Request $request, + PersonGamificationService $personGamificationService + ) { $dto = $personGamificationService->getPersonGamificationDTO($this->getUser(), $request->getLocale()); return $this->json($dto); } diff --git a/src/DTO/Mapper/GamificationPersonProfileMapper.php b/src/DTO/Mapper/GamificationPersonProfileMapper.php index 929fe46..9651f10 100644 --- a/src/DTO/Mapper/GamificationPersonProfileMapper.php +++ b/src/DTO/Mapper/GamificationPersonProfileMapper.php @@ -9,7 +9,6 @@ class GamificationPersonProfileMapper { - public static function createFromEntity(GamificationPersonProfile $profile, string $locale): PersonGamificationDTO { $dto = new PersonGamificationDTO(); @@ -27,7 +26,8 @@ public static function createFromEntity(GamificationPersonProfile $profile, stri return $dto; } - public static function checkLevelUp(GamificationPersonProfile $profile) { + public static function checkLevelUp(GamificationPersonProfile $profile) + { $levelUps = $profile->getPerson()->getLevelUps(); if (count($levelUps) > 0) { return true; diff --git a/src/DTO/Model/Gamification/GoalDTO.php b/src/DTO/Model/Gamification/GoalDTO.php index bc91c4c..ae01e89 100644 --- a/src/DTO/Model/Gamification/GoalDTO.php +++ b/src/DTO/Model/Gamification/GoalDTO.php @@ -106,5 +106,4 @@ public function setRequired(bool $required): void { $this->required = $required; } - } diff --git a/src/DTO/Model/Gamification/LevelDTO.php b/src/DTO/Model/Gamification/LevelDTO.php index 9fbcdba..97aa26a 100644 --- a/src/DTO/Model/Gamification/LevelDTO.php +++ b/src/DTO/Model/Gamification/LevelDTO.php @@ -90,5 +90,4 @@ public function setGoals(array $goals): void { $this->goals = $goals; } - } diff --git a/src/DTO/Model/Gamification/PersonGamificationDTO.php b/src/DTO/Model/Gamification/PersonGamificationDTO.php index 180d3fe..042b0e0 100644 --- a/src/DTO/Model/Gamification/PersonGamificationDTO.php +++ b/src/DTO/Model/Gamification/PersonGamificationDTO.php @@ -90,5 +90,4 @@ public function setLevels(array $levels): void { $this->levels = $levels; } - } diff --git a/src/Entity/Gamification/GamificationPersonProfile.php b/src/Entity/Gamification/GamificationPersonProfile.php index 3d1fb83..b50aeb9 100644 --- a/src/Entity/Gamification/GamificationPersonProfile.php +++ b/src/Entity/Gamification/GamificationPersonProfile.php @@ -74,7 +74,7 @@ class GamificationPersonProfile * @ORM\Column(type="boolean") */ private $el_improved; - + public function getId(): ?int { diff --git a/src/Entity/Gamification/Level.php b/src/Entity/Gamification/Level.php index 308f09a..c53a1af 100644 --- a/src/Entity/Gamification/Level.php +++ b/src/Entity/Gamification/Level.php @@ -197,6 +197,4 @@ public function setKey($key): void { $this->key = $key; } - - } diff --git a/src/Repository/Gamification/LoginRepository.php b/src/Repository/Gamification/LoginRepository.php index 7bf2103..f3f33e7 100644 --- a/src/Repository/Gamification/LoginRepository.php +++ b/src/Repository/Gamification/LoginRepository.php @@ -25,9 +25,10 @@ public function __construct(ManagerRegistry $registry) parent::__construct($registry, Login::class); } - public function findAllActiveBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) { + public function findAllActiveBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) + { $criteria['hashed_id'] = null; - return $this->findBy($criteria,$orderBy, $limit, $offset); + return $this->findBy($criteria, $orderBy, $limit, $offset); } /** diff --git a/src/Repository/Security/PermissionRepository.php b/src/Repository/Security/PermissionRepository.php index 83a19a6..eff4d50 100644 --- a/src/Repository/Security/PermissionRepository.php +++ b/src/Repository/Security/PermissionRepository.php @@ -196,6 +196,4 @@ public function endAllOpenPermissions(): void ] ); } - - } diff --git a/src/Service/Gamification/LoginService.php b/src/Service/Gamification/LoginService.php index 6ffd31a..2040d5e 100644 --- a/src/Service/Gamification/LoginService.php +++ b/src/Service/Gamification/LoginService.php @@ -26,15 +26,15 @@ public function __construct( LoginRepository $loginRepository, GroupRepository $groupRepository, PermissionRepository $permissionRepository - ) - { + ) { $this->personRepository = $personRepository; $this->loginRepository = $loginRepository; $this->groupRepository = $groupRepository; $this->permissionRepository = $permissionRepository; } - public function logByUserDTOForLogin(PbsUserDTO $userDTO):Login { + public function logByUserDTOForLogin(PbsUserDTO $userDTO): Login + { $login = new Login(); $activeGroupDTO = $userDTO->getGroups()[0]; // Group 0 is the active group on Login. @@ -63,7 +63,8 @@ public function logByUserDTOForLogin(PbsUserDTO $userDTO):Login { return $login; } - public function logByPersonAndGroup(PbsUserDTO $userDTO, Group $group) { + public function logByPersonAndGroup(PbsUserDTO $userDTO, Group $group) + { $login = new Login(); $person = $this->personRepository->find($userDTO->getId()); $role = $this->permissionRepository->findHighestById($group, $person->getId()); diff --git a/src/Service/Gamification/PersonGamificationService.php b/src/Service/Gamification/PersonGamificationService.php index 7b6a3f4..bd2838c 100644 --- a/src/Service/Gamification/PersonGamificationService.php +++ b/src/Service/Gamification/PersonGamificationService.php @@ -43,8 +43,7 @@ public function __construct( PersonRepository $personRepository, EntityManagerInterface $em, LevelUpLogRepository $levelUpLogRepository - ) - { + ) { $this->loginRepository = $loginRepository; $this->levelRepository = $levelRepository; $this->personRepository = $personRepository; @@ -53,7 +52,8 @@ public function __construct( $this->levelUpLogRepository = $levelUpLogRepository; } - public function reset(PbsUserDTO $pbsUserDTO) { + public function reset(PbsUserDTO $pbsUserDTO) + { $person = $this->personRepository->find($pbsUserDTO->getId()); $pgp = $this->getPersonGamification($person); $this->personGoalRepository->remove($pgp); @@ -62,7 +62,7 @@ public function reset(PbsUserDTO $pbsUserDTO) { public function getPersonGamification(Person $person): GamificationPersonProfile { $gamificationProfile = $person->getGamification(); - if(is_null($gamificationProfile)) { + if (is_null($gamificationProfile)) { $gamificationProfile = new GamificationPersonProfile(); $gamificationProfile->setLevel($this->levelRepository->findOneBy(['key' => 0])); $gamificationProfile->setPerson($person); @@ -80,7 +80,8 @@ public function getPersonGamification(Person $person): GamificationPersonProfile return $gamificationProfile; } - public function genericGoalProgress(PbsUserDTO $pbsUserDTO, string $type) { + public function genericGoalProgress(PbsUserDTO $pbsUserDTO, string $type) + { $person = $this->personRepository->find($pbsUserDTO->getId()); $pgp = $this->getPersonGamification($person); @@ -127,7 +128,8 @@ public function genericGoalProgress(PbsUserDTO $pbsUserDTO, string $type) { $this->em->flush(); } - public function checkLevelUp(GamificationPersonProfile $person) { + public function checkLevelUp(GamificationPersonProfile $person) + { $currentLevel = $person->getLevel(); $nextLevel = $this->levelRepository->findNextLevel($currentLevel); @@ -178,18 +180,20 @@ public function checkLevelUp(GamificationPersonProfile $person) { return $person; } - private function resetLevelUp(Person $person) { + private function resetLevelUp(Person $person) + { $levelUps = $this->levelUpLogRepository->findBy(['person' => $person->getId()]); foreach ($levelUps as $levelUp) { $this->levelUpLogRepository->remove($levelUp); } } - public function checkLoginGoal(GamificationPersonProfile $profile): bool { + public function checkLoginGoal(GamificationPersonProfile $profile): bool + { return count($profile->getPerson()->getLogins()) >= 4; } - public function getPersonGamificationDTO(PbsUserDTO $pbsUserDTO, String $locale): PersonGamificationDTO + public function getPersonGamificationDTO(PbsUserDTO $pbsUserDTO, string $locale): PersonGamificationDTO { $levels = $this->levelRepository->findBy(['type' => Level::USER]); /** @var Person $person */ diff --git a/src/Service/Gamification/QuapGamificationService.php b/src/Service/Gamification/QuapGamificationService.php index f0e09bc..9ab0a79 100644 --- a/src/Service/Gamification/QuapGamificationService.php +++ b/src/Service/Gamification/QuapGamificationService.php @@ -13,8 +13,7 @@ class QuapGamificationService public function __construct( PersonGamificationService $personGamificationService, AggregatedQuapRepository $aggregatedQuapRepository - ) - { + ) { $this->personGamificationService = $personGamificationService; $this->aggregatedQuapRepository = $aggregatedQuapRepository; } @@ -62,7 +61,8 @@ public function processQuapEvent(array $newAnswers, Group $group, PbsUserDTO $pb } } - private function isQuestionnaireFullyAnswered($questionnaire) { + private function isQuestionnaireFullyAnswered($questionnaire) + { foreach ($questionnaire as $answer) { if ($answer === 0) { return false;