Completed
Push — master ( 9672ef...b72795 )
by Ivannis Suárez
02:30
created

Resolver   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 1
cbo 0
dl 0
loc 44
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A resolve() 0 8 2
A notify() 0 8 2
onResolve() 0 1 ?
onNotify() 0 1 ?
A onInnerFailure() 0 4 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
 * Resolver class.
16
 *
17
 * @author Karel Osorio Ramírez <[email protected]>
18
 */
19
abstract class Resolver implements ResolverInterface
20
{
21
    /**
22
     * {@inheritdoc}
23
     */
24
    public function resolve($value = null)
25
    {
26
        try {
27
            $this->onResolve($value);
28
        } catch (\Exception $e) {
29
            $this->onInnerFailure($e);
30
        }
31
    }
32
33
    /**
34
     * {@inheritdoc}
35
     */
36
    public function notify($state = null)
37
    {
38
        try {
39
            $this->onNotify($state);
40
        } catch (\Exception $e) {
41
            $this->onInnerFailure($e);
42
        }
43
    }
44
45
    /**
46
     * @param mixed $value
47
     */
48
    abstract protected function onResolve($value = null);
49
50
    /**
51
     * @param mixed $state
52
     */
53
    abstract protected function onNotify($state = null);
54
55
    /**
56
     * @param \Exception $reason
57
     */
58
    protected function onInnerFailure(\Exception $reason)
59
    {
60
        $this->reject($reason);
61
    }
62
}
63