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

AsyncCommandResult   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 18
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getResult() 0 9 2
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