| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | declare(strict_types=1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | namespace BEAR\Package\Provide\Error; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use BEAR\Resource\ResourceObject; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use BEAR\Sunday\Extension\Router\RouterMatch; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use Override; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use Throwable; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | use function assert; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | use function json_encode; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | use function sprintf; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | use const JSON_PRETTY_PRINT; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | use const JSON_UNESCAPED_SLASHES; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | use const PHP_EOL; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | final class DevVndErrorPage extends ResourceObject | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |     public function __construct(Throwable $e, RouterMatch $request) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |         $status = new Status($e); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |         $this->code = $status->code; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |         $this->headers = $this->getHeader(); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |         $this->body = $this->getResponseBody($e, $request, $status); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |     #[Override] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |     public function toString(): string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |         $jsonEncoded = json_encode($this->body, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |         assert($jsonEncoded !== false); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |         $this->view = $jsonEncoded . PHP_EOL; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |         return $this->view; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |     /** @return array<string, string> */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |     private function getHeader(): array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |         return ['content-type' => 'application/vnd.error+json']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |  | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 46 |  |  |     /** @return array<string, string> */ | 
            
                                                                        
                            
            
                                    
            
            
                | 47 |  |  |     private function getResponseBody(Throwable $e, RouterMatch $request, Status $status): array | 
            
                                                                        
                            
            
                                    
            
            
                | 48 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 49 |  |  |         return [ | 
            
                                                                        
                            
            
                                    
            
            
                | 50 |  |  |             'message' => $status->text, | 
            
                                                                        
                            
            
                                    
            
            
                | 51 |  |  |             'logref' => (string) new LogRef($e), | 
            
                                                                        
                            
            
                                    
            
            
                | 52 |  |  |             'request' => (string) $request, | 
            
                                                                        
                            
            
                                    
            
            
                | 53 |  |  |             'exceptions' => sprintf('%s(%s)', $e::class, $e->getMessage()), | 
            
                                                                        
                            
            
                                    
            
            
                | 54 |  |  |             'file' => sprintf('%s(%s)', $e->getFile(), $e->getLine()), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |         ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 57 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 58 |  |  |  | 
            
                        
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..