Completed
Push — SWP-2334 ( b8b10a...19878c )
by
unknown
56s
created
src/SWP/Bundle/UserBundle/Controller/ProfileController.php 1 patch
Indentation   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -34,10 +34,10 @@  discard block
 block discarded – undo
34 34
 
35 35
 class ProfileController extends AbstractController {
36 36
 
37
-  private EntityManagerInterface $entityManager;
38
-  private AuthorizationCheckerInterface $authorizationChecker;
39
-  private UserRepository $userRepository;
40
-  private PaginatorInterface $paginator;
37
+    private EntityManagerInterface $entityManager;
38
+    private AuthorizationCheckerInterface $authorizationChecker;
39
+    private UserRepository $userRepository;
40
+    private PaginatorInterface $paginator;
41 41
 
42 42
     /**
43 43
      * @param EntityManagerInterface $entityManager
@@ -75,27 +75,27 @@  discard block
 block discarded – undo
75 75
         return new ResourcesListResponse($profiles);
76 76
     }
77 77
 
78
-  /**
79
-   * @Route("/api/{version}/users/profile/{id}", methods={"GET"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_user_get_user_profile")
80
-   */
81
-  public function getAction($id) {
78
+    /**
79
+     * @Route("/api/{version}/users/profile/{id}", methods={"GET"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_user_get_user_profile")
80
+     */
81
+    public function getAction($id) {
82 82
     $requestedUser = $this->userRepository->find($id);
83 83
     if (!is_object($requestedUser) || !$requestedUser instanceof UserInterface) {
84
-      throw new NotFoundHttpException('Requested user don\'t exists');
84
+        throw new NotFoundHttpException('Requested user don\'t exists');
85 85
     }
86 86
 
87 87
     $this->checkIfCanAccess($requestedUser);
88 88
 
89 89
     return new SingleResourceResponse($requestedUser);
90
-  }
90
+    }
91 91
 
92
-  /**
93
-   * @Route("/api/{version}/users/profile/{id}", methods={"PATCH"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_user_edit_user_profile")
94
-   */
95
-  public function editAction(Request $request, $id, UserPasswordEncoderInterface $passwordEncoder) {
92
+    /**
93
+     * @Route("/api/{version}/users/profile/{id}", methods={"PATCH"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_user_edit_user_profile")
94
+     */
95
+    public function editAction(Request $request, $id, UserPasswordEncoderInterface $passwordEncoder) {
96 96
     $requestedUser = $this->userRepository->find($id);
97 97
     if (!is_object($requestedUser) || !$requestedUser instanceof UserInterface) {
98
-      throw new NotFoundHttpException('Requested user don\'t exists');
98
+        throw new NotFoundHttpException('Requested user don\'t exists');
99 99
     }
100 100
 
101 101
     $this->checkIfCanAccess($requestedUser);
@@ -106,32 +106,32 @@  discard block
 block discarded – undo
106 106
     $form->handleRequest($request);
107 107
 
108 108
     if ($form->isSubmitted() && $form->isValid()) {
109
-      if (!empty($form->get('plainPassword')->getData())) {
109
+        if (!empty($form->get('plainPassword')->getData())) {
110 110
         $requestedUser->setPassword(
111 111
             $passwordEncoder->encodePassword(
112 112
                 $requestedUser,
113 113
                 $form->get('plainPassword')->getData()
114 114
             )
115 115
         );
116
-      }
116
+        }
117 117
 
118
-      $entityManager = $this->entityManager;
119
-      $entityManager->flush();
118
+        $entityManager = $this->entityManager;
119
+        $entityManager->flush();
120 120
 
121
-      return new SingleResourceResponse($requestedUser);
121
+        return new SingleResourceResponse($requestedUser);
122 122
     }
123 123
 
124 124
     return new SingleResourceResponse($form, new ResponseContext(400));
125
-  }
125
+    }
126 126
 
127
-  private function checkIfCanAccess($requestedUser) {
127
+    private function checkIfCanAccess($requestedUser) {
128 128
     /** @var UserInterface $currentUser */
129 129
     $currentUser = $this->getUser();
130 130
     if (
131 131
         !$this->authorizationChecker->isGranted('ROLE_ADMIN') &&
132 132
         $requestedUser->getId() !== $currentUser->getId()
133 133
     ) {
134
-      throw new AccessDeniedException('This user does not have access to this section. profile');
134
+        throw new AccessDeniedException('This user does not have access to this section. profile');
135
+    }
135 136
     }
136
-  }
137 137
 }
Please login to merge, or discard this patch.