QueryController   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 8
Bugs 0 Features 5
Metric Value
wmc 4
eloc 14
c 8
b 0
f 5
dl 0
loc 32
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A explain() 0 12 2
A exec() 0 10 2
1
<?php
2
3
namespace Socialblue\LaravelQueryAdviser\Http\Controllers;
4
5
use Illuminate\Http\Request;
6
use Illuminate\Routing\Controller;
7
use Illuminate\Support\Facades\Cache;
8
use Illuminate\Support\Facades\DB;
9
use Socialblue\LaravelQueryAdviser\DataListener\Services\BindingsMapper;
10
use Socialblue\LaravelQueryAdviser\Helper\QueryBuilderHelper;
11
12
/**
13
 * Class QueryController
14
 * @package Socialblue\LaravelQueryAdviser\Http\Controllers
15
 */
16
class QueryController extends Controller
17
{
18
    /**
19
     * Execute query
20
     */
21
    public function exec(string $sessionKey, string $time, string $timeKey, Request $request): array
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

21
    public function exec(string $sessionKey, string $time, string $timeKey, /** @scrutinizer ignore-unused */ Request $request): array

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
22
    {
23
        $data = Cache::get($sessionKey);
24
25
        if (isset($data[$time][$timeKey])) {
26
            $query = $data[$time][$timeKey];
27
            return DB::connection()->select($query['rawSql'], (new BindingsMapper())->fromCache($query['bindings']));
28
        }
29
30
        return [];
31
    }
32
33
    /**
34
     * Use explain for query
35
     */
36
    public function explain(string $sessionKey, string $time, string $timeKey, Request $request): array
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

36
    public function explain(string $sessionKey, string $time, string $timeKey, /** @scrutinizer ignore-unused */ Request $request): array

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
37
    {
38
        $data = Cache::get($sessionKey);
39
        if (isset($data[$time][$timeKey])) {
40
            $query = $data[$time][$timeKey];
41
            return QueryBuilderHelper::analyze($query['rawSql'], (new BindingsMapper())->fromCache($query['bindings']));
42
        }
43
44
        return [
45
            'queryParts' => "",
46
            'query' => "",
47
            'optimized' => "",
48
        ];
49
    }
50
}
51