Lines
100.00%
20 / 20
Methods
100.00%
1 / 1
Classes
100.00%
1 / 1
| Name | Lines | Methods | CRAP | ||||
|---|---|---|---|---|---|---|---|
| __invoke | 100.00% | 20 / 20 | 100.00% | 1 / 1 | 5 | ||
| 17 | class ProfileController extends BaseController | |
| 18 | { | |
| 19 | public function __invoke(Request $request, ApiTokenStore $apiTokenStore, EntityManagerInterface $entityManager): Response | |
| 20 | { | |
| 21 | $user = $this->getUser(); | |
| 22 | $form = $this->createForm(ProfileVisibilityType::class, ['visibleParts' => $user->getVisibleParts()]); | |
| 23 | $form->handleRequest($request); | |
| 24 | ||
| 25 | if ($form->isSubmitted() && $form->isValid()) { | |
| 26 | /** @var list<ProfilePart> $parts */ | |
| 27 | $parts = $form->get('visibleParts')->getData(); | |
| 28 | $user->chooseVisibleParts($parts, new \DateTimeImmutable()); | |
| 29 | $entityManager->flush(); | |
| 30 | ||
| 31 | $this->addFlash('success', 'profile.visibility.saved'); | |
| 32 | ||
| 33 | return $this->redirectToRoute('app_profile', [], Response::HTTP_SEE_OTHER); | |
| 34 | } | |
| 35 | ||
| 36 | $partHelp = []; | |
| 37 | foreach (ProfilePart::cases() as $part) { | |
| 38 | $partHelp[$part->value] = $part->help(); | |
| 39 | } | |
| 40 | ||
| 41 | return $this->render('default/profile.html.twig', [ | |
| 42 | 'visibilityForm' => $form, | |
| 43 | 'partHelp' => $partHelp, | |
| 44 | 'agentPageVisible' => $user->isVisible(ProfilePart::AGENT), | |
| 45 | 'apiToken' => $this->isGranted(UserRole::ADMIN->value) | |
| 46 | ? $apiTokenStore->get($request->getSession(), $user) | |
| 47 | : null, | |
| 48 | ]); | |
| 49 | } | |
| 50 | } |