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

SyncWrapper   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 2
A __call() 0 9 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