HigherOrderMessage::__call()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 4
rs 10
1
<?php
2
3
/*
4
 * This file is part of the PHP-UNDERSCORE package.
5
 *
6
 * (c) Jitendra Adhikari <[email protected]>
7
 *     <https://github.com/adhocore>
8
 *
9
 * Licensed under MIT license.
10
 */
11
12
namespace Ahc\Underscore;
13
14
/**
15
 * Source: Laravel HigherOrderProxy.
16
 *
17
 * @link https://github.com/laravel/framework/pull/16267
18
 */
19
class HigherOrderMessage
20
{
21
    protected $underscore;
22
    protected $method;
23
24
    public function __construct(UnderscoreBase $underscore, $method)
25
    {
26
        $this->underscore = $underscore;
27
        $this->method     = $method;
28
    }
29
30
    public function __call($method, $args)
31
    {
32
        return $this->underscore->{$this->method}(function ($item) use ($method, $args) {
33
            return \call_user_func_array([$item, $method], $args);
34
        });
35
    }
36
37
    public function __get($prop)
38
    {
39
        return $this->underscore->{$this->method}(function ($item) use ($prop) {
40
            $props = \array_column([$item], $prop);
41
42
            return empty($props) ? null : $props[0];
43
        });
44
    }
45
}
46