| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | declare(strict_types=1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  | namespace JsonDecodeStream\Exception; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use JsonDecodeStream\Event; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use JsonDecodeStream\Token; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | class ParserException extends JsonDecodeStreamException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |     const CODE_INVALID_ARGUMENT = 1; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |     const CODE_UNEXPECTED_VALUE = 2; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |     const CODE_UNEXPECTED_TOKEN = 101; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |     const CODE_EXPECTED_BUT_GOT = 102; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 16 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 17 |  |  |     public function __construct($message, int $code, ?int $lineNumber = null, ?int $charNumber = null) | 
            
                                                                        
                            
            
                                    
            
            
                | 18 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 19 |  |  |         if ($lineNumber !== null && $charNumber !== null) { | 
            
                                                                        
                            
            
                                    
            
            
                | 20 |  |  |             $message .= " at $lineNumber:$charNumber"; | 
            
                                                                        
                            
            
                                    
            
            
                | 21 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 22 |  |  |         parent::__construct($message, $code); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |     public static function unexpectedToken(Token $token) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |         return new static( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |             sprintf('Unexpected token `%s`', $token->getId()), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |             static::CODE_UNEXPECTED_TOKEN, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |             $token->getLineNumber(), $token->getCharNumber() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |     public static function expectedButGot(string $expected, Token $gotToken) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |         $got = ($gotToken->getValue() ? json_encode($gotToken->getValue()) : $gotToken->getId()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |         return new static( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |             sprintf('Expected `%s` but got `%s`', $expected, $got), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |             static::CODE_EXPECTED_BUT_GOT, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |             $gotToken->getLineNumber(), $gotToken->getCharNumber() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |     public static function unexpectedCollectorReturn($yielded, Event $event) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 48 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 49 |  |  |  | 
            
                        
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.