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

SlotRenderer::renderSlot()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 2
Metric Value
cc 1
eloc 1
c 2
b 0
f 2
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
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