Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

Completed
Push — master ( c08359...df3a1d )
by Mark
02:41
created

BackendController   A

Complexity

Total Complexity 16

Size/Duplication

Total Lines 212
Duplicated Lines 19.81 %

Coupling/Cohesion

Components 1
Dependencies 12

Importance

Changes 0
Metric Value
dl 42
loc 212
rs 10
c 0
b 0
f 0
wmc 16
lcom 1
cbo 12

13 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A index() 0 4 1
A create() 0 4 1
A form() 0 4 1
A store() 10 10 1
A show() 0 4 1
A edit() 0 4 1
A update() 10 10 1
A destroy() 10 10 1
A categories() 0 4 1
A categories_store() 12 12 1
A categories_destroy() 0 10 1
B save() 0 29 4

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
 * Created by PhpStorm.
4
 * User: Mark
5
 * Date: 05/03/2016
6
 * Time: 20:30.
7
 */
8
9
namespace App\Plugins\Articles;
10
11
use Carbon\Carbon;
12
use App\Model\Article;
13
use App\Model\Activity;
14
use Illuminate\Http\Request;
15
use App\Plugins\PluginEngine;
16
use App\Model\ArticleCategory;
17
use Illuminate\Validation\Rule;
18
use App\Classes\Repositories\ArticleRepository;
19
use App\Classes\Repositories\ArticleCategoryRepository;
20
21
/**
22
 * Class Controller.
23
 */
