Completed
Push — EventLoopContainer ( c9a84d )
by Vasily
04:35
created

SyncWrapper::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
eloc 3
nc 2
nop 1
1
<?php
2
namespace PHPDaemon\Core;
3
4
class SyncWrapper
5
{
6
    protected $obj;
7
8
    /**
9
     * SyncWrapper constructor.
10
     * @param $obj
11
     */
12
    public function __construct($cb) {
13
        EventLoop::$instance || EventLoop::init();
14
        $this->obj = $cb($this);
15
    }
16
17
18
    /**
19
     * Abstract call
20
     * @param $method
21
     * @param $args
22
     */
23
    public function __call($method, $args) {
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
24
        $args[] = function($arg) use (&$ret) {
25
            $ret = $arg->result;
26
            EventLoop::$instance->stop();
27
        };
28
        $this->obj->$method(...$args);
29
        EventLoop::$instance->run();
30
        return $ret;
31
    }
32
}
33