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 — merge-dev-to-master ( fdc6fe )
by
unknown
11:18
created

AlterPaginateDisplayController::async()   C

Complexity

Conditions 15
Paths 9

Size

Total Lines 49
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 15
eloc 22
c 1
b 0
f 0
nc 9
nop 4
dl 0
loc 49
rs 5.9166

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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\Form\Columns\Column;
10
use SleepingOwl\Admin\Display\DisplayTabbed;
11
use Illuminate\Contracts\Foundation\Application;
12
use SleepingOwl\Admin\Contracts\ModelConfigurationInterface;
13
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
14
use SleepingOwl\Admin\Display\DisplayDatatablesAsyncAlterPaginate;
15
16
class AlterPaginateDisplayController extends Controller
17
{
18
    /**
19
     * @param ModelConfigurationInterface $model
20
     * @param Request $request
21
     * @param Application $application
22
     * @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...
23
     * @return JsonResponse
24
     * @throws NotFoundHttpException
25
     */
26
    public function async(ModelConfigurationInterface $model, Request $request, Application $application, $name = null)
27
    {
28
        $payload = $request->payload ?: [];
29
30
        $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

30
        /** @scrutinizer ignore-call */ 
31
        $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...
31
32
        if ($display instanceof DisplayTabbed) {
33
            $tabs = $display->getTabs();
34
35
            foreach ($tabs as $tab) {
36
                $content = $tab->getContent();
37
38
                if ($content instanceof FormElements) {
39
                    foreach ($content->getElements() as $element) {
40
41
                        //Return data-table if inside FormElements
42
                        if ($element instanceof DisplayDatatablesAsyncAlterPaginate) {
43
                            if ($element->getName() == $name) {
44
                                return $this->renderFindedTable($element, $application, $request);
45
                            }
46
                        }
47
48
                        //Try to find data table in columns
49
                        if ($element instanceof Column) {
50
                            foreach ($element->getElements() as $columnElement) {
51
                                if ($columnElement instanceof DisplayDatatablesAsyncAlterPaginate) {
52
                                    if ($columnElement->getName() == $name) {
53
                                        return $this->renderFindedTable($columnElement, $application, $request);
54
                                    }
55
                                }
56
                            }
57
                        }
58
                    }
59
                }
60
61
                //Finded trully in content-tab
62
                if ($content instanceof DisplayDatatablesAsyncAlterPaginate) {
63
                    if ($content->getName() == $name) {
64
                        return $this->renderFindedTable($content, $application, $request);
65
                    }
66
                }
67
            }
68
        }
69
70
        if ($display instanceof DisplayDatatablesAsyncAlterPaginate) {
71
            return $this->renderFindedTable($display, $application, $request);
72
        }
73
74
        abort(404);
75
    }
76
77
    /**
78
     * @param ModelConfigurationInterface $model
79
     * @param Request $request
80
     */
81
    public function treeReorder(ModelConfigurationInterface $model, Request $request)
82
    {
83
        $display = $model->fireDisplay();
84
85
        if ($display instanceof DisplayTabbed) {
86
            $display->getTabs()->each(function (DisplayTab $tab) use ($request) {
0 ignored issues
show
Bug introduced by
The type SleepingOwl\Admin\Http\Controllers\DisplayTab was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
87
                $content = $tab->getContent();
88
                if ($content instanceof DisplayTree) {
0 ignored issues
show
Bug introduced by
The type SleepingOwl\Admin\Http\Controllers\DisplayTree was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
89
                    $content->getRepository()->reorder(
90
                        $request->input('data')
91
                    );
92
                }
93
            });
94
        } else {
95
            $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

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