Completed
Pull Request — master (#41)
by Ben
03:49 queued 01:21
created

WidgetExpression::getWidget()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Arrilot\Widgets\Misc;
4
5
use Arrilot\Widgets\AbstractWidget;
6
use Illuminate\View\Expression;
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
     *
18
     * @param AbstractWidget $widget instance of the widget this expression
19
     *                               represents
20
     */
21
    public function __construct($html, AbstractWidget $widget)
22
    {
23
        $this->widget = $widget;
24
        parent::__construct($html);
25
26
    }
27
28
    /**
29
     * Get the instance of the widget this expression represents.
30
     *
31
     * @return AbstractWidget
32
     */
33
    public function getWidget()
34
    {
35
        return $this->widget;
36
    }
37
38
    /**
39
     * Call a method directly on the widget instance.
40
     *
41
     * @param string $method method name
42
     * @param array  $params
43
     * 
44
     * @return mixed
45
     */
46
    public function __call($method, array $params = [])
47
    {
48
        if (is_callable($this->widget, $method)) {
49
            return call_user_func_array([$this->widget, $method], $params);
50
        }
51
        throw new InvalidArgumentException(
52
            sprintf(
53
                '"%s" does not have a method of "%s"',
54
                get_class($this->widget),
55
                $method
56
            )
57
        );
58
    }
59
}
60