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

DeferredFactory::getPromiseFactory()   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 0
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\Adapter\React;
13
14
use Tidal\WampWatch\Async\Adapter\PromiseFactoryInterface;
15
use React\Promise\Deferred as ReactDeferred;
16
17
class DeferredFactory
18
{
19
    /**
20
     * @var PromiseFactoryInterface
21
     */
22
    private $promiseFactory;
23
24
    public function __construct(PromiseFactoryInterface $promiseFactory)
25
    {
26
        $this->setPromiseFactory($promiseFactory);
27
    }
28
29
    /**
30
     * @param PromiseFactoryInterface $promiseFactory
31
     */
32
    private function setPromiseFactory(PromiseFactoryInterface $promiseFactory)
33
    {
34
        $this->promiseFactory = $promiseFactory;
35
    }
36
37
    /**
38
     * @return PromiseFactoryInterface
39
     */
40
    public function getPromiseFactory()
41
    {
42
        return $this->promiseFactory;
43
    }
44
45
    /**
46
     * @param callable|null $canceller
47
     *
48
     * @return DeferredAdapter
49
     */
50
    public function create(callable $canceller = null)
51
    {
52
        $adapter = new DeferredAdapter(
53
            new ReactDeferred($canceller)
54
        );
55
        $adapter->setPromiseFactory($this->getPromiseFactory());
56
57
        return $adapter;
58
    }
59
}
60