Code Duplication    Length = 8-10 lines in 4 locations

src/AppBundle/Controller/Api/FormRequestController.php 1 location

@@ 68-75 (lines=8) @@
65
            ['object_to_populate' => $formRequest]
66
        );
67
        $errors = $this->get('validator')->validate($formRequest);
68
        if ($errors->count()) {
69
            $outErrors = [];
70
            /** @var ConstraintViolation $error */
71
            foreach ($errors as $error) {
72
                $outErrors[$error->getPropertyPath()] = $error->getMessage();
73
            }
74
            throw new JsonHttpException(400, 'Bad Request', $outErrors);
75
        }
76
        $em->persist($formRequest);
77
        $em->flush();
78

src/AppBundle/Controller/Api/SurveyController.php 1 location

@@ 83-90 (lines=8) @@
80
            array('object_to_populate' => $survey)
81
        );
82
        $errors = $this->get('validator')->validate($survey);
83
        if ($errors->count()) {
84
            $outErrors = [];
85
            /** @var ConstraintViolation $error */
86
            foreach ($errors as $error) {
87
                $outErrors[$error->getPropertyPath()] = $error->getMessage();
88
            }
89
            throw new JsonHttpException(400, 'Bad Request', $outErrors);
90
        }
91
        $em->persist($survey);
92
        $em->flush();
93

src/AppBundle/Controller/Api/UserController.php 2 locations

@@ 36-45 (lines=10) @@
33
        /** @var ConstraintViolationList $errors */
34
        $errors = $this->get('validator')->validate($image, null, ['Api']);
35
36
        if ($errors->count()) {
37
            $outErrors = [];
38
39
            /** @var ConstraintViolation $error */
40
            foreach ($errors as $error) {
41
                $outErrors['headers'][$error->getPropertyPath()] = $error->getMessage();
42
            }
43
44
            throw new JsonHttpException(400, 'Bad Request', $outErrors);
45
        }
46
        $user->setImage($image);
47
        $this->getDoctrine()->getManager()->flush();
48
@@ 110-119 (lines=10) @@
107
                AbstractNormalizer::OBJECT_TO_POPULATE => $user
108
            ]);
109
        $errors = $this->get('validator')->validate($user);
110
        if ($errors->count()) {
111
            $outErrors = [];
112
113
            /** @var ConstraintViolation $error */
114
            foreach ($errors as $error) {
115
                $outErrors[$error->getPropertyPath()] = $error->getMessage();
116
            }
117
118
            throw new JsonHttpException(400, 'Bad Request', $outErrors);
119
        }
120
        $this->getDoctrine()->getManager()->flush();
121
122
        return $this->json(['user' => $this->getUser()], 200, [], [AbstractNormalizer::GROUPS => ['Short']]);