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

AsyncResult::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
namespace Ivory\Result;
4
5
class AsyncResult implements IAsyncResult
6
{
7
    private $resultFetcher;
8
9
    public function __construct(\Closure $resultFetcher)
10
    {
11
        $this->resultFetcher = $resultFetcher;
12
    }
13
14
    public function getResult(): IResult
15
    {
16
        $result = ($this->resultFetcher)();
17
        if ($result instanceof IResult) {
18
            return $result;
19
        } else {
20
            throw new \LogicException('The result fetcher did not return an expected result.');
21
        }
22
    }
23
}
24