Completed
Push — master ( f471c7...2c4c63 )
by Nekrasov
01:27
created

IlluminateQueryDebugger   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 13
c 1
b 0
f 0
lcom 0
cbo 0
dl 0
loc 28
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
B onAfterEpilogHandler() 0 12 10
A interpolateQuery() 0 12 3
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()
0 ignored issues
show
Coding Style introduced by
onAfterEpilogHandler uses the super-global variable $_REQUEST 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...
Coding Style introduced by
onAfterEpilogHandler uses the super-global variable $_SESSION 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...
10
    {
11
        global $DB, $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...
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