Deferred   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 3
dl 0
loc 71
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A promise() 0 18 2
A resolve() 0 6 1
A reject() 0 6 1
A notify() 0 6 1
1
<?php
2
3
/*
4
 * This file is part of the Cubiche package.
5
 *
6
 * Copyright (c) Cubiche
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Cubiche\Core\Async\Promise;
13
14
/**
15
 * Deferred class.
16
 *
17
 * @author Karel Osorio Ramírez <[email protected]>
18
 */
19
class Deferred extends ObservableResolver implements DeferredInterface
20
{
21
    use CancelDeferredTrait;
22
23
    /**
24
     * @var PromiseInterface
25
     */
26
    protected $promise;
27
28
    /**
29
     * Constructor.
30
     */
31
    public function __construct()
32
    {
33
        parent::__construct(null, null, null);
34
35
        $this->promise = null;
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41
    public function promise()
42
    {
43
        if ($this->promise === null) {
44
            $this->promise = new Promise(
45
                function (callable $resolveCallback) {
46
                    $this->resolveCallback = $resolveCallback;
47
                },
48
                function (callable $rejectCallback) {
49
                    $this->rejectCallback = $rejectCallback;
50
                },
51
                function (callable $notifyCallback) {
52
                    $this->notifyCallback = $notifyCallback;
53
                }
54
            );
55
        }
56
57
        return $this->promise;
58
    }
59
60
    /**
61
     * {@inheritdoc}
62
     */
63
    public function resolve($value = null)
64
    {
65
        $this->promise();
66
67
        parent::resolve($value);
68
    }
69
70
    /**
71
     * {@inheritdoc}
72
     */
73
    public function reject($reason = null)
74
    {
75
        $this->promise();
76
77
        parent::reject($reason);
78
    }
79
80
    /**
81
     * {@inheritdoc}
82
     */
83
    public function notify($state = null)
84
    {
85
        $this->promise();
86
87
        parent::notify($state);
88
    }
89
}
90