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

AdminController::deleteDestroy()   A

Complexity

Conditions 5
Paths 8

Size

Total Lines 24
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 0
Metric Value
cc 5
eloc 12
nc 8
nop 3
dl 0
loc 24
ccs 0
cts 0
cp 0
crap 30
rs 9.5555
c 0
b 0
f 0
1
<?php
2
3
namespace SleepingOwl\Admin\Http\Controllers;
4
5
use Illuminate\Http\Request;
6
use Illuminate\Routing\Controller;
7
use Illuminate\Http\RedirectResponse;
8
use SleepingOwl\Admin\Form\FormElements;
9
use DaveJamesMiller\Breadcrumbs\Generator;
10
use SleepingOwl\Admin\Form\Columns\Column;
11
use SleepingOwl\Admin\Display\DisplayTable;
12
use Illuminate\Contracts\Support\Renderable;
13
use SleepingOwl\Admin\Display\DisplayTabbed;
14
use Illuminate\Validation\ValidationException;
15
use SleepingOwl\Admin\Contracts\AdminInterface;
16
use SleepingOwl\Admin\Model\ModelConfiguration;
17
use Illuminate\Contracts\Foundation\Application;
18
use SleepingOwl\Admin\Contracts\Form\FormInterface;
19
use SleepingOwl\Admin\Contracts\ModelConfigurationInterface;
20
use SleepingOwl\Admin\Contracts\Display\ColumnEditableInterface;
21
22
class AdminController extends Controller
23
{
24
    /**
25
     * @var \DaveJamesMiller\Breadcrumbs\Manager
26
     */
27
    protected $breadcrumbs;
28
29
    /**
30
     * @var
31
     */
32
    protected $breadCrumbsData;
33
34
    /**
35
     * @var AdminInterface
36
     */
37
    protected $admin;
38
39
    /**
40
     * @var
41
     */
42
    private $parentBreadcrumb = 'home';
43
44
    /**
45
     * @var Application
46
     */
47
    public $app;
48
49
    /**
50
     * @var
51
     */
52
    protected $envPolicy;
53
54
    /**
55
     * AdminController constructor.
56
     *
57
     * @param Request $request
58
     * @param AdminInterface $admin
59
     * @param Application $application
60
     */
61
    public function __construct(Request $request, AdminInterface $admin, Application $application)
62
    {
63
        $this->app = $application;
64
        $this->admin = $admin;
65
        $this->breadcrumbs = $admin->template()->breadcrumbs();
66
67
        if ($this->envPolicy = config('sleeping_owl.env_editor_policy')) {
68
            $this->envPolicy = new $this->envPolicy;
69
        }
70
71
        $admin->navigation()->setCurrentUrl($request->getUri());
0 ignored issues
show
Bug introduced by
The method setCurrentUrl() does not exist on SleepingOwl\Admin\Contra...ion\NavigationInterface. It seems like you code against a sub-type of said class. However, the method does not exist in SleepingOwl\Admin\Contra...avigation\PageInterface. Are you sure you never get one of those? ( Ignorable by Annotation )

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

71
        $admin->navigation()->/** @scrutinizer ignore-call */ setCurrentUrl($request->getUri());
Loading history...
72
73
        if (! $this->breadcrumbs->exists('home')) {
74
            $this->breadcrumbs->register('home', function (Generator $breadcrumbs) {
75
                $breadcrumbs->push(trans('sleeping_owl::lang.dashboard'), route('admin.dashboard'));
76
            });
77
        }
78
79
        $this->breadCrumbsData = [];
80
81
        if ($currentPage = $admin->navigation()->getCurrentPage()) {
82
            foreach ($currentPage->getPathArray() as $page) {
83
                $this->breadCrumbsData[] = [
84
                    'id'     => $page['id'],
85
                    'title'  => $page['title'],
86
                    'url'    => $page['url'],
87
                    'parent' => $this->parentBreadcrumb,
88
                ];
89
90
                $this->parentBreadcrumb = $page['id'];
91
            }
92
        }
93
    }
94
95
    /**
96
     * @return string
97
     */
98
    public function getParentBreadcrumb()
99
    {
100
        return $this->parentBreadcrumb;
101
    }
102
103
    /**
104
     * @param string $parentBreadcrumb
105
     */
106
    public function setParentBreadcrumb($parentBreadcrumb)
107
    {
108
        $this->parentBreadcrumb = $parentBreadcrumb;
109
    }
110
111
    /**
112
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
113
     */
114
    public function getDashboard()
115
    {
116
        return $this->renderContent(
117
            $this->admin->template()->view('dashboard'),
0 ignored issues
show
Bug introduced by
It seems like $this->admin->template()->view('dashboard') can also be of type Illuminate\Contracts\View\Factory; however, parameter $content of SleepingOwl\Admin\Http\C...roller::renderContent() does only seem to accept string|Illuminate\Contracts\Support\Renderable, maybe add an additional type check? ( Ignorable by Annotation )

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

117
            /** @scrutinizer ignore-type */ $this->admin->template()->view('dashboard'),
Loading history...
118
            trans('sleeping_owl::lang.dashboard')
0 ignored issues
show
Bug introduced by
It seems like trans('sleeping_owl::lang.dashboard') can also be of type array; however, parameter $title of SleepingOwl\Admin\Http\C...roller::renderContent() does only seem to accept null|string, maybe add an additional type check? ( Ignorable by Annotation )

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

118
            /** @scrutinizer ignore-type */ trans('sleeping_owl::lang.dashboard')
Loading history...
119
        );
120
    }
121
122
    /**
123
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
124
     */
125
    public function getEnvEditor()
126
    {
127
        $envFile = app()->environmentFilePath();
0 ignored issues
show
introduced by
The method environmentFilePath() 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

127
        $envFile = app()->/** @scrutinizer ignore-call */ environmentFilePath();
Loading history...
128
        $envContent = collect(parse_ini_file($envFile, false, INI_SCANNER_RAW));
129
130
        /**
131
         * Use filter masks.
132
         * @param $key
133
         * @return bool
134
         */
135
        $envContent = $envContent->filter(function ($value, $key) {
136
            return ! in_array($key, config('sleeping_owl.env_editor_excluded_keys')) && ! $this->filterKey($key);
137
        });
138
139
        $envContent = $envContent->filter(function ($value, $key) {
140
            return $this->validatePolicy('display', $key);
141
        });
142
143
        $envContent = $envContent->map(function ($value, $key) {
144
            return (object) [
145
                'value'     => $value,
146
                'editable'  => $this->validatePolicy('edit', $key),
147
                'deletable' => $this->validatePolicy('delete', $key),
148
            ];
149
        });
150
151
        return $this->renderContent(
152
            $this->admin->template()->view('env_editor', ['data' => $envContent]),
0 ignored issues
show
Bug introduced by
It seems like $this->admin->template()...'data' => $envContent)) can also be of type Illuminate\Contracts\View\Factory; however, parameter $content of SleepingOwl\Admin\Http\C...roller::renderContent() does only seem to accept string|Illuminate\Contracts\Support\Renderable, maybe add an additional type check? ( Ignorable by Annotation )

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

152
            /** @scrutinizer ignore-type */ $this->admin->template()->view('env_editor', ['data' => $envContent]),
Loading history...
153
            trans('sleeping_owl::lang.env_editor.title')
0 ignored issues
show
Bug introduced by
It seems like trans('sleeping_owl::lang.env_editor.title') can also be of type array; however, parameter $title of SleepingOwl\Admin\Http\C...roller::renderContent() does only seem to accept null|string, maybe add an additional type check? ( Ignorable by Annotation )

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

153
            /** @scrutinizer ignore-type */ trans('sleeping_owl::lang.env_editor.title')
Loading history...
154
        );
