Completed
Push — master ( 298e09...565401 )
by Ivannis Suárez
02:36
created

CallablePromisor::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 1
eloc 3
nc 1
nop 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
use Cubiche\Core\Delegate\Delegate;
15
16
/**
17
 * Callable Promisor class.
18
 *
19
 * @author Karel Osorio Ramírez <[email protected]>
20
 */
21
class CallablePromisor extends Delegate implements PromisorInterface
22
{
23
    /**
24
     * @var Delegate
25
     */
26
    protected $delegate;
27
28
    /**
29
     * @var DeferredInterface
30
     */
31
    protected $deferred = null;
32
33
    /**
34
     * @param callable $callable
35
     */
36
    public function __construct(callable $callable)
37
    {
38
        parent::__construct(array($this, 'execute'));
39
40
        $this->delegate = new Delegate($callable);
41
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46
    public function promise()
47
    {
48
        return $this->deferred()->promise();
49
    }
50
51
    protected function execute()
52
    {
53
        try {
54
            $this->deferred()->resolve($this->delegate->invokeWith(\func_get_args()));
55
        } catch (\Throwable $e) {
1 ignored issue
show
Bug introduced by
The class Throwable does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
56
            $this->deferred()->reject($e);
57
        } catch (\Exception $e) {
58
            $this->deferred()->reject($e);
59
        }
60
    }
61
62
    /**
63
     * @return \Cubiche\Core\Async\Promise\DeferredInterface
64
     */
65
    protected function deferred()
66
    {
67
        if ($this->deferred === null) {
68
            $this->deferred = new Deferred();
69
        }
70
71
        return $this->deferred;
72
    }
73
}
74