PhpViewFileHelper::render()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 5
c 0
b 0
f 0
nc 1
nop 2
dl 0
loc 7
ccs 5
cts 5
cp 1
crap 1
rs 10
1
<?php
2
3
namespace Da\Mailer\Helper;
4
5
final class PhpViewFileHelper
6
{
7
    /**
8
     * Renders a view file as a PHP script.
9
     *
10
     * This method expects a php file and includes the file after it extracts the given parameters (name-value pairs)
11
     * to make them available to the php file. Captures the output and returns its result as a string.
12
     *
13
     * @param string $file full path of the view file
14
     * @param array $params the parameters that will be extracted and make them available to the php view file.
15
     *
16
     * @return string the rendering result.
17 2
     */
18
    public static function render($file, array $params = [])
19 2
    {
20 2
        ob_start();
21 2
        ob_implicit_flush(false);
22 2
        extract($params, EXTR_OVERWRITE);
23
        require $file;
24 2
        return ob_get_clean();
25
    }
26
}
27