155
    }
156
157
    /**
158
     * @param $permission
159
     * @param $key
160
     * @return bool
161
     */
162
    protected function validatePolicy($permission, $key)
163
    {
164
        return ($this->envPolicy && ((method_exists($this->envPolicy, $permission)
165
                    && $this->envPolicy->$permission(\Auth::user(), $key) !== false)))
166
            || ! method_exists($this->envPolicy, $permission) || ! $this->envPolicy || $this->validateBeforePolicy($key);
167
    }
168
169
    /**
170
     * @param $key
171
     * @return bool
172
     */
173
    protected function validateBeforePolicy($key)
174
    {
175
        return ($this->envPolicy && (method_exists($this->envPolicy, 'before'))
176
                && $this->envPolicy->before(\Auth::user(), $key) == true)
177
            || ! method_exists($this->envPolicy, 'before') || ! $this->envPolicy;
178
    }
179
180
    /**
181
     * @param Request $request
182
     * @return \Illuminate\Http\RedirectResponse
183
     */
184
    public function postEnvEditor(Request $request)
185
    {
186
        $envFile = app()->environmentFilePath();
187
        $envContent = collect(parse_ini_file($envFile, false, INI_SCANNER_RAW));
188
189
        $requestContent = collect($request->input('variables'));
190
        $removeContent = collect();
191
192
        foreach ($envContent as $key => $value) {
193
            if (! in_array($key, config('sleeping_owl.env_editor_excluded_keys')) && ! $this->filterKey($key)) {
194
                if ($requestContent->has($key)) {
195
                    if ($this->validatePolicy('edit', $key)) {
196
                        $envContent[$key] = $requestContent[$key]['value'];
197
                    }
198
                    $requestContent->forget($key);
199
                } else {
200
                    $envContent->forget($key);
201
                    $removeContent->put($key, null);
202
                }
203
            }
204
        }
205
206
        foreach ($requestContent as $key => $value) {
207
            if (! in_array($key, config('sleeping_owl.env_editor_excluded_keys')) && ! $this->filterKey($key)
208
                && $this->validatePolicy('create', $key)) {
209
                $this->writeEnvData($key, $value['value'], 1);
210
            }
211
            $requestContent->forget($key);
212
        }
213
214
        foreach ($removeContent as $key => $value) {
215
            if ($this->validatePolicy('delete', $key)) {
216
                $this->writeEnvData($key);
217
            }
218
        }
219
220
        foreach ($envContent as $key => $value) {
221
            $this->writeEnvData($key, $value);
222
        }
223
224
        return redirect()->back()->with('success_message', 'Env Updated');
225
    }
