self::REFUSED_MESSAGE, 'integrity' => 'The file did not match its hash.', 'encoding' => 'The file data could not be read.', 'offset' => 'The transfer is out of step. Restart this file.', 'write' => 'The file could not be written.', ]; public static function reason( \Throwable $e ): string { $message = $e->getMessage(); return match ( true ) { $e instanceof FileRefusedException => 'refused', str_contains( $message, 'integrity check' ) => 'integrity', str_contains( $message, 'Base64' ) || str_contains( $message, 'Gzip' ) => 'encoding', str_contains( $message, 'Transfer offset' ) || str_contains( $message, 'Transfer state' ) => 'offset', default => 'write', }; } public static function message( string $reason ): string { return self::MESSAGES[ $reason ] ?? self::MESSAGES['write']; } }