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.

ModelAdminController   A
last analyzed

Complexity

Total Complexity 27

Size/Duplication

Total Lines 262
Duplicated Lines 28.24 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 27
lcom 1
cbo 5
dl 74
loc 262
rs 10
c 0
b 0
f 0

14 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 14 1
A getIndex() 0 8 1
A getTrashed() 12 12 2
A getAll() 12 12 2
A getCreate() 0 8 2
A postCreate() 10 10 2
A getView() 0 12 2
A getEdit() 0 10 2
A postEdit() 10 10 2
A getDelete() 0 14 3
A postDelete() 10 10 2
A getRestore() 0 8 2
A postRestore() 10 10 2
A getClone() 10 10 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace LaravelFlare\Flare\Admin\Models;
4
5
use LaravelFlare\Flare\Events\ModelView;
6
use LaravelFlare\Flare\Admin\AdminManager;
7
use LaravelFlare\Flare\Http\Requests\ModelEditRequest;
8
use LaravelFlare\Flare\Http\Requests\ModelCreateRequest;
9
use LaravelFlare\Flare\Http\Controllers\FlareController;
10
11
class ModelAdminController extends FlareController
12
{
13
    /**
14
     * ModelAdmin instance which has been resolved.
15
     * 
16
     * @var ModelAdmin
17
     */
18
    protected $modelAdmin;
19
20
    /**
21
     * Model instance.
22
     * 
23
     * @var Model
24
     */
25
    protected $model;
26
27
    /**
28
     * __construct.
29
     * 
30
     * @param AdminManager $adminManager
31
     */
32
    public function __construct(AdminManager $adminManager)
33
    {
34
        // Must call parent __construct otherwise 
35
        // we need to redeclare checkpermissions
36
        // middleware for authentication check
37
        parent::__construct($adminManager);
38
39
        $this->middleware('checkmodelfound', ['only' => ['getView', 'edit', 'delete']]);
40
41
        $this->modelAdmin = $this->adminManager->getAdminInstance();
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->adminManager->getAdminInstance() can also be of type object<LaravelFlare\Flare\Admin\Admin>. However, the property $modelAdmin is declared as type object<LaravelFlare\Flar...dmin\Models\ModelAdmin>. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
42
        $this->model = $this->modelAdmin->model();
43
44
        view()->share('modelAdmin', $this->modelAdmin);
0 ignored issues
show
Bug introduced by
The method share does only exist in Illuminate\Contracts\View\Factory, but not in Illuminate\View\View.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
45
    }
46
47
    /**
48
     * Index page for ModelAdmin.
49
     * 
50
     * @return \Illuminate\Http\Response
51
     */
52
    public function getIndex()
53
    {
54
        return view('flare::admin.modeladmin.index', [
55
                                                        'modelItems' => $this->modelAdmin->items(),
56
                                                        'totals' => $this->modelAdmin->totals(),
57
                                                    ]
58
                                                );
59
    }
60
61
    /**
62
     * Lists Trashed Model Items.
63
     * 
64
     * @return \Illuminate\Http\Response
65
     */
66 View Code Duplication
    public function getTrashed()
67
    {
68
        if (!$this->modelAdmin->hasSoftDeleting()) {
69
            return $this->missingMethod();
70
        }
71
72
        return view('flare::admin.modeladmin.trashed', [
0 ignored issues
show
Bug Best Practice introduced by
The return type of return view('flare::admi...modelAdmin->totals())); (Illuminate\View\View|Ill...\Contracts\View\Factory) is incompatible with the return type documented by LaravelFlare\Flare\Admin...nController::getTrashed of type Illuminate\Http\Response.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
73
                                                        'modelItems' => $this->modelAdmin->onlyTrashedItems(),
74
                                                        'totals' => $this->modelAdmin->totals(),
75
                                                    ]
76
                                                );
77
    }
78
79
    /**
80
     * List All Model Items inc Trashed.
81
     * 
82
     * @return \Illuminate\Http\Response
83
     */
84 View Code Duplication
    public function getAll()
85
    {
86
        if (!$this->modelAdmin->hasSoftDeleting()) {
87
            return $this->missingMethod();
88
        }
89
90
        return view('flare::admin.modeladmin.all', [
0 ignored issues
show
Bug Best Practice introduced by
The return type of return view('flare::admi...modelAdmin->totals())); (Illuminate\View\View|Ill...\Contracts\View\Factory) is incompatible with the return type documented by LaravelFlare\Flare\Admin...AdminController::getAll of type Illuminate\Http\Response.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
91
                                                        'modelItems' => $this->modelAdmin->allItems(),
92
                                                        'totals' => $this->modelAdmin->totals(),
93
                                                    ]
94
                                            );
95
    }
96
97
    /**
98
     * Create a new Model Entry from ModelAdmin Create Page.
99
     * 
100
     * @return \Illuminate\Http\Response
101
     */
102
    public function getCreate()
103
    {
104
        if (!$this->modelAdmin->hasCreating()) {
105
            return $this->missingMethod();
106
        }
107
108
        return view('flare::admin.modeladmin.create', []);
0 ignored issues
show
Bug Best Practice introduced by
The return type of return view('flare::admi...dmin.create', array()); (Illuminate\View\View|Ill...\Contracts\View\Factory) is incompatible with the return type documented by LaravelFlare\Flare\Admin...inController::getCreate of type Illuminate\Http\Response.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
109
    }
110
111
    /**
112
     * Receive new Model Entry Post Data, validate it and return user.
113
     * 
114
     * @return \Illuminate\Http\RedirectResponse
115
     */
116 View Code Duplication
    public function postCreate(ModelCreateRequest $request)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
117
    {
118
        if (!$this->modelAdmin->hasCreating()) {
119
            return $this->missingMethod();
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->missingMethod(); (Illuminate\Http\Response) is incompatible with the return type documented by LaravelFlare\Flare\Admin...nController::postCreate of type Illuminate\Http\RedirectResponse.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
120
        }
121
122
        $this->modelAdmin->create();
123
124
        return redirect($this->modelAdmin->currentUrl())->with('notifications_below_header', [['type' => 'success', 'icon' => 'check-circle', 'title' => 'Success!', 'message' => 'The '.$this->modelAdmin->getTitle().' was successfully created.', 'dismissable' => false]]);
0 ignored issues
show
Bug introduced by
It seems like $this->modelAdmin->currentUrl() targeting LaravelFlare\Flare\Admin\Admin::currentUrl() can also be of type object<Illuminate\Contracts\Routing\UrlGenerator>; however, redirect() does only seem to accept string|null, 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...
125
    }
126
127
    /**
128
     * View a Model Entry from ModelAdmin View Page.
129
     * 
130
     * @return \Illuminate\Http\Response
131
     */
132
    public function getView($modelitemId)
133
    {
134
        if (!$this->modelAdmin->hasViewing()) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->modelAdmin->hasViewing() of type null|boolean is loosely compared to false; this is ambiguous if the boolean can be false. You might want to explicitly use !== null instead.

If an expression can have both false, and null as possible values. It is generally a good practice to always use strict comparison to clearly distinguish between those two values.

$a = canBeFalseAndNull();

// Instead of
if ( ! $a) { }

// Better use one of the explicit versions:
if ($a !== null) { }
if ($a !== false) { }
if ($a !== null && $a !== false) { }
Loading history...
135
            return $this->missingMethod();
136
        }
137
138
        $this->modelAdmin->find($modelitemId);
139
140
        event(new ModelView($this->modelAdmin));
141
142
        return view('flare::admin.modeladmin.view', ['modelItem' => $this->modelAdmin->model]);
0 ignored issues
show
Bug Best Practice introduced by
The return type of return view('flare::admi...s->modelAdmin->model)); (Illuminate\View\View|Ill...\Contracts\View\Factory) is incompatible with the return type documented by LaravelFlare\Flare\Admin...dminController::getView of type Illuminate\Http\Response.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
143
    }
144
145
    /**
146
     * Edit Model Entry from ModelAdmin Edit Page.
147
     *
148
     * @param int $modelitemId
149
     * 
150
     * @return \Illuminate\Http\Response
151
     */
152
    public function getEdit($modelitemId)
153
    {
154
        if (!$this->modelAdmin->hasEditing()) {
155
            return $this->missingMethod();
156
        }
157
158
        $this->modelAdmin->find($modelitemId);
159
160
        return view('flare::admin.modeladmin.edit', ['modelItem' => $this->modelAdmin->model]);
0 ignored issues
show
Bug Best Practice introduced by
The return type of return view('flare::admi...s->modelAdmin->model)); (Illuminate\View\View|Ill...\Contracts\View\Factory) is incompatible with the return type documented by LaravelFlare\Flare\Admin...dminController::getEdit of type Illuminate\Http\Response.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
161
    }
162
163
    /**
164
     * Receive Model Entry Update Post Data, validate it and return user.
165
     * 
166
     * @param int $modelitemId
167
     * 
168
     * @return \Illuminate\Http\RedirectResponse
169
     */
170 View Code Duplication
    public function postEdit(ModelEditRequest $request, $modelitemId)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
171
    {
172
        if (!$this->modelAdmin->hasEditing()) {
173
            return $this->missingMethod();
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->missingMethod(); (Illuminate\Http\Response) is incompatible with the return type documented by LaravelFlare\Flare\Admin...minController::postEdit of type Illuminate\Http\RedirectResponse.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
174
        }
175
176
        $this->modelAdmin->edit($modelitemId);
177
178
        return redirect($this->modelAdmin->currentUrl())->with('notifications_below_header', [['type' => 'success', 'icon' => 'check-circle', 'title' => 'Success!', 'message' => 'The '.$this->modelAdmin->getTitle().' was successfully updated.', 'dismissable' => false]]);
0 ignored issues
show
Bug introduced by
It seems like $this->modelAdmin->currentUrl() targeting LaravelFlare\Flare\Admin\Admin::currentUrl() can also be of type object<Illuminate\Contracts\Routing\UrlGenerator>; however, redirect() does only seem to accept string|null, 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...
179
    }
180
181
    /**
182
     * Delete Model Entry from ModelAdmin Delete Page.
183
     *
184
     * @param int $modelitemId
185
     * 
186
     * @return \Illuminate\Http\Response
187
     */
188
    public function getDelete($modelitemId)
189
    {
190
        if (!$this->modelAdmin->hasDeleting()) {
191
            return $this->missingMethod();
192
        }
193
194
        if ($this->modelAdmin->hasSoftDeleting()) {
195
            $this->modelAdmin->findWithTrashed($modelitemId);
0 ignored issues
show
Bug introduced by
The method findWithTrashed() does not seem to exist on object<LaravelFlare\Flar...dmin\Models\ModelAdmin>.

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...
196
        } else {
197
            $this->modelAdmin->find($modelitemId);
198
        }
199
200
        return view('flare::admin.modeladmin.delete', ['modelItem' => $this->modelAdmin->model]);
0 ignored issues
show
Bug Best Practice introduced by
The return type of return view('flare::admi...s->modelAdmin->model)); (Illuminate\View\View|Ill...\Contracts\View\Factory) is incompatible with the return type documented by LaravelFlare\Flare\Admin...inController::getDelete of type Illuminate\Http\Response.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
201
    }
202
203
    /**
204
     * Receive Model Entry Delete Post Data, validate it and return user.
205
     *
206
     * @param int $modelitemId
207
     * 
208
     * @return \Illuminate\Http\RedirectResponse
209
     */
210 View Code Duplication
    public function postDelete($modelitemId)
211
    {
212
        if (!$this->modelAdmin->hasDeleting()) {
213
            return $this->missingMethod();
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->missingMethod(); (Illuminate\Http\Response) is incompatible with the return type documented by LaravelFlare\Flare\Admin...nController::postDelete of type Illuminate\Http\RedirectResponse.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
214
        }
215
216
        $this->modelAdmin->delete($modelitemId);
217
218
        return redirect($this->modelAdmin->currentUrl())->with('notifications_below_header', [['type' => 'success', 'icon' => 'check-circle', 'title' => 'Success!', 'message' => 'The '.$this->modelAdmin->getTitle().' was successfully removed.', 'dismissable' => false]]);
0 ignored issues
show
Bug introduced by
It seems like $this->modelAdmin->currentUrl() targeting LaravelFlare\Flare\Admin\Admin::currentUrl() can also be of type object<Illuminate\Contracts\Routing\UrlGenerator>; however, redirect() does only seem to accept string|null, 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...
219
    }
220
221
    /**
222
     * Restore a ModelItem.
223
     *
224
     * @param int $modelitemId
225
     * 
226
     * @return \Illuminate\Http\Response
227
     */
228
    public function getRestore($modelitemId)
0 ignored issues
show
Unused Code introduced by
The parameter $modelitemId is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
229
    {
230
        if (!$this->modelAdmin->hasSoftDeleting()) {
231
            return $this->missingMethod();
232
        }
233
234
        return view('flare::admin.modeladmin.restore', ['modelItem' => $this->modelAdmin->model]);
0 ignored issues
show
Bug Best Practice introduced by
The return type of return view('flare::admi...s->modelAdmin->model)); (Illuminate\View\View|Ill...\Contracts\View\Factory) is incompatible with the return type documented by LaravelFlare\Flare\Admin...nController::getRestore of type Illuminate\Http\Response.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
235
    }
236
237
    /**
238
     * Process Restore ModelItem Request.
239
     *
240
     * @param int $page_id
0 ignored issues
show
Bug introduced by
There is no parameter named $page_id. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
241
     * 
242
     * @return \Illuminate\Http\RedirectResponse
243
     */
244 View Code Duplication
    public function postRestore($modelitemId)
245
    {
246
        if (!$this->modelAdmin->hasSoftDeleting()) {
247
            return $this->missingMethod();
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->missingMethod(); (Illuminate\Http\Response) is incompatible with the return type documented by LaravelFlare\Flare\Admin...Controller::postRestore of type Illuminate\Http\RedirectResponse.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
248
        }
249
250
        $this->modelAdmin->restore($modelitemId);
0 ignored issues
show
Bug introduced by
The method restore() does not seem to exist on object<LaravelFlare\Flar...dmin\Models\ModelAdmin>.

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...
251
252
        return redirect($this->modelAdmin->currentUrl())->with('notifications_below_header', [['type' => 'success', 'icon' => 'check-circle', 'title' => 'Success!', 'message' => 'The '.$this->modelAdmin->getTitle().' was successfully restored.', 'dismissable' => false]]);
0 ignored issues
show
Bug introduced by
It seems like $this->modelAdmin->currentUrl() targeting LaravelFlare\Flare\Admin\Admin::currentUrl() can also be of type object<Illuminate\Contracts\Routing\UrlGenerator>; however, redirect() does only seem to accept string|null, 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...
253
    }
254
255
    /**
256
     * Clone a Page.
257
     *
258
     * @param int $modelitemId
259
     * 
260
     * @return \Illuminate\Http\Response
261
     */
262 View Code Duplication
    public function getClone($modelitemId)
263
    {
264
        if (!$this->modelAdmin->hasCloning()) {
265
            return $this->missingMethod();
266
        }
267
268
        $this->modelAdmin->clone($modelitemId);
0 ignored issues
show
Bug introduced by
The method clone() does not seem to exist on object<LaravelFlare\Flar...dmin\Models\ModelAdmin>.

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...
269
270
        return redirect($this->modelAdmin->currentUrl())->with('notifications_below_header', [['type' => 'success', 'icon' => 'check-circle', 'title' => 'Success!', 'message' => 'The '.$this->modelAdmin->getTitle().' was successfully cloned.', 'dismissable' => false]]);
0 ignored issues
show
Bug introduced by
It seems like $this->modelAdmin->currentUrl() targeting LaravelFlare\Flare\Admin\Admin::currentUrl() can also be of type object<Illuminate\Contracts\Routing\UrlGenerator>; however, redirect() does only seem to accept string|null, 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...
Bug Best Practice introduced by
The return type of return redirect($this->m...smissable' => false))); (Illuminate\Http\RedirectResponse) is incompatible with the return type documented by LaravelFlare\Flare\Admin...minController::getClone of type Illuminate\Http\Response.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
271
    }
272
}
273