226
227
    /**
228
     * @param $key
229
     * @return bool
230
     */
231
    public function filterKey($key)
232
    {
233
        foreach (config('sleeping_owl.env_editor_excluded_keys') as $val) {
234
            if (strpos($val, '*') !== false) {
235
                $val = str_replace('*', '', $val);
236
                if (strpos($key, $val) !== false) {
237
                    return true;
238
                }
239
            }
240
        }
241
242
        return false;
243
    }
244
245
    /**
246
     * @param $key
247
     * @param null $data
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $data is correct as it would always require null to be passed?
Loading history...
248
     * @param bool $new
249
     * @return bool
250
     */
251
    public function writeEnvData($key, $data = null, $new = null)
252
    {
253
        $envFile = app()->environmentFilePath();
254
        $str = file_get_contents($envFile);
255
256
        if (is_null($data)) {
257
            $str = preg_replace("/$key=.*/m", '', $str);
258
            file_put_contents($envFile, $str);
259
260
            return false;
261
        }
262
263
        if (is_null($new)) {
264
            $str = preg_replace("/$key=.*/m", "$key=$data", $str);
265
            file_put_contents($envFile, $str);
266
267
            return false;
268
        }
269
270
        $str = $str."\r\n$key=$data";
271
        file_put_contents($envFile, $str);
272
273
        return true;
274
    }
275
276
    /**
277
     * @param ModelConfigurationInterface $model
278
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
279
     * @throws \DaveJamesMiller\Breadcrumbs\Exception
280
     */
281
    public function getDisplay(ModelConfigurationInterface $model)
282
    {
283
        if (! $model->isDisplayable()) {
284
            abort(404);
285
        }
286
287
        $display = $model->fireDisplay();
288
289
        $this->registerBreadcrumbs($model);
290
291
        return $this->render($model, $display);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->render($model, $display) also could return the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type Illuminate\View\View|Ill...\Contracts\View\Factory.
Loading history...
292
    }
