Completed
Push — master ( 5b45c7...94c940 )
by Jitendra
02:27
created

HigherOrderMessage::__get()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 1
nop 1
dl 0
loc 6
rs 10
c 0
b 0
f 0
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 $props ? $props[0] : null;
43
        });
44
    }
45
}
46