mirror of
https://codeberg.org/icewind/SMB.git
synced 2026-06-04 01:34:07 +02:00
all the types
This commit is contained in:
parent
515b42586e
commit
84fa890ea7
28 changed files with 330 additions and 110 deletions
|
|
@ -7,16 +7,36 @@
|
|||
|
||||
namespace Icewind\SMB\Exception;
|
||||
|
||||
use Throwable;
|
||||
|
||||
/**
|
||||
* @psalm-consistent-constructor
|
||||
*/
|
||||
class Exception extends \Exception {
|
||||
public static function unknown(?string $path, $error) {
|
||||
$message = 'Unknown error (' . $error . ')';
|
||||
public function __construct(string $message = "", int $code = 0, Throwable $previous = null) {
|
||||
parent::__construct($message, $code, $previous);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|null $path
|
||||
* @param string|int|null $error
|
||||
* @return Exception
|
||||
*/
|
||||
public static function unknown(?string $path, $error): Exception {
|
||||
$message = 'Unknown error (' . (string)$error . ')';
|
||||
if ($path) {
|
||||
$message .= ' for ' . $path;
|
||||
}
|
||||
|
||||
return new Exception($message, is_string($error) ? 0 : $error);
|
||||
return new Exception($message, is_int($error) ? $error : 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<int|string, class-string<Exception>> $exceptionMap
|
||||
* @param string|int|null $error
|
||||
* @param string|null $path
|
||||
* @return Exception
|
||||
*/
|
||||
public static function fromMap(array $exceptionMap, $error, ?string $path): Exception {
|
||||
if (isset($exceptionMap[$error])) {
|
||||
$exceptionClass = $exceptionMap[$error];
|
||||
|
|
|
|||
|
|
@ -13,15 +13,11 @@ class InvalidRequestException extends Exception {
|
|||
*/
|
||||
protected $path;
|
||||
|
||||
/**
|
||||
* @param string $path
|
||||
* @param int $code
|
||||
*/
|
||||
public function __construct($path, $code = 0) {
|
||||
public function __construct(string $path = "", int $code = 0, \Throwable $previous = null) {
|
||||
$class = get_class($this);
|
||||
$parts = explode('\\', $class);
|
||||
$baseName = array_pop($parts);
|
||||
parent::__construct('Invalid request for ' . $path . ' (' . $baseName . ')', $code);
|
||||
parent::__construct('Invalid request for ' . $path . ' (' . $baseName . ')', $code, $previous);
|
||||
$this->path = $path;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ namespace Icewind\SMB\Exception;
|
|||
use Throwable;
|
||||
|
||||
class RevisionMismatchException extends Exception {
|
||||
public function __construct($message = 'Protocol version mismatch', $code = 0, Throwable $previous = null) {
|
||||
public function __construct(string $message = 'Protocol version mismatch', int $code = 0, Throwable $previous = null) {
|
||||
parent::__construct($message, $code, $previous);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue