page_builder   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 24
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A render() 0 6 1
A __construct() 0 2 1
A return_template_replace() 0 8 2
1
<?php
2
3
/**
4
* @Auther: bhief
5
* @Version: 1.0
6
*
7
* Builds pages
8
*
9
**/
10
class page_builder {
11
    public $__root;
12
13
	public function __construct($templates){
14
        $this->__root = $templates;
15
	}
16
17
    function return_template_replace(string $template, array $inputs) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
18
        $__template_file = file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/" . $this->__root . "/" . $template);
19
20
        foreach($inputs as $key => $input) {
21
            $__template_file = str_replace("{{" . $key . "}}", $input, $__template_file);
22
        }
23
24
        return $__template_file;
25
    }
26
27
    /* Thanks https://stackoverflow.com/questions/1309800/php-eval-that-evaluates-html-php */
28
    function render($script, array $vars = array()) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
29
        extract($vars);
30
31
        ob_start();
32
        require $script;
33
        return ob_get_clean();
34
    }
35
}
36
37
?>
0 ignored issues
show
Best Practice introduced by
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...