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

MakesPromisesTrait::getPromiseFactory()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 0
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