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

DeferredFactory   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

4 Methods

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