Completed
Pull Request — master (#55)
by Timo
02:47
created

MakesPromisesTrait   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A createPromise() 0 4 1
A setPromiseFactory() 0 4 1
A getPromiseFactory() 0 8 2
1
<?php
2
/**
3
 * This file is part of the Tidal/WampWatch package.
4
 *  (c) 2016 Timo Michna <timomichna/yahoo.de>.
5
 *
6
 *  For the full copyright and license information, please view the LICENSE
7
 *  file that was distributed with this source code.
8
 */
9
10
namespace Tidal\WampWatch\Behavior\Async;
11
12
use Tidal\WampWatch\Async\PromiseInterface;
13
use Tidal\WampWatch\Async\Adapter\PromiseFactoryInterface;
14
use RuntimeException;
15
16
trait MakesPromisesTrait
17
{
18
    /**
19
     * @var PromiseFactoryInterface
20
     */
21
    private $promiseFactory;
22
23
    /**
24
     * @param callable      $resolver
25
     * @param callable|null $canceller
26
     *
27
     * @return PromiseInterface
28
     */
29
    protected function createPromise(callable $resolver, callable $canceller = null)
30
    {
31
        return $this->getPromiseFactory()->create($resolver, $canceller);
32
    }
33
34
    /**
35
     * @param PromiseFactoryInterface $promiseFactory
36
     */
37
    public function setPromiseFactory($promiseFactory)
38
    {
39
        $this->promiseFactory = $promiseFactory;
40
    }
41
42
    /**
43
     * @return PromiseFactoryInterface
44
     */
45
    public function getPromiseFactory()
46
    {
47
        if (!isset($this->promiseFactory)) {
48
            throw new RuntimeException('Promise Factory not set.');
49
        }
50
51
        return $this->promiseFactory;
52
    }
53
}
54