293
294
    /**
295
     * @param ModelConfigurationInterface $model
296
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
297
     * @throws \DaveJamesMiller\Breadcrumbs\Exception
298
     */
299
    public function getCreate(ModelConfigurationInterface $model)
300
    {
301
        if (! $model->isCreatable()) {
302
            abort(404);
303
        }
304
305
        $create = $model->fireCreate();
306
307
        $this->registerBreadcrumb($model->getCreateTitle(), $this->parentBreadcrumb);
308
        $this->registerBreadcrumbs($model);
309
310
        return $this->render($model, $create, $model->getCreateTitle());
0 ignored issues
show
Bug introduced by
It seems like $model->getCreateTitle() can also be of type Symfony\Component\Translation\TranslatorInterface; however, parameter $title of SleepingOwl\Admin\Http\C...minController::render() does only seem to accept null|string, maybe add an additional type check? ( Ignorable by Annotation )

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

310
        return $this->render($model, $create, /** @scrutinizer ignore-type */ $model->getCreateTitle());
Loading history...
Bug Best Practice introduced by
The expression return $this->render($mo...odel->getCreateTitle()) also could return the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type Illuminate\View\View|Ill...\Contracts\View\Factory.
Loading history...
311
    }
312
313
    /**
314
     * @param ModelConfigurationInterface $model
315
     * @param Request $request
316
     *
317
     * @return \Illuminate\Http\RedirectResponse
318
     */
319
    public function postStore(ModelConfigurationInterface $model, Request $request)
320
    {
321
        if (! $model->isCreatable()) {
322
            abort(404);
323
        }
324
325
        $createForm = $model->fireCreate();
326
        $nextAction = $request->input('next_action');
327
328
        $backUrl = $this->getBackUrl($request);
329
330
        if ($createForm instanceof FormInterface) {
331
            try {
332
                $createForm->validateForm($request, $model);
333
334
                if ($createForm->saveForm($request, $model) === false) {
0 ignored issues
show
Bug introduced by
Are you sure the usage of $createForm->saveForm($request, $model) targeting SleepingOwl\Admin\Contra...rmInterface::saveForm() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
introduced by
The condition $createForm->saveForm($request, $model) === false is always true.
Loading history...
335
                    return redirect()->back()->with([
336
                        '_redirectBack'       => $backUrl,
337
                        'sleeping_owl_tab_id' => $request->get('sleeping_owl_tab_id') ?: null,
338
                    ]);
339
                }
340
            } catch (ValidationException $exception) {
341
                return redirect()->back()
342
                    ->withErrors($exception->validator)
343
                    ->withInput()
344
                    ->with([
345
                        '_redirectBack'       => $backUrl,
346
                        'sleeping_owl_tab_id' => $request->get('sleeping_owl_tab_id') ?: null,
347
                    ]);
348
            }
349
        }
350
351
        if ($nextAction == 'save_and_continue') {
352
            $newModel = $createForm->getModel();
353
            $primaryKey = $newModel->getKeyName();
354
355
            $redirectUrl = $model->getEditUrl($newModel->{$primaryKey});
356
            $redirectPolicy = $model->getRedirect();
357
358
            /* Make redirect when use in model config && Fix editable redirect */
359
            if ($redirectPolicy->get('create') == 'display' || ! $model->isEditable($newModel)) {
360
                $redirectUrl = $model->getDisplayUrl();
361
            }
362
363
            $response = redirect()->to(
364
                $redirectUrl
365
            )->with([
366
                '_redirectBack'       => $backUrl,
367
                'sleeping_owl_tab_id' => $request->get('sleeping_owl_tab_id') ?: null,
368
            ]);
369
        } elseif ($nextAction == 'save_and_create') {
370
            $response = redirect()->to($model->getCreateUrl($request->except([
371
                '_redirectBack',
372
                '_token',
373
                'url',
374
                'next_action',
375
            ])))->with([
376
                '_redirectBack'       => $backUrl,
377
                'sleeping_owl_tab_id' => $request->get('sleeping_owl_tab_id') ?: null,
378
            ]);
379
        } else {
380
            $response = redirect()->to($request->input('_redirectBack', $model->getDisplayUrl()));
381
        }
382
383
        return $response->with('success_message', $model->getMessageOnCreate());
384
    }
