BakeryController   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 8
eloc 15
c 0
b 0
f 0
dl 0
loc 55
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A graphiql() 0 7 2
A graphql() 0 7 1
A isExceptionHandlingDisabled() 0 5 1
A debug() 0 13 4
1
<?php
2
3
namespace Bakery\Http\Controllers;
4
5
use Bakery\Bakery;
6
use GraphQL\Error\Debug;
7
use Illuminate\Support\Str;
8
use Illuminate\Http\Request;
9
use Illuminate\Http\JsonResponse;
10
use Illuminate\Routing\Controller;
11
use Illuminate\Contracts\Debug\ExceptionHandler;
12
13
class BakeryController extends Controller
14
{
15
    protected function isExceptionHandlingDisabled()
16
    {
17
        $handler = app(ExceptionHandler::class);
18
19
        return Str::contains(get_class($handler), 'InteractsWithExceptionHandling');
20
    }
21
22
    protected function debug()
23
    {
24
        $debug = null;
25
26
        if (config('app.debug') or app()->runningUnitTests()) {
0 ignored issues
show
introduced by
The method runningUnitTests() does not exist on Illuminate\Container\Container. Are you sure you never get this type here, but always one of the subclasses? ( Ignorable by Annotation )

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

26
        if (config('app.debug') or app()->/** @scrutinizer ignore-call */ runningUnitTests()) {
Loading history...
27
            $debug = Debug::INCLUDE_DEBUG_MESSAGE;
28
        }
29
30
        if ($this->isExceptionHandlingDisabled()) {
31
            $debug = Debug::RETHROW_INTERNAL_EXCEPTIONS;
32
        }
33
34
        return $debug;
35
    }
36
37
    /**
38
     * Handle an HTTP response containing the GraphQL query.
39
     *
40
     * @param Request $request
41
     * @param \Bakery\Bakery $bakery
42
     * @return JsonResponse
43
     * @throws \Exception
44
     */
45
    public function graphql(Request $request, Bakery $bakery): JsonResponse
46
    {
47
        $input = $request->all();
48
49
        $data = $bakery->executeQuery($input)->toArray($this->debug());
50
51
        return response()->json($data, 200, []);
52
    }
53
54
    /**
55
     * Serve the GraphiQL tool.
56
     *
57
     * @param \Illuminate\Http\Request $request
58
     * @param \Bakery\Bakery $bakery
59
     * @return \Illuminate\Contracts\View\View
60
     */
61
    public function graphiql(Request $request, Bakery $bakery)
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

61
    public function graphiql(/** @scrutinizer ignore-unused */ Request $request, Bakery $bakery)

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...
62
    {
63
        if (! app()->isLocal()) {
0 ignored issues
show
introduced by
The method isLocal() does not exist on Illuminate\Container\Container. Are you sure you never get this type here, but always one of the subclasses? ( Ignorable by Annotation )

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

63
        if (! app()->/** @scrutinizer ignore-call */ isLocal()) {
Loading history...
64
            abort(404);
65
        }
66
67
        return $bakery->graphiql('bakery.graphql');
68
    }
69
}
70