| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  * Copyright (c) 2014 Robin Appelman <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * This file is licensed under the Licensed under the MIT license: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * http://opensource.org/licenses/MIT | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | namespace Icewind\SMB\Exception; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use Throwable; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 | 2 |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 | 2 |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 | 2 |  |  * @psalm-consistent-constructor | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 14 | 2 |  |  */ | 
            
                                                                        
                            
            
                                    
            
            
                | 15 |  |  | class Exception extends \Exception { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | 	public function __construct(string $message = "", int $code = 0, Throwable $previous = null) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 | 2 |  | 		parent::__construct($message, $code, $previous); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 18 |  |  | 	} | 
            
                                                                        
                            
            
                                    
            
            
                | 19 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 20 |  |  | 	/** | 
            
                                                                        
                            
            
                                    
            
            
                | 21 |  |  | 	 * @param string|null $path | 
            
                                                                        
                            
            
                                    
            
            
                | 22 |  |  | 	 * @param string|int|null $error | 
            
                                                                        
                            
            
                                    
            
            
                | 23 |  |  | 	 * @return Exception | 
            
                                                                        
                            
            
                                    
            
            
                | 24 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  | 	public static function unknown(?string $path, $error): Exception { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 | 74 |  | 		$message = 'Unknown error (' . (string)$error . ')'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 | 74 |  | 		if ($path) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 | 74 |  | 			$message .= ' for ' . $path; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 | 74 |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 | 36 |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  | 		return new Exception($message, is_int($error) ? $error : 0); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 32 | 38 |  | 	} | 
            
                                                                        
                            
            
                                    
            
            
                | 33 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 34 |  |  | 	/** | 
            
                                                                        
                            
            
                                    
            
            
                | 35 | 2 |  | 	 * @param array<int|string, class-string<Exception>> $exceptionMap | 
            
                                                                        
                            
            
                                    
            
            
                | 36 |  |  | 	 * @param string|int|null $error | 
            
                                                                        
                            
            
                                    
            
            
                | 37 |  |  | 	 * @param string|null $path | 
            
                                                                        
                            
            
                                    
            
            
                | 38 |  |  | 	 * @return Exception | 
            
                                                                        
                            
            
                                    
            
            
                | 39 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  | 	public static function fromMap(array $exceptionMap, $error, ?string $path): Exception { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  | 		if (isset($exceptionMap[$error])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  | 			$exceptionClass = $exceptionMap[$error]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  | 			if (is_numeric($error)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  | 				return new $exceptionClass($path, $error); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  | 			} else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  | 				return new $exceptionClass($path); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  | 		} else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  | 			return Exception::unknown($path, $error); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  | 		} | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 51 |  |  | 	} | 
            
                                                        
            
                                    
            
            
                | 52 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 53 |  |  |  | 
            
                        
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
stringvalues, the empty string''is a special case, in particular the following results might be unexpected: