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

DeferredAdapter::makePromise()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 5
nc 2
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\DeferredInterface;
15
use Tidal\WampWatch\Behavior\Async\MakesPromisesTrait;
16
use React\Promise\Deferred;
17
18
class DeferredAdapter implements DeferredInterface
19
{
20
    use MakesPromisesTrait;
21
22
    /**
23
     * @var Deferred
24
     */
25
    private $adaptee;
26
27
    /**
28
     * DeferredAdapter constructor.
29
     *
30
     * @param \React\Promise\Deferred $adaptee
31
     */
32
    public function __construct(Deferred $adaptee)
33
    {
34
        $this->setAdaptee($adaptee);
35
    }
36
37
    /**
38
     * @param \React\Promise\Deferred $adaptee
39
     */
40
    private function setAdaptee(Deferred $adaptee)
41
    {
42
        $this->adaptee = $adaptee;
43
    }
44
45
    /**
46
     * @return mixed
47
     */
48
    public function getAdaptee()
49
    {
50
        return $this->adaptee;
51
    }
52
53
    /**
54
     * @return PromiseAdapter
55
     */
56
    public function promise()
57
    {
58
        return $this->makePromise();
59
    }
60
61
    /**
62
     * @param null $value
63
     */
64
    public function resolve($value = null)
65
    {
66
        $this->adaptee->resolve($value);
67
    }
68
69
    /**
70
     * @param null $reason
71
     */
72
    public function reject($reason = null)
73
    {
74
        $this->adaptee->reject($reason);
75
    }
76
77
    /**
78
     * @param null $update
79
     */
80
    public function notify($update = null)
81
    {
82
        $this->adaptee->notify($update);
83
    }
84
85
    private function makePromise()
86
    {
87
        if (!isset($this->promiseFactory)) {
88
            $this->promiseFactory = new PromiseFactory();
89
        }
90
91
        return $this->getPromiseFactory()->createFromAdaptee(
92
            $this->adaptee->promise()
93
        );
94
    }
95
}
96