Invoker::build()   B
last analyzed

Complexity

Conditions 7
Paths 4

Size

Total Lines 9
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 7

Importance

Changes 0
Metric Value
cc 7
eloc 8
nc 4
nop 1
dl 0
loc 9
rs 8.8333
c 0
b 0
f 0
ccs 8
cts 8
cp 1
crap 7
1
<?php
2
/**
3
 * Created by Gorlum 21.08.2016 13:33
4
 */
5
6
namespace Common;
7
8
/**
9
 * Class Invoker
10
 *
11
 * Invoker incapsulates callable until PHP 5.4+
12
 *
13
 * Supports method callable (2 element array), function callable (string) and lambda-functions
14
 *
15
 * @package Common
16
 * @deprecated
17
 */
18
19
class Invoker {
20
21
  protected $callable;
22
23
  /**
24
   * Invoker constructor.
25
   *
26
   * @param callable|null $callable
27
   */
28 1
  public function __construct($callable) {
29 1
    $this->callable = $callable;
30 1
  }
31
32
  /**
33
   * @param mixed $callable
34
   *
35
   * @return static
36
   */
37 1
  public static function build($callable) {
38 1
    if (is_array($callable) && count($callable) == 2 && is_object($callable[0])) {
39 1
      return new static($callable);
40 1
    } elseif (is_string($callable) && function_exists($callable)) {
41 1
      return new static($callable);
42 1
    } elseif (is_callable($callable)) {
43 1
      return new static($callable);
44
    } else {
45 1
      return new static(null);
46
    }
47
  }
48
49 1
  public function __invoke() {
50 1
    return is_callable($this->callable) ? call_user_func_array($this->callable, func_get_args()) : null;
0 ignored issues
show
Bug introduced by
It seems like $this->callable can also be of type null; however, parameter $callback of call_user_func_array() does only seem to accept callable, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

50
    return is_callable($this->callable) ? call_user_func_array(/** @scrutinizer ignore-type */ $this->callable, func_get_args()) : null;
Loading history...
51
  }
52
53
}
54