| 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); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 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); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 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); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 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); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |                     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |         if ($display instanceof DisplayDatatablesAsync) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |             return $this->renderFindedTable($display, $application, $request); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 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') | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 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 |  |  |  | 
            
                        
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
@ignorePhpDoc annotation to the duplicate definition and it will be ignored.