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

AsyncResult   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 16
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 7 2
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