ViewableTrait::render()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2.0185

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 8
ccs 5
cts 6
cp 0.8333
rs 10
cc 2
nc 2
nop 0
crap 2.0185
1
<?php
2
3
declare(strict_types=1);
4
5
namespace midorikocak\view;
6
7
trait ViewableTrait
8
{
9
    public ?View $view = null;
10
    public string $template = '';
11
12
    abstract public function toArray(): array;
13
14 1
    public function render(): string
15
    {
16 1
        $this->view ??= new View(new FileRenderer());
17 1
        if ($this->template === '') {
18
            return '';
19
        }
20 1
        $this->view->setTemplate($this->template);
21 1
        return $this->view->render($this->toArray());
22
    }
23
}
24