24
class BackendController extends PluginEngine
25
{
26
    /**
27
     * @var ArticleRepository
28
     */
29
    private $articles;
30
31
    /**
32
     * @var ArticleCategoryRepository
33
     */
34
    private $categories;
35
36
    /**
37
     * BackendController constructor.
38
     *
39
     * @param ArticleRepository $repository
40
     */
41
    public function __construct(ArticleRepository $repository, ArticleCategoryRepository $categories)
42
    {
43
        $this->articles = $repository;
44
45
        $this->categories = $categories;
46
    }
47
48
    /**
49
     * Display a listing of the resource.
50
     *
51
     * @return \Illuminate\Contracts\View\View|\Illuminate\Http\Response
52
     */
53
    public function index()
54
    {
55
        return $this->make('index')->with('articles', $this->articles->all());
56
    }
57
58
    /**
59
     * Show the form for creating a new resource.
60
     *
61
     * @return \Illuminate\Contracts\View\View|\Illuminate\Http\Response
62
     */
63
    public function create()
64
    {
65
        return $this->form(new Article);
66
    }
67
68
    /**
69
     * Generate a form for editing or creating a model.
70
     *
71
     * @param Article $article model to be used.
72
     * @return void
0 ignored issues
show
Documentation introduced by
Should the return type not be \Illuminate\Contracts\View\View?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
73
     */
74
    public function form(Article $article)
75
    {
76
        return $this->make('form')->with('categories', $this->categories->all())->with('article', $article);
77
    }
78
79
    /**
80
     * Store a newly created resource in storage.
81
     *
82
     * @param Article $article
83
     * @param  \Illuminate\Http\Request $request
84
     * @return \Illuminate\Http\Response
0 ignored issues
show
Documentation introduced by
Should the return type not be \Illuminate\Http\RedirectResponse?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
85
     */
86 View Code Duplication
    public function store(Article $article, Request $request)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
87
    {
88
        // use the global save function.
89
        $this->save($request, $article);
90
91
        account()->record(Activity::$created, $article);
0 ignored issues
show
Bug introduced by
The method record does only exist in App\Model\Account, but not in Illuminate\Contracts\Auth\Authenticatable.

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...
92
93
        // redirect back to articles index.
94
        return redirect()->route('admin.articles.index');
95
    }
96
97
    /**
98
     * Display the specified resource.
99
     *
100
     * @param  int  $id
101
     * @return \Illuminate\Http\Response
0 ignored issues
show
Documentation introduced by
Should the return type not be \Illuminate\Http\Response|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
102
     */
103
    public function show($id)
0 ignored issues
show
Unused Code introduced by
The parameter $id 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...
104
    {
105
        //
106
    }
107
108
    /**
109
     * Show the form for editing the specified resource.
110
     *
111
     * @param $slug
112
     * @return \Illuminate\Contracts\View\View
113
     */
114
    public function edit($slug)
115
    {
116
        return $this->form($this->articles->whereSlug($slug));
0 ignored issues
show
Deprecated Code introduced by
The method App\Classes\Repositories...Repository::whereSlug() has been deprecated with message: change to the repository class calling it.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
117
    }
118
119
    /**
120
     * Update the specified resource in storage.
121
     *
122
     * @param  \Illuminate\Http\Request $request
123
     * @param $slug
124
     * @return \Illuminate\Http\Response
0 ignored issues
show
Documentation introduced by
Should the return type not be \Illuminate\Http\RedirectResponse?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
125
     * @internal param int $id
126
     */
127 View Code Duplication
    public function update(Request $request, $slug)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
128
    {
129
        $article = $this->articles->whereSlug($slug);
0 ignored issues
show
Deprecated Code introduced by
The method App\Classes\Repositories...Repository::whereSlug() has been deprecated with message: change to the repository class calling it.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
130
131
        $this->save($request, $article);
132
133
        account()->record(Activity::$updated, $article);
0 ignored issues
show
Bug introduced by
The method record does only exist in App\Model\Account, but not in Illuminate\Contracts\Auth\Authenticatable.

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...
134
135
        return redirect()->route('admin.articles.index');
136
    }
137
138
    /**
139
     * Remove the specified resource from storage.
140
     *
141
     * @param  int  $id
0 ignored issues
show
Bug introduced by
There is no parameter named $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...
142
     * @return \Illuminate\Http\Response
0 ignored issues
show
Documentation introduced by
Should the return type not be \Illuminate\Http\RedirectResponse?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
143
     */
144 View Code Duplication
    public function destroy($slug)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
145
    {
146
        $article = $this->articles->whereSlug($slug);
0 ignored issues
show
Deprecated Code introduced by
The method App\Classes\Repositories...Repository::whereSlug() has been deprecated with message: change to the repository class calling it.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
147
148
        $article->delete();
149
150
        account()->record(Activity::$deleted, $article);
0 ignored issues
show
Bug introduced by
The method record does only exist in App\Model\Account, but not in Illuminate\Contracts\Auth\Authenticatable.

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...
151
152
        return redirect()->route('admin.articles.index');
153
    }
154
155
    /**
156
     * Category Index.
157
     * @param ArticleCategoryRepository $categoryRepository
158
     * @return \Illuminate\Contracts\View\View
159
     */
160
    public function categories(ArticleCategoryRepository $categoryRepository)
161
    {
162
        return $this->make('categories')->with('categories', $categoryRepository->all());
163
    }
164
165
    /**
166
     * @param Request $request
167
     * @return \Illuminate\Http\RedirectResponse
168
     */
169 View Code Duplication
    public function categories_store(Request $request)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
Coding Style introduced by
This method is not in camel caps format.

This check looks for method names that are not written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection seeker becomes databaseConnectionSeeker.

Loading history...
170
    {
171
        $this->validate($request, ['unique:title']);
172
173
        $category = new ArticleCategory;
174
        $category->title = $request['name'];
175
        $category->auditSave();
176
177
        account()->record(Activity::$created, $category);
0 ignored issues
show
Bug introduced by
The method record does only exist in App\Model\Account, but not in Illuminate\Contracts\Auth\Authenticatable.

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...
178
179
        return redirect()->route('admin.articles.categories.index');
180
    }
181
182
    /**
183
     * @param int $id
184
     * @param ArticleCategoryRepository $categoryRepository
185
     * @return \Illuminate\Http\RedirectResponse
186
     */
187
    public function categories_destroy(int $id, ArticleCategoryRepository $categoryRepository)
0 ignored issues
show
Coding Style introduced by
This method is not in camel caps format.

This check looks for method names that are not written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection seeker becomes databaseConnectionSeeker.

Loading history...
188
    {
189
        $category = $categoryRepository->whereID($id);
190
191
        account()->record(Activity::$deleted, $category);
0 ignored issues
show
Bug introduced by
The method record does only exist in App\Model\Account, but not in Illuminate\Contracts\Auth\Authenticatable.

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...
192
193
        $category->delete();
194
195
        return redirect()->route('admin.articles.categories.index');
196
    }
197
198
    /**
199
     * Save the data for the menu to the database.
200
     *
201
     * @param Request $request
202
     * @param Article $article
203
     * @return bool
204
     * @internal param Article $menu
205
     */
206
    public function save(Request $request, Article $article)
207
    {
208
        $this->validate($request, [
209
            'title' => ['min:3|max:255', Rule::unique('articles')->ignore($article->id)], 'content' => ['min:3'],
210
            'publish_date' => 'required|date',
211
        ]);
212
213
        if ($request['unpublish_date']) {
214
            $this->validate($request, ['unpublish_date' => 'sometimes|date|after:publish_date']);
215
        }
216
217
        // set attribute for the model.
218
        $article->setAttribute('title', $request['title']);
219
        $article->setAttribute('content', $request['content']);
220
        $article->setAttribute('category_id', $request['category']);
221
        $article->setAttribute('status', $request['status']);
222
        $article->setAttribute('featured_img', $request['image']);
223
224
        // 09/05/2018 $publish_date =
0 ignored issues
show
Unused Code Comprehensibility introduced by
40% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
225
        $publish_date   = $request['publish_date']   ? Carbon::createFromFormat('m/d/Y', $request['publish_date']) : null;
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 122 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
226
        $unpublish_date = $request['unpublish_date'] ? Carbon::createFromFormat('m/d/Y', $request['unpublish_date']) : null;
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 124 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
227
228
        // Store the carbon dates to the database.
229
        $article->setAttribute('publish_date', $publish_date);
230
        $article->setAttribute('unpublish_date', $unpublish_date);
231
232
        // save the article as an audit.
233
        return $article->auditSave();
234
    }
235
}
236