Completed
Push — master ( 9d700f...b6792d )
by Mark
24s queued 13s
created

QueryController::index()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
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\Helper\QueryBuilderHelper;
10
11
/**
12
 * Class QueryController
13
 * @package Socialblue\LaravelQueryAdviser\Http\Controllers
14
 */
15
class QueryController extends Controller
16
{
17
    /**
18
     * Execute query
19
     */
20
    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

20
    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...
21
    {
22
        $data = Cache::get($sessionKey);
23
24
        if (isset($data[$time][$timeKey])) {
25
            $query = $data[$time][$timeKey];
26
            return DB::connection()->select($query['rawSql'], $query['bindings']);
27
        }
28
29
        return [];
30
    }
31
32
    /**
33
     * Use explain for query
34
     */
35
    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

35
    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...
36
    {
37
        $data = Cache::get($sessionKey);
38
        if (isset($data[$time][$timeKey])) {
39
            $query = $data[$time][$timeKey];
40
            return QueryBuilderHelper::analyze($query['rawSql'], $query['bindings']);
41
        }
42
43
        return [
44
            'queryParts' => "",
45
            'query' => "",
46
            'optimized' => "",
47
        ];
48
    }
49
}
50