385
386
    /**
387
     * @param ModelConfigurationInterface $model
388
     * @param $id
389
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
390
     * @throws \DaveJamesMiller\Breadcrumbs\Exception
391
     */
392
    public function getEdit(ModelConfigurationInterface $model, $id)
393
    {
394
        $item = $model->getRepository()->find($id);
395
396
        if (is_null($item) || ! $model->isEditable($item)) {
397
            abort(404);
398
        }
399
400
        $this->registerBreadcrumb($model->getEditTitle(), $this->parentBreadcrumb);
401
402
        $edit = $model->fireEdit($id);
403
404
        $this->registerBreadcrumbs($model);
405
406
        return $this->render($model, $edit, $model->getEditTitle());
0 ignored issues
show
Bug introduced by
It seems like $model->getEditTitle() can also be of type Symfony\Component\Translation\TranslatorInterface; however, parameter $title of SleepingOwl\Admin\Http\C...minController::render() does only seem to accept null|string, maybe add an additional type check? ( Ignorable by Annotation )

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

406
        return $this->render($model, $edit, /** @scrutinizer ignore-type */ $model->getEditTitle());
Loading history...
Bug Best Practice introduced by
The expression return $this->render($mo...$model->getEditTitle()) also could return the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type Illuminate\View\View|Ill...\Contracts\View\Factory.
Loading history...
407
    }
408
409
    /**
410
     * @param ModelConfigurationInterface $model
411
     * @param Request $request
412
     * @param int $id
413
     *
414
     * @return \Illuminate\Http\RedirectResponse
415
     *
416
     * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
417
     */
418
    public function postUpdate(ModelConfigurationInterface $model, Request $request, $id)
419
    {
420
        /** @var FormInterface $editForm */
421
        $editForm = $model->fireEdit($id);
422
        $item = $editForm->getModel();
423
424
        if (is_null($item) || ! $model->isEditable($item)) {
425
            abort(404);
426
        }
427
428
        $nextAction = $request->input('next_action');
429
430
        $backUrl = $this->getBackUrl($request);
431
432
        if ($editForm instanceof FormInterface) {
0 ignored issues
show
introduced by
$editForm is always a sub-type of SleepingOwl\Admin\Contracts\Form\FormInterface. If $editForm can have other possible types, add them to src/Http/Controllers/AdminController.php:420.
Loading history...
433
            try {
434
                $editForm->validateForm($request, $model);
435
436
                if ($editForm->saveForm($request, $model) === false) {
0 ignored issues
show
introduced by
The condition $editForm->saveForm($request, $model) === false is always true.
Loading history...
Bug introduced by
Are you sure the usage of $editForm->saveForm($request, $model) targeting SleepingOwl\Admin\Contra...rmInterface::saveForm() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
437
                    return redirect()->back()->with([
438
                        '_redirectBack'       => $backUrl,
439
                        'sleeping_owl_tab_id' => $request->get('sleeping_owl_tab_id') ?: null,
440
                    ]);
441
                }
442
            } catch (ValidationException $exception) {
443
                return redirect()->back()
444
                    ->withErrors($exception->validator)
445
                    ->withInput()
446
                    ->with([
447
                        '_redirectBack'       => $backUrl,
448
                        'sleeping_owl_tab_id' => $request->get('sleeping_owl_tab_id') ?: null,
449
                    ]);
450
            }
451
        }
452
453
        $redirectPolicy = $model->getRedirect();
454
455
        if ($nextAction == 'save_and_continue') {
456
            $response = redirect()->back()->with([
457
                '_redirectBack'       => $backUrl,
458
                'sleeping_owl_tab_id' => $request->get('sleeping_owl_tab_id') ?: null,
459
            ]);
460
461
            if ($redirectPolicy->get('edit') == 'display') {
462
                $response = redirect()->to(
463
                    $model->getDisplayUrl()
464
                )->with([
465
                    '_redirectBack'       => $backUrl,
466
                    'sleeping_owl_tab_id' => $request->get('sleeping_owl_tab_id') ?: null,
467
                ]);
468
            }
469
        } elseif ($nextAction == 'save_and_create') {
470
            $response = redirect()->to($model->getCreateUrl($request->except([
471
                '_redirectBack',
472
                '_token',
473
                'url',
474
                'next_action',
475
            ])))->with([
476
                '_redirectBack'       => $backUrl,
477
                'sleeping_owl_tab_id' => $request->get('sleeping_owl_tab_id') ?: null,
478
            ]);
479
        } else {
480
            $response = redirect()->to($request->input('_redirectBack', $model->getDisplayUrl()));
481
        }
482
483
        return $response->with('success_message', $model->getMessageOnUpdate());
484
    }
