Test Failed
Pull Request — master (#68)
by yasin
04:44
created

SlotRenderer   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 9
c 1
b 0
f 1
dl 0
loc 30
rs 10
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A renderSlot() 0 3 1
A hasSlot() 0 3 1
A startSlot() 0 4 2
A assignSlots() 0 4 2
1
<?php
2
3
namespace Imanghafoori\Widgets\Utils;
4
5
trait SlotRenderer 
6
{
7
	protected $slotName;
8
9
	protected $slots = [];
10
11
	public function startSlot($name)
12
	{
13
		if(ob_start()){
14
			$this->slotName = $name;
15
		}
16
	}
17
18
	public function renderSlot($data)
19
	{
20
		$this->slots[$this->slotName] = $data ?? "";
21
	}
22
23
	public function hasSlot()
24
	{
25
		return !empty($this->slots);
26
	}
27
28
    /**
29
     * Assign slots to $_viewData
30
     */
31
    private function assignSlots()
32
    {
33
        if($this->hasSlot())
34
            $this->_viewData = array_merge($this->_viewData, $this->slots);
0 ignored issues
show
Bug Best Practice introduced by
The property _viewData does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
35
    }
36
}