Passed
Pull Request — master (#119)
by Mark
15:13
created

QueryController   A

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\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