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.
Passed
Push — master ( b2510c...ee0bb8 )
by
unknown
12:46
created

DisplayController   A

Complexity

Total Complexity 21

Size/Duplication

Total Lines 105
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 11

Test Coverage

Coverage 0%

Importance

Changes 4
Bugs 1 Features 0
Metric Value
dl 0
loc 105
c 4
b 1
f 0
ccs 0
cts 68
cp 0
rs 10
wmc 21
lcom 0
cbo 11

3 Methods

Rating   Name   Duplication   Size   Complexity  
C async() 0 50 15
A treeReorder() 0 19 3
A renderFindedTable() 0 12 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\DisplayTree;
10
use SleepingOwl\Admin\Form\Columns\Column;
11
use SleepingOwl\Admin\Display\DisplayTabbed;
12
use Illuminate\Contracts\Foundation\Application;
13
use SleepingOwl\Admin\Display\DisplayDatatablesAsync;
14
use SleepingOwl\Admin\Contracts\ModelConfigurationInterface;
15
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
16
17
class DisplayController extends Controller
18
{
19
    /**
20
     * @param ModelConfigurationInterface $model
21
     * @param Request $request
22
     * @param Application $application
23
     * @param null $name
24
     * @throws NotFoundHttpException
25
     *
26
     * @return JsonResponse
27
     */
28
    public function async(ModelConfigurationInterface $model, Request $request, Application $application, $name = null)
29
    {
30
        $payload = $request->payload ?: [];
31
32
        $display = $model->fireDisplay($payload);
0 ignored issues
show
Unused Code introduced by
The call to ModelConfigurationInterface::fireDisplay() has too many arguments starting with $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.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
33
34
        if ($display instanceof DisplayTabbed) {
35
            $tabs = $display->getTabs();
36
37
            foreach ($tabs as $tab) {
38
                $content = $tab->getContent();
39
40
                if ($content instanceof FormElements) {
41
                    foreach ($content->getElements() as $element) {
42
43
                        //Return data-table if inside FormElements
44
                        if ($element instanceof DisplayDatatablesAsync) {
45
                            if ($element->getName() == $name) {
46
                                return $this->renderFindedTable($element, $application, $request);
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->renderFindedTable...application, $request); of type array<string,string|arra...inate\Http\JsonResponse adds the type array<string,string|array|integer> to the return on line 46 which is incompatible with the return type documented by SleepingOwl\Admin\Http\C...isplayController::async of type Illuminate\Http\JsonResponse|null.
Loading history...
47
                            }
48
                        }
49
50
                        //Try to find data table in columns
51
                        if ($element instanceof Column) {
52
                            foreach ($element->getElements() as $columnElement) {
53
                                if ($columnElement instanceof DisplayDatatablesAsync) {
54
                                    if ($columnElement->getName() == $name) {
55
                                        return $this->renderFindedTable($columnElement, $application, $request);
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->renderFindedTable...application, $request); of type array<string,string|arra...inate\Http\JsonResponse adds the type array<string,string|array|integer> to the return on line 55 which is incompatible with the return type documented by SleepingOwl\Admin\Http\C...isplayController::async of type Illuminate\Http\JsonResponse|null.
Loading history...
56
                                    }
57
                                }
58
                            }
59
                        }
60
                    }
61
                }
62
63
                //Finded trully in content-tab
64
                if ($content instanceof DisplayDatatablesAsync) {
65
                    if ($content->getName() == $name) {
66
                        return $this->renderFindedTable($content, $application, $request);
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->renderFindedTable...application, $request); of type array<string,string|arra...inate\Http\JsonResponse adds the type array<string,string|array|integer> to the return on line 66 which is incompatible with the return type documented by SleepingOwl\Admin\Http\C...isplayController::async of type Illuminate\Http\JsonResponse|null.
Loading history...
67
                    }
68
                }
69
            }
70
        }
71
72
        if ($display instanceof DisplayDatatablesAsync) {
73
            return $this->renderFindedTable($display, $application, $request);
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->renderFindedTable...application, $request); of type array<string,string|arra...inate\Http\JsonResponse adds the type array<string,string|array|integer> to the return on line 73 which is incompatible with the return type documented by SleepingOwl\Admin\Http\C...isplayController::async of type Illuminate\Http\JsonResponse|null.
Loading history...
74
        }
75
76
        abort(404);
77
    }
78
79
    /**
80
     * @param ModelConfigurationInterface $model
81
     * @param Request $request
82
     */
83
    public function treeReorder(ModelConfigurationInterface $model, Request $request)
84
    {
85
        $display = $model->fireDisplay();
86
87
        if ($display instanceof DisplayTabbed) {
88
            $display->getTabs()->each(function ($tab) use ($request) {
89
                $content = $tab->getContent();
90
                if ($content instanceof DisplayTree) {
91
                    $content->getRepository()->reorder(
92
                        $request->input('data')
0 ignored issues
show
Bug introduced by
It seems like $request->input('data') targeting Illuminate\Http\Concerns...ractsWithInput::input() can also be of type string; however, SleepingOwl\Admin\Contra...oryInterface::reorder() does only seem to accept array, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

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