| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace App\Controller\Scenario; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use ApiPlatform\Core\Bridge\Symfony\Validator\Exception\ValidationException; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use App\Entity\Submission; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use App\Service\ScenarioService; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use App\Service\SubmissionService; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use InvalidArgumentException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use Symfony\Component\HttpFoundation\JsonResponse; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | use Symfony\Component\HttpFoundation\RequestStack; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | use Symfony\Component\HttpFoundation\Response; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | use Symfony\Component\Validator\ConstraintViolationList; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | use function GuzzleHttp\json_decode; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | use Symfony\Component\Routing\Annotation\Route; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  * Class SubmissionsController | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 22 |  |  |  */ | 
            
                                                                        
                            
            
                                    
            
            
                | 23 |  |  | final class SubmissionsController | 
            
                                                                        
                            
            
                                    
            
            
                | 24 |  |  | { | 
            
                                                                        
                            
            
                                    
            
            
                | 25 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 26 |  |  |      * @var \Symfony\Component\HttpFoundation\RequestStack | 
            
                                                                        
                            
            
                                    
            
            
                | 27 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 28 |  |  |     private $requestStack; | 
            
                                                                        
                            
            
                                    
            
            
                | 29 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 30 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 31 |  |  |      * @var \App\Service\ScenarioService | 
            
                                                                        
                            
            
                                    
            
            
                | 32 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 33 |  |  |     private $scenarioService; | 
            
                                                                        
                            
            
                                    
            
            
                | 34 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 35 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 36 |  |  |      * @var \App\Service\SubmissionService | 
            
                                                                        
                            
            
                                    
            
            
                | 37 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 38 |  |  |     private $submissionService; | 
            
                                                                        
                            
            
                                    
            
            
                | 39 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 40 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 41 |  |  |      * Constructor | 
            
                                                                        
                            
            
                                    
            
            
                | 42 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 43 |  |  |      * @param \Symfony\Component\HttpFoundation\RequestStack $requestStack | 
            
                                                                        
                            
            
                                    
            
            
                | 44 |  |  |      * @param \App\Service\ScenarioService $scenarioService | 
            
                                                                        
                            
            
                                    
            
            
                | 45 |  |  |      * @param \App\Service\SubmissionService $submissionService | 
            
                                                                        
                            
            
                                    
            
            
                | 46 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 47 |  |  |     public function __construct(RequestStack $requestStack, ScenarioService $scenarioService, SubmissionService $submissionService) | 
            
                                                                        
                            
            
                                    
            
            
                | 48 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 49 |  |  |         $this->requestStack = $requestStack; | 
            
                                                                        
                            
            
                                    
            
            
                | 50 |  |  |         $this->scenarioService = $scenarioService; | 
            
                                                                        
                            
            
                                    
            
            
                | 51 |  |  |         $this->submissionService = $submissionService; | 
            
                                                                        
                            
            
                                    
            
            
                | 52 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 53 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 54 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 55 |  |  |      * Form | 
            
                                                                        
                            
            
                                    
            
            
                | 56 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 57 |  |  |      * @Route(path="/scenarios/{uuid}/submissions", methods={"POST"}) | 
            
                                                                        
                            
            
                                    
            
            
                | 58 |  |  |      * @param string $uuid | 
            
                                                                        
                            
            
                                    
            
            
                | 59 |  |  |      * @return \Symfony\Component\HttpFoundation\JsonResponse | 
            
                                                                        
                            
            
                                    
            
            
                | 60 |  |  |      * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException | 
            
                                                                        
                            
            
                                    
            
            
                | 61 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |     public function post($uuid) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |         $scenario = $this->scenarioService->getRepository()->findOneBy(['uuid' => $uuid]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |         if (!$scenario) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |             throw new NotFoundHttpException('Scenario not found.'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |         $request = $this->requestStack->getCurrentRequest(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |         try { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |             $content = json_decode($request->getContent()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |         } catch (InvalidArgumentException $exception) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |             throw new BadRequestHttpException('Request content is not valid json.'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |         $submission = $this->submissionService->createInstance(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |         $submission | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |             ->setScenario($scenario) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |             ->setData((array) $content->data) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |             ->setState(Submission::STATE_SUBMITTED); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |         $violations = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |         if (!$this->submissionService->isValid($submission, $violations)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |             $list = new ConstraintViolationList($violations); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |             throw new ValidationException($list, 'An error occurred'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |         $manager = $this->submissionService->getManager(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |         $manager->persist($submission); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |         $manager->flush(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |         $response = new JsonResponse($submission, Response::HTTP_CREATED); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |  | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 95 |  |  |         return $response; | 
            
                                                                        
                                                                
            
                                    
            
            
                | 96 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 97 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 98 |  |  |  | 
            
                        
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths