Passed
Push — master ( 27ca4d...8d618a )
by Ondřej
02:45 queued 10s
created

AsyncCommandResult::getResult()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 7
nc 2
nop 0
dl 0
loc 9
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
namespace Ivory\Result;
4
5
use Ivory\Exception\UsageException;
6
7
class AsyncCommandResult implements IAsyncCommandResult
8
{
9
    private $asyncResult;
10
11
    public function __construct(\Closure $resultFetcher)
12
    {
13
        $this->asyncResult = new AsyncResult($resultFetcher);
14
    }
15
16
    public function getResult(): ICommandResult
17
    {
18
        $result = $this->asyncResult->getResult();
19
        if ($result instanceof ICommandResult) {
20
            return $result;
21
        } else {
22
            throw new UsageException(
23
                'The supplied SQL statement was supposed to be a command, but it returned a result set. ' .
24
                'Did you mean to call queryAsync()?'
25
            );
26
        }
27
    }
28
}
29