Passed
Pull Request — master (#68)
by yasin
02:44
created

SlotRenderer   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 33.33%

Importance

Changes 5
Bugs 0 Features 2
Metric Value
eloc 9
c 5
b 0
f 2
dl 0
loc 30
ccs 4
cts 12
cp 0.3333
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 18
    public function hasSlot()
24
    {
25 18
        return !empty($this->slots);
26
    }
27
28
    /**
29
     * Assign slots to $_viewData
30
     */
31 18
    private function assignSlots()
32
    {
33 18
        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 18
    }
36
}
37