Render   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 1
cbo 2
dl 0
loc 38
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A render() 0 6 1
A redirect() 0 5 1
A error() 0 9 1
A finish() 0 5 1
A __construct() 0 4 1
1
<?php
2
3
namespace cvweiss\projectbase;
4
5
class Render
6
{
7
    private $twig;
8
9
    public function __construct($twig)
10
    {
11
        $this->twig = $twig;
12
    }
13
14
    public function render($file, $values = [])
15
    {
16
        $values = array_merge($values, Config::getInstance()->getAll());
17
        echo $this->twig->render($file . '.html', $values);
18
        $this->finish();
19
    }
20
21
    public function redirect($url, $code = 302)
22
    {
23
        header("Location: $url", $code);
24
        $this->finish();
25
    }
26
27
    public function error($errorCode, $errorMessage, $params)
28
    {   
29
        $params['errorCode'] = $errorCode;
30
        $params['errorMessage'] = $errorMessage;
31
32
        http_response_code($errorCode);
33
        echo $this->twig->render("error.html", $params);
34
        $this->finish();
35
    }
36
37
    public function finish()
38
    {
39
        Session::commit();
40
        exit();
0 ignored issues
show
Coding Style Compatibility introduced by
The method finish() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
41
    }
42
}
43