Passed
Push — master ( d5b9c5...238a05 )
by Timo
26s
created

MakesPromisesTrait::setPromiseFactory()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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