Expression   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 2
Bugs 0 Features 2
Metric Value
wmc 4
c 2
b 0
f 2
lcom 0
cbo 1
dl 0
loc 50
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getWidget() 0 4 1
A __call() 0 13 2
1
<?php
2
3
namespace Benrowe\Laravel\Widgets;
4
5
use Arrilot\Widgets\AbstractWidget as BaseAbstractWidget;
6
use Illuminate\Support\HtmlString;
7
use InvalidArgumentException;
8
9
/**
10
 * Represents the widget after it has been executed.
11
 *
12
 * This expression allows the widets to be outputted (aka echo'd) or
13
 * allows access to the public methods of the widget inside the view.
14
 *
15
 * @package Benrowe\Laravel\Widgets
16
 */
17
class Expression extends HtmlString
18
{
19
    protected $widget;
20
21
    /**
22
     * Constructor
23
     * Recieve necessary dependancies
24
     *
25
     * @param string             $html
26
     * @param BaseAbstractWidget $widget
27
     */
28
    public function __construct($html, BaseAbstractWidget $widget)
29
    {
30
        $this->widget = $widget;
31
        parent::__construct($html);
32
    }
33
34
    /**
35
     * Retrieve the instance of the widget this Expression Represents
36
     *
37
     * @return BaseAbstractWidget
38
     */
39
    public function getWidget()
40
    {
41
        return $this->widget;
42
    }
43
44
    /**
45
     * Magic method implementation
46
     * Expose the methods of the widget through this expression
47
     *
48
     * @param  string $method the method name to try and call
49
     * @param  array $params params the method requires
50
     * @throws InvalidArgumentException
51
     * @return mixed
52
     */
53
    public function __call($method, array $params = [])
54
    {
55
        if (is_callable($this->widget, $method)) {
56
            return call_user_func_array([$this->widget, $method], $params);
57
        }
58
        throw new InvalidArgumentException(
59
            sprintf(
60
                '"%s" does not have a method of "%s"',
61
                get_class($this->widget),
62
                $method
63
            )
64
        );
65
    }
66
}
67