IlluminateQueryDebugger::interpolateQuery()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 12
rs 9.8666
cc 3
nc 3
nop 2
1
<?php
2
3
namespace Arrilot\BitrixModels\Debug;
4
5
use Illuminate\Database\Capsule\Manager;
6
7
class IlluminateQueryDebugger
8
{
9
    public static function onAfterEpilogHandler()
10
    {
11
        global $DB, $USER;
12
13
        $bExcel = isset($_REQUEST["mode"]) && $_REQUEST["mode"] === 'excel';
14
        if (!defined("ADMIN_AJAX_MODE") && !defined('PUBLIC_AJAX_MODE') && !$bExcel) {
15
            $bShowStat = ($DB->ShowSqlStat && ($USER->CanDoOperation('edit_php') || $_SESSION["SHOW_SQL_STAT"]=="Y"));
16
            if ($bShowStat && class_exists(Manager::class) && Manager::logging()) {
17
                require_once(__DIR__.'/debug_info.php');
18
            }
19
        }
20
    }
21
    
22
    public static function interpolateQuery($query, $params)
23
    {
24
        $keys = array();
25
26
        # build a regular expression for each parameter
27
        foreach ($params as $key => $value) {
28
            $keys[] = is_string($key) ? '/:'.$key.'/' : '/[?]/';
29
            $params[$key] = "'" . $value . "'";
30
        }
31
    
32
        return preg_replace($keys, $params, $query, 1, $count);
33
    }
34
}
35