Completed
Push — master ( b2a693...7e421d )
by Nekrasov
02:01
created

functions.php ➔ renderBladeTemplate()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 31
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 23
nc 2
nop 7
dl 0
loc 31
rs 8.8571
c 0
b 0
f 0
1
<?php
2
3
use Arrilot\BitrixBlade\BladeProvider;
4
5
if (!function_exists('renderBladeTemplate')) {
6
    /**
7
     * Render blade template callback.
8
     *
9
     * @param $templateFile
10
     * @param $arResult
11
     * @param $arParams
12
     * @param $arLangMessages
13
     * @param $templateFolder
14
     * @param $parentTemplateFolder
15
     * @param $template
16
     *
17
     * @return void
18
     */
19
    function renderBladeTemplate($templateFile, $arResult, $arParams, $arLangMessages, $templateFolder, $parentTemplateFolder, $template)
0 ignored issues
show
Coding Style introduced by
renderBladeTemplate uses the super-global variable $_SERVER which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
20
    {
21
        $view = BladeProvider::getViewFactory();
22
23
        BladeProvider::updateViewPaths($template->__folder);
24
25
        global $APPLICATION, $USER;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
26
27
        echo $view->file($_SERVER['DOCUMENT_ROOT'].$templateFile, compact(
28
            'arParams',
29
            'arResult',
30
            'arLangMessages',
31
            'template',
32
            'templateFolder',
33
            'parentTemplateFolder',
34
            'APPLICATION',
35
            'USER'
36
        ))->render();
37
38
        $epilogue = $templateFolder.'/component_epilog.php';
39
        if (file_exists($_SERVER['DOCUMENT_ROOT'].$epilogue)) {
40
            $component = $template->__component;
41
            $component->SetTemplateEpilog([
42
                'epilogFile'     => $epilogue,
43
                'templateName'   => $template->__name,
44
                'templateFile'   => $template->__file,
45
                'templateFolder' => $template->__folder,
46
                'templateData'   => false,
47
            ]);
48
        }
49
    }
50
}
51