GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Branch master (9e3162)
by Dave
63:34
created

DisplayController   A

Complexity

Total Complexity 21

Size/Duplication

Total Lines 106
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 43
dl 0
loc 106
ccs 0
cts 69
cp 0
rs 10
c 0
b 0
f 0
wmc 21

3 Methods

Rating   Name   Duplication   Size   Complexity  
C async() 0 49 15
A treeReorder() 0 16 3
A renderFindedTable() 0 14 3
1
<?php
2
3
namespace SleepingOwl\Admin\Http\Controllers;
4
5
use Illuminate\Http\Request;
6
use Illuminate\Http\JsonResponse;
7
use Illuminate\Routing\Controller;
8
use SleepingOwl\Admin\Form\FormElements;
9
use SleepingOwl\Admin\Display\DisplayTab;
10
use SleepingOwl\Admin\Display\DisplayTree;
11
use SleepingOwl\Admin\Form\Columns\Column;
12
use SleepingOwl\Admin\Display\DisplayTabbed;
13
use Illuminate\Contracts\Foundation\Application;
14
use SleepingOwl\Admin\Display\DisplayDatatablesAsync;
15
use SleepingOwl\Admin\Contracts\ModelConfigurationInterface;
16
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
17
18
class DisplayController extends Controller
19
{
20
    /**
21
     * @param ModelConfigurationInterface $model
22
     * @param Request $request
23
     * @param Application $application
24
     * @param null $name
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $name is correct as it would always require null to be passed?
Loading history...
25
     * @throws NotFoundHttpException
26
     *
27
     * @return JsonResponse
28
     */
29
    public function async(ModelConfigurationInterface $model, Request $request, Application $application, $name = null)
30
    {
31
        $payload = $request->payload ?: [];
32
33
        $display = $model->fireDisplay($payload);
0 ignored issues
show
Unused Code introduced by
The call to SleepingOwl\Admin\Contra...nterface::fireDisplay() has too many arguments starting with $payload. ( Ignorable by Annotation )

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

33
        /** @scrutinizer ignore-call */ 
34
        $display = $model->fireDisplay($payload);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
34
35
        if ($display instanceof DisplayTabbed) {
36
            $tabs = $display->getTabs();
37
38
            foreach ($tabs as $tab) {
39
                $content = $tab->getContent();
40
41
                if ($content instanceof FormElements) {
42
                    foreach ($content->getElements() as $element) {
43
44
                        //Return data-table if inside FormElements
45
                        if ($element instanceof DisplayDatatablesAsync) {
46
                            if ($element->getName() == $name) {
47
                                return $this->renderFindedTable($element, $application, $request);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->renderFind...$application, $request) also could return the type array which is incompatible with the documented return type Illuminate\Http\JsonResponse.
Loading history...
48
                            }
49
                        }
50
51
                        //Try to find data table in columns
52
                        if ($element instanceof Column) {
53
                            foreach ($element->getElements() as $columnElement) {
54
                                if ($columnElement instanceof DisplayDatatablesAsync) {
55
                                    if ($columnElement->getName() == $name) {
56
                                        return $this->renderFindedTable($columnElement, $application, $request);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->renderFind...$application, $request) also could return the type array which is incompatible with the documented return type Illuminate\Http\JsonResponse.
Loading history...
57
                                    }
58
                                }
59
                            }
60
                        }
61
                    }
62
                }
63
64
                //Finded trully in content-tab
65
                if ($content instanceof DisplayDatatablesAsync) {
66
                    if ($content->getName() == $name) {
67
                        return $this->renderFindedTable($content, $application, $request);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->renderFind...$application, $request) also could return the type array which is incompatible with the documented return type Illuminate\Http\JsonResponse.
Loading history...
68
                    }
69
                }
70
            }
71
        }
72
73
        if ($display instanceof DisplayDatatablesAsync) {
74
            return $this->renderFindedTable($display, $application, $request);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->renderFind...$application, $request) also could return the type array which is incompatible with the documented return type Illuminate\Http\JsonResponse.
Loading history...
75
        }
76
77
        abort(404);
78
    }
79
80
    /**
81
     * @param ModelConfigurationInterface $model
82
     * @param Request $request
83
     */
84
    public function treeReorder(ModelConfigurationInterface $model, Request $request)
85
    {
86
        $display = $model->fireDisplay();
87
88
        if ($display instanceof DisplayTabbed) {
89
            $display->getTabs()->each(function (DisplayTab $tab) use ($request) {
90
                $content = $tab->getContent();
91
                if ($content instanceof DisplayTree) {
92
                    $content->getRepository()->reorder(
93
                        $request->input('data')
94
                    );
95
                }
96
            });
97
        } else {
98
            $display->getRepository()->reorder(
0 ignored issues
show
Bug introduced by
The method getRepository() does not exist on SleepingOwl\Admin\Contra...isplay\DisplayInterface. It seems like you code against a sub-type of SleepingOwl\Admin\Contra...isplay\DisplayInterface such as SleepingOwl\Admin\Form\FormDefault or SleepingOwl\Admin\Display\Display. ( Ignorable by Annotation )

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

98
            $display->/** @scrutinizer ignore-call */ 
99
                      getRepository()->reorder(
Loading history...
99
                $request->input('data')
100
            );
101
        }
102
    }
103
104
    /**
105
     * @param DisplayDatatablesAsync $datatable
106
     * @param Application $application
107
     * @param Request $request
108
     * @return array|JsonResponse
109
     */
110
    protected function renderFindedTable(DisplayDatatablesAsync $datatable, Application $application, Request $request)
111
    {
112
        try {
113
            return $datatable->renderAsync($request);
114
        } catch (\Exception $exception) {
115
            \Log::error('unable to render finded table!', [
116
                'exception' => $exception,
117
            ]);
118
119
            return new JsonResponse([
120
                'message' => $application->isLocal()
121
                    ? $exception->getMessage()
122
                    : trans('sleeping_owl::lang.table.error'),
123
            ], 403);
124
        }
125
    }
126
}
127