Completed
Pull Request — master (#86)
by Luc
02:31
created

PromiseOperation   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 0
dl 0
loc 19
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getPromise() 0 9 3
1
<?php
2
3
/*
4
 * This file is part of the Tolerance package.
5
 *
6
 * (c) Samuel ROZE <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Tolerance\Operation;
13
14
class PromiseOperation implements Operation
15
{
16
    private $promiseProvider;
17
18
    public function __construct(callable $promiseProvider)
19
    {
20
        $this->promiseProvider = $promiseProvider;
21
    }
22
23
    public function getPromise()
24
    {
25
        $promise = call_user_func($this->promiseProvider);
26
        if (!is_object($promise) || !method_exists($promise, 'then')) {
27
            throw new \LogicException('The "promiseProvider" must return a promise with a "then" method');
28
        }
29
30
        return $promise;
31
    }
32
}
33