485
486
    /**
487
     * @param ModelConfigurationInterface $model
488
     * @param Request $request
489
     *
490
     * @return bool
491
     *
492
     * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
493
     */
494
    public function inlineEdit(ModelConfigurationInterface $model, Request $request)
495
    {
496
        $field = $request->input('name');
497
        $id = $request->input('pk');
498
        $display = $model->fireDisplay();
499
        $column = null;
500
501
        /* @var ColumnEditableInterface|null $column */
502
        if (is_callable([$display, 'getColumns'])) {
503
            $column = $display->getColumns()->all()->filter(function ($column) use ($field) {
0 ignored issues
show
Bug introduced by
The method getColumns() 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\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

503
            $column = $display->/** @scrutinizer ignore-call */ getColumns()->all()->filter(function ($column) use ($field) {
Loading history...
504
                return ($column instanceof ColumnEditableInterface) && $field == $column->getName();
0 ignored issues
show
Bug introduced by
The method getName() does not exist on SleepingOwl\Admin\Contra...ColumnEditableInterface. Since it exists in all sub-types, consider adding an abstract or default implementation to SleepingOwl\Admin\Contra...ColumnEditableInterface. ( Ignorable by Annotation )

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

504
                return ($column instanceof ColumnEditableInterface) && $field == $column->/** @scrutinizer ignore-call */ getName();
Loading history...
505
            })->first();
506
        } else {
507
            if ($display instanceof DisplayTabbed) {
508
                foreach ($display->getTabs() as $tab) {
509
                    $content = $tab->getContent();
510
511
                    if ($content instanceof DisplayTable) {
512
                        $column = $content->getColumns()->all()->filter(function ($column) use ($field) {
513
                            return ($column instanceof ColumnEditableInterface) && $field == $column->getName();
514
                        })->first();
515
                    }
516
                    if ($content instanceof FormElements) {
517
                        foreach ($content->getElements() as $element) {
518
519
                            //Return data-table if inside FormElements
520
                            if ($element instanceof DisplayTable) {
521
                                $column = $element->getColumns()->all()->filter(function ($column) use ($field) {
522
                                    return ($column instanceof ColumnEditableInterface) && $field == $column->getName();
523
                                })->first();
524
                            }
525
526
                            //Try to find inline Editable in columns
527
                            if ($element instanceof Column) {
528
                                foreach ($element->getElements() as $columnElement) {
529
                                    if ($columnElement instanceof DisplayTable) {
530
                                        $column = $columnElement->getColumns()->all()->filter(function ($column) use (
531
                                            $field
532
                                        ) {
533
                                            return ($column instanceof ColumnEditableInterface) && $field == $column->getName();
534
                                        })->first();
535
                                    }
536
                                }
537
                            }
538
                        }
539
                    }
540
                }
541
            }
542
        }
543
544
        if (is_null($column)) {
545
            abort(404);
546
        }
547
548
        $repository = $model->getRepository();
549
        $item = $repository->find($id);
550
551
        if (is_null($item) || ! $model->isEditable($item)) {
552
            abort(404);
553
        }
554
555
        $column->setModel($item);
556
557
        if ($model->fireEvent('updating', true, $item, $request) === false) {
0 ignored issues
show
Bug introduced by
The method fireEvent() does not exist on SleepingOwl\Admin\Contra...lConfigurationInterface. Did you maybe mean fireEdit()? ( Ignorable by Annotation )

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

557
        if ($model->/** @scrutinizer ignore-call */ fireEvent('updating', true, $item, $request) === false) {

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
558
            return;
559
        }
560
561
        $column->save($request, $model);
562
563
        $model->fireEvent('updated', false, $item, $request);
564
    }
565
566
    /**
567
     * @param ModelConfigurationInterface $model
568
     * @param Request $request
569
     * @param int $id
570
     * @return \Illuminate\Http\RedirectResponse
571
     */
572
    public function deleteDelete(ModelConfigurationInterface $model, Request $request, $id)
573
    {
574
        $item = $model->getRepository()->find($id);
575
576
        if (is_null($item) || ! $model->isDeletable($item)) {
577
            abort(404);
578
        }
579
580
        $model->fireDelete($id);
581
582
        if ($model->fireEvent('deleting', true, $item, $request) === false) {
583
            return redirect()->back();
584
        }
585
586
        $model->getRepository()->delete($id);
587
588
        $model->fireEvent('deleted', false, $item, $request);
589
590
        return redirect($request->input('_redirectBack', back()->getTargetUrl()))
0 ignored issues
show
Bug Best Practice introduced by
The expression return redirect($request...->getMessageOnDelete()) also could return the type Illuminate\Routing\Redirector which is incompatible with the documented return type Illuminate\Http\RedirectResponse.
Loading history...
591
            ->with('success_message', $model->getMessageOnDelete());
592
    }
593
594
    /**
595
     * @param ModelConfigurationInterface $model
596
     * @param Request $request
597
     * @param int $id
598
     *
599
     * @return \Illuminate\Http\RedirectResponse
600
     *
601
     * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
602
     */
603
    public function deleteDestroy(ModelConfigurationInterface $model, Request $request, $id)
604
    {
605
        if (! $model->isRestorableModel()) {
606
            abort(404);
607
        }
608
609
        $item = $model->getRepository()->findOnlyTrashed($id);
610
611
        if (is_null($item) || ! $model->isRestorable($item)) {
612
            abort(404);
613
        }
614
615
        $model->fireDestroy($id);
616
617
        if ($model->fireEvent('destroying', true, $item, $request) === false) {
618
            return redirect()->back();
619
        }
620
621
        $model->getRepository()->forceDelete($id);
622
623
        $model->fireEvent('destroyed', false, $item, $request);
624
625
        return redirect($request->input('_redirectBack', back()->getTargetUrl()))
0 ignored issues
show
Bug Best Practice introduced by
The expression return redirect($request...>getMessageOnDestroy()) also could return the type Illuminate\Routing\Redirector which is incompatible with the documented return type Illuminate\Http\RedirectResponse.
Loading history...
626
            ->with('success_message', $model->getMessageOnDestroy());
627
    }
628
629
    /**
630
     * @param ModelConfigurationInterface|ModelConfiguration $model
631
     * @param Request $request
632
     * @param int $id
633
     *
634
     * @return \Illuminate\Http\RedirectResponse
635
     *
636
     * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
637
     */
638
    public function postRestore(ModelConfigurationInterface $model, Request $request, $id)
639
    {
640
        if (! $model->isRestorableModel()) {
641
            abort(404);
642
        }
643
644
        $item = $model->getRepository()->findOnlyTrashed($id);
645
646
        if (is_null($item) || ! $model->isRestorable($item)) {
647
            abort(404);
648
        }
649
650
        $model->fireRestore($id);
651
652
        if ($model->fireEvent('restoring', true, $item, $request) === false) {
653
            return redirect()->back();
654
        }
655
656
        $model->getRepository()->restore($id);
657
658
        $model->fireEvent('restored', false, $item, $request);
659
660
        return redirect($request->input('_redirectBack', back()->getTargetUrl()))
0 ignored issues
show
Bug Best Practice introduced by
The expression return redirect($request...>getMessageOnRestore()) also could return the type Illuminate\Routing\Redirector which is incompatible with the documented return type Illuminate\Http\RedirectResponse.
Loading history...
661
            ->with('success_message', $model->getMessageOnRestore());
662
    }
663
664
    /**
665
     * @param ModelConfigurationInterface $model
666
     * @param Renderable|RedirectResponse|string $content
667
     * @param string|null $title
668
     *
669
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View|\Illuminate\Http\RedirectResponse
670
     */
671
    public function render(ModelConfigurationInterface $model, $content, $title = null)
672
    {
673
        if ($content instanceof RedirectResponse) {
674
            return $content;
675
        }
676
677
        if ($content instanceof Renderable) {
678
            $content = $content->render();
679
        }
680
681
        if (is_null($title)) {
682
            $title = $model->getTitle();
683
        }
684
685
        return $this->admin->template()->view('_layout.inner')
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->admin->tem...this->parentBreadcrumb) also could return the type boolean which is incompatible with the documented return type Illuminate\Http\Redirect...\Contracts\View\Factory.
Loading history...
686
            ->with('title', $title)
0 ignored issues
show
Bug introduced by
The method with() does not exist on Illuminate\Contracts\View\Factory. ( Ignorable by Annotation )

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

686
            ->/** @scrutinizer ignore-call */ with('title', $title)

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
687
            ->with('content', $content)
688
            ->with('breadcrumbKey', $this->parentBreadcrumb);
689
    }
690
691
    /**
692
     * @param Renderable|string $content
693
     * @param string|null $title
694
     *
695
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
696
     */
697
    public function renderContent($content, $title = null)
698
    {
699
        if ($content instanceof Renderable) {
700
            $content = $content->render();
701
        }
702
703
        return $this->admin->template()->view('_layout.inner')
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->admin->tem...this->parentBreadcrumb) also could return the type boolean which is incompatible with the documented return type Illuminate\View\View|Ill...\Contracts\View\Factory.
Loading history...
704
            ->with('title', $title)
705
            ->with('content', $content)
706
            ->with('breadcrumbKey', $this->parentBreadcrumb);
707
    }
708
709
    /**
710
     * @param Request $request
711
     *
712
     * @return null|string
713
     */
714
    protected function getBackUrl(Request $request)
715
    {
716
        if (($backUrl = $request->input('_redirectBack')) == \URL::previous()) {
717
            $backUrl = null;
718
            $request->merge(['_redirectBack' => $backUrl]);
719
        }
720
721
        return $backUrl;
722
    }
723
724
    public function getWildcard()
725
    {
726
        abort(404);
727
    }
728
729
    /**
730
     * @param $title
731
     * @param $parent
732
     * @throws \DaveJamesMiller\Breadcrumbs\Exception
733
     */
734
    protected function registerBreadcrumb($title, $parent)
735
    {
736
        $this->breadcrumbs->register('render', function (Generator $breadcrumbs) use ($title, $parent) {
737
            $breadcrumbs->parent($parent);
738
            $breadcrumbs->push($title);
739
        });
740
741
        $this->parentBreadcrumb = 'render';
742
    }
743
744
    /**
745
     * @param ModelConfigurationInterface $model
746
     * @throws \DaveJamesMiller\Breadcrumbs\Exception
747
     */
748
    protected function registerBreadcrumbs(ModelConfigurationInterface $model)
749
    {
750
        $this->breadCrumbsData = $this->breadCrumbsData + (array) $model->getBreadCrumbs();
751
752
        foreach ($this->breadCrumbsData as $breadcrumb) {
753
            if (! $this->breadcrumbs->exists($breadcrumb['id'])) {
754
                $this->breadcrumbs->register($breadcrumb['id'], function (Generator $breadcrumbs) use ($breadcrumb) {
755
                    $breadcrumbs->parent($breadcrumb['parent']);
756
                    $breadcrumbs->push($breadcrumb['title'], $breadcrumb['url']);
757
                });
758
            }
759
        }
760
    }
761
}
762