Completed
Push — master ( 84efb4...d8405a )
by Ben
01:54
created

WidgetWrapperFactory::begin()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 1
eloc 5
nc 1
nop 0
1
<?php
2
3
namespace Benrowe\Laravel\Widgets\Traits;
4
5
/**
6
 * Provides the begin & end functionality for the Widget factory
7
 *
8
 * @package Benrowe\Laravel\Widgets
9
 */
10
trait WidgetWrapperFactory
11
{
12
    private $stack = [];
13
14
    /**
15
     *
16
     * @param  [type] $args [description]
0 ignored issues
show
Documentation introduced by
The doc-type [type] could not be parsed: Unknown type name "" at position 0. [(view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
17
     * @return [type]       [description]
0 ignored issues
show
Documentation introduced by
The doc-type [type] could not be parsed: Unknown type name "" at position 0. [(view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
18
     */
19
    abstract protected function instantiateWidget($args);
20
21
    /**
22
     * [asExpression description]
23
     * @param  [type] $html [description]
0 ignored issues
show
Documentation introduced by
The doc-type [type] could not be parsed: Unknown type name "" at position 0. [(view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
24
     * @return [type]       [description]
0 ignored issues
show
Documentation introduced by
The doc-type [type] could not be parsed: Unknown type name "" at position 0. [(view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
25
     */
26
    abstract protected function asExpression($html);
27
28
    /**
29
     * Being the widget
30
     *
31
     * @return Expression
32
     */
33
    public function begin()
34
    {
35
        $args = func_get_args();
36
        $this->stack[] = $args;
37
        $this->instantiateWidget($args);
38
39
        return $this->asExpression($this->widget->begin());
0 ignored issues
show
Bug introduced by
The property widget does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
40
    }
41
42
    /**
43
     * End the widget
44
     *
45
     * @param array $config suplementry config
46
     * @return Expression
47
     */
48
    public function end($config = [])
49
    {
50
        $args = array_pop($this->stack);
51
        $args[1] = $args[1] ? array_merge($args[1], $config) : [];
52
        $this->instantiateWidget($args);
53
54
        return $this->asExpression($this->widget->end());
55
    }
56
}
57