| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | declare(strict_types=1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | namespace AbterPhp\Framework\Http\Controllers; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use AbterPhp\Framework\Domain\Entities\IToJsoner; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use Opulence\Http\Responses\Response; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use Opulence\Http\Responses\ResponseHeaders; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | trait ApiIssueTrait | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |     /** @var string */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |     protected $problemBaseUrl; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |      * @param string $msg | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |      * @param array  $errors | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |      * @return Response | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |     protected function handleErrors(string $msg, array $errors): Response | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |         $this->logger->debug($msg); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |         $detail = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |         foreach ($errors as $key => $keyErrors) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |             foreach ($keyErrors as $keyError) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |                 $detail[] = sprintf('%s: %s', $key, $keyError); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |         $status  = ResponseHeaders::HTTP_BAD_REQUEST; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |         $content = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |             'type'   => sprintf('%sbad-request', $this->problemBaseUrl), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |             'title'  => 'Bad Request', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |             'status' => $status, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |             'detail' => implode("\n", $detail), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |         ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |         $response = new Response(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |         $response->setStatusCode($status); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |         $response->setContent(json_encode($content)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |         return $response; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |      * @param string     $msg | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |      * @param \Exception $exception | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |      * @return Response | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |     protected function handleException(string $msg, \Exception $exception): Response | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |         $this->logger->error($msg, $this->getExceptionContext($exception)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |         $status  = ResponseHeaders::HTTP_INTERNAL_SERVER_ERROR; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |         $content = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |             'type'   => sprintf('%sinternal-server-error', $this->problemBaseUrl), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |             'title'  => 'Internal Server Error', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |             'status' => $status, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |             'detail' => $exception->getMessage(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |         ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |         $response = new Response(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |         $response->setStatusCode($status); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |         $response->setContent(json_encode($content)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |         return $response; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |      * @param \Exception $exception | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |      * @return array | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 77 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 78 |  |  |     protected function getExceptionContext(\Exception $exception): array | 
            
                                                                        
                            
            
                                    
            
            
                | 79 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 80 |  |  |         $result = [static::LOG_CONTEXT_EXCEPTION => $exception->getMessage()]; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 81 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 82 |  |  |         $i = 1; | 
            
                                                                        
                            
            
                                    
            
            
                | 83 |  |  |         while ($exception = $exception->getPrevious()) { | 
            
                                                                        
                            
            
                                    
            
            
                | 84 |  |  |             $result[sprintf(static::LOG_PREVIOUS_EXCEPTION, $i++)] = $exception->getMessage(); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 85 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 86 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 87 |  |  |         return $result; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 89 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 90 |  |  |  | 
            
                        
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