Completed
Pull Request — master (#41)
by Ben
03:10
created

WidgetExpression::__call()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 13
rs 9.4285
cc 2
eloc 8
nc 2
nop 2
1
<?php
2
3
namespace Arrilot\Widgets\Misc;
4
5
use Illuminate\View\Expression;
6
use Arrilot\Widgets\AbstractWidget;
7
8
/**
9
 * Represents an widget to the view
10
 */
11
class WidgetExpression extends Expression
0 ignored issues
show
Deprecated Code introduced by
The class Illuminate\View\Expression has been deprecated with message: since version 5.2. Use Illuminate\Support\HtmlString.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
12
{
13
    protected $widget;
14
15
    /**
16
     * @inheritdoc
17
     * @param AbstractWidget $widget instance of the widget this expression
18
     *                               represents
19
     */
20
    public function __construct($html, AbstractWidget $widget)
21
    {
22
        $this->widget = $widget;
23
        parent::__construct($html);
24
25
    }
26
27
    /**
28
     * Get the instance of the widget this expression represents
29
     *
30
     * @return AbstractWidget
31
     */
32
    public function getWidget()
33
    {
34
        return $this->widget;
35
    }
36
37
    /**
38
     * Call a method directly on the widget instance
39
     *
40
     * @param  string $method method name
41
     * @param  array $params
42
     * @return mixed
43
     */
44
    public function __call($method, array $params = [])
45
    {
46
        if (is_callable($this->widget, $method)) {
47
            return call_user_func_array([$this->widget, $method], $params);
48
        }
49
        throw new InvalidArgumentException(
50
            sprintf(
51
                '"%s" does not have a method of "%s"',
52
                get_class($this->widget),
53
                $method
54
            )
55
        );
56
    }
57
}
58