Passed
Pull Request — master (#68)
by yasin
03:56
created

SlotRenderer::startSlot()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

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