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 ( 4024e8...d63cae )
by Mark
02:55
created

BackendController::categories_store()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 7

Duplication

Lines 12
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
eloc 7
nc 1
nop 1
dl 12
loc 12
rs 9.4285
c 0
b 0
f 0
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 App\Model\Article;
12
use App\Model\Activity;
13
use Illuminate\Http\Request;
14
use App\Plugins\PluginEngine;
15
use App\Model\ArticleCategory;
16
use Illuminate\Validation\Rule;
17
use App\Classes\Repositories\ArticleRepository;
18
use App\Classes\Repositories\ArticleCategoryRepository;
19
20
/**
21
 * Class Controller.
22
 */
23
class BackendController extends PluginEngine
24
{
25
    /**
26
     * @var ArticleRepository
27
     */
28
    private $articles;
29
30
    /**
31
     * @var ArticleCategoryRepository
32
     */
33
    private $categories;
34
35
    /**
36
     * BackendController constructor.
37
     *
38
     * @param ArticleRepository $repository
39
     */
40
    public function __construct(ArticleRepository $repository, ArticleCategoryRepository $categories)
41
    {
42
        $this->articles = $repository;
43
44
        $this->categories = $categories;
45
    }
46
47
    /**
48
     * Display a listing of the resource.
49
     *
50
     * @return \Illuminate\Contracts\View\View|\Illuminate\Http\Response
51
     */
52
    public function index()
53
    {
54
        return $this->make('index')->with('articles', $this->articles->all());
55
    }
56
57
    /**
58
     * Show the form for creating a new resource.
59
     *
60
     * @return \Illuminate\Contracts\View\View|\Illuminate\Http\Response
61
     */
62
    public function create()
63
    {
64
        return $this->form(new Article);
65
    }
66
67
    /**
68
     * Generate a form for editing or creating a model.
69
     *
70
     * @param Article $article model to be used.
71
     * @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...
72
     */
73
    public function form(Article $article)
74
    {
75
        return $this->make('form')->with('categories', $this->categories->all())->with('article', $article);
76
    }
77
78
    /**
79
     * Store a newly created resource in storage.
80
     *
81
     * @param Article $article
82
     * @param  \Illuminate\Http\Request $request
83
     * @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...
84
     */
85 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...
86
    {
87
        // use the global save function.
88
        $this->save($request, $article);
89
90
        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...
91
92
        // redirect back to articles index.
93
        return redirect()->route('admin.articles.index');
94
    }
95
96
    /**
97
     * Display the specified resource.
98
     *
99
     * @param  int  $id
100
     * @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...
101
     */
102
    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...
103
    {
104
        //
105
    }
106
107
    /**
108
     * Show the form for editing the specified resource.
109
     *
110
     * @param $slug
111
     * @return \Illuminate\Contracts\View\View
112
     */
113
    public function edit($slug)
114
    {
115
        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...
116
    }
117
118
    /**
119
     * Update the specified resource in storage.
120
     *
121
     * @param  \Illuminate\Http\Request $request
122
     * @param $slug
123
     * @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...
124
     * @internal param int $id
125
     */
126 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...
127
    {
128
        $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...
129
130
        $this->save($request, $article);
131
132
        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...
133
134
        return redirect()->route('admin.articles.index');
135
    }
136
137
    /**
138
     * Remove the specified resource from storage.
139
     *
140
     * @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...
141
     * @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...
142
     */
143 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...
144
    {
145
        $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...
146
147
        $article->delete();
148
149
        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...
150
151
        return redirect()->route('admin.articles.index');
152
    }
153
154
    /**
155
     * Category Index.
156
     * @param ArticleCategoryRepository $categoryRepository
157
     * @return \Illuminate\Contracts\View\View
158
     */
159
    public function categories(ArticleCategoryRepository $categoryRepository)
160
    {
161
        return $this->make('categories')->with('categories', $categoryRepository->all());
162
    }
163
164
    /**
165
     * @param Request $request
166
     * @return \Illuminate\Http\RedirectResponse
167
     */
168 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...
169
    {
170
        $this->validate($request, ['unique:title']);
171
172
        $category = new ArticleCategory;
173
        $category->title = $request['name'];
174
        $category->auditSave();
175
176
        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...
177
178
        return redirect()->route('admin.articles.categories.index');
179
    }
180
181
    /**
182
     * @param int $id
183
     * @param ArticleCategoryRepository $categoryRepository
184
     * @return \Illuminate\Http\RedirectResponse
185
     */
186
    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...
187
    {
188
        $category = $categoryRepository->whereID($id);
189
190
        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...
191
192
        $category->delete();
193
194
        return redirect()->route('admin.articles.categories.index');
195
    }
196
197
    /**
198
     * Save the data for the menu to the database.
199
     *
200
     * @param Request $request
201
     * @param Article $article
202
     * @return bool
203
     * @internal param Article $menu
204
     */
205
    public function save(Request $request, Article $article)
206
    {
207
        $this->validate($request, ['title' => ['min:3|max:255', Rule::unique('articles')->ignore($article->id)], 'content' => ['min:3']]);
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 138 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...
208
209
        // set attribute for the model.
210
        $article->setAttribute('title', $request['title']);
211
        $article->setAttribute('content', $request['content']);
212
        $article->setAttribute('category_id', $request['category']);
213
        $article->setAttribute('status', $request['status']);
214
        $article->setAttribute('featured_img', $request['image']);
215
216
        return $article->auditSave();
217
    }
218
}
219