generated from Nodarx/template
refactor: unify command complition checking
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace KTXM\ProviderImap\Client\Protocol;
|
||||
|
||||
use KTXM\ProviderImap\Client\CommandFailedException;
|
||||
use KTXM\ProviderImap\Client\ImapException;
|
||||
use KTXM\ProviderImap\Client\Protocol\Parser\ResponseCodeParser;
|
||||
use KTXM\ProviderImap\Client\Protocol\Response\TaggedResponse;
|
||||
|
||||
final class CompletionChecker
|
||||
{
|
||||
public static function assertSuccess(string $command, TaggedResponse $response): void
|
||||
{
|
||||
if ($response->isOk()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!in_array($response->status(), ['NO', 'BAD'], true)) {
|
||||
throw new ImapException($command . ' received an invalid completion status: ' . $response->status());
|
||||
}
|
||||
|
||||
throw new CommandFailedException(
|
||||
$command,
|
||||
$response->status(),
|
||||
$response->text(),
|
||||
(new ResponseCodeParser())->parse($response->text()),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user