AbstractWidget   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 37
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A render() 0 3 1
1
<?php
2
3
namespace WebComplete\mvc\widget;
4
5
use WebComplete\core\utils\container\ContainerInterface;
6
use WebComplete\mvc\view\View;
7
use WebComplete\mvc\view\ViewInterface;
8
9
abstract class AbstractWidget
10
{
11
12
    /**
13
     * @var ContainerInterface
14
     */
15
    protected $container;
16
    /**
17
     * @var ViewInterface
18
     */
19
    protected $view;
20
21
    /**
22
     * @param ContainerInterface $container
23
     */
24
    public function __construct(ContainerInterface $container)
25
    {
26
        $this->container = $container;
27
        $this->view = $this->container->get(View::class);
28
    }
29
30
    /**
31
     * @param array $params
32
     * @return string
33
     */
34
    abstract public function run(array $params = []): string;
35
36
    /**
37
     * @param string $templatePath
38
     * @param array $vars
39
     *
40
     * @return string
41
     * @throws \Exception
42
     */
43
    protected function render(string $templatePath, array $vars = []): string
44
    {
45
        return $this->view->layout()->render($templatePath, $vars);
46
    }
47
}
48