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 ( 70e47f...dda101 )
by Mark
07: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\Classes\Repositories\ArticleCategoryRepository;
12
use App\Classes\Repositories\ArticleRepository;
13
use App\Model\Activity;
14
use App\Model\Article;
15
use App\Model\ArticleCategory;
16
use Illuminate\Http\Request;
17
use App\Plugins\PluginEngine;
18
use Illuminate\Validation\Rule;
19
20
/**
21
 * Class Controller.
22
 */
23
class BackendController extends PluginEngine
24
{
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->make('create')->with('categories', $this->categories->all());
66
    }
67
68
    /**
69
     * Store a newly created resource in storage.
70
     *
71
     * @param Article $article
72
     * @param  \Illuminate\Http\Request $request
73
     * @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...
74
     */
75 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...
76
    {
77
        // use the global save function.
78
        $this->save($request, $article);
79
80
        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...
81
82
        // redirect back to articles index.
83
        return redirect()->route('admin.articles.index');
84
    }
85
86
    /**
87
     * Display the specified resource.
88
     *
89
     * @param  int  $id
90
     * @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...
91
     */
92
    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...
93
    {
94
        //
95
    }
96
97
    /**
98
     * Show the form for editing the specified resource.
99
     *
100
     * @param $slug
101
     * @return \Illuminate\Contracts\View\View
102
     * @internal param int $id
103
     */
104
    public function edit($slug)
105
    {
106
        $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...
107
108
        return $this->make('edit')->with(['categories' => $this->categories->all(), 'article' => $article]);
109
    }
110
111
    /**
112
     * Update the specified resource in storage.
113
     *
114
     * @param  \Illuminate\Http\Request $request
115
     * @param $slug
116
     * @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...
117
     * @internal param int $id
118
     */
119 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...
120
    {
121
        $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...
122
123
        $this->save($request, $article);
124
125
        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...
126
127
        return redirect()->route('admin.articles.index');
128
    }
129
130
    /**
131
     * Remove the specified resource from storage.
132
     *
133
     * @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...
134
     * @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...
135
     */
136 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...
137
    {
138
        $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...
139
140
        $article->delete();
141
142
        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...
143
144
        return redirect()->route('admin.articles.index');
145
    }
146
147
    /**
148
     * Category Index.
149
     * @param ArticleCategoryRepository $categoryRepository
150
     * @return \Illuminate\Contracts\View\View
151
     */
152
    public function categories(ArticleCategoryRepository $categoryRepository)
153
    {
154
        return $this->make('categories')->with('categories', $categoryRepository->all());
155
    }
156
157
    /**
158
     * @param Request $request
159
     * @return \Illuminate\Http\RedirectResponse
160
     */
161 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...
162
    {
163
        $this->validate($request,['unique:title']);
164
165
        $category = new ArticleCategory;
166
        $category->title = $request['name'];
167
        $category->auditSave();
168
169
        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...
170
171
        return redirect()->route('admin.articles.categories.index');
172
    }
173
174
    /**
175
     * @param int $id
176
     * @param ArticleCategoryRepository $categoryRepository
177
     * @return \Illuminate\Http\RedirectResponse
178
     */
179
    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...
180
    {
181
        $category = $categoryRepository->whereID($id);
182
183
        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...
184
185
        $category->delete();
186
187
        return redirect()->route('admin.articles.categories.index');
188
    }
189
190
    /**
191
     * Save the data for the menu to the database.
192
     *
193
     * @param Request $request
194
     * @param Article $article
195
     * @return bool
196
     * @internal param Article $menu
197
     */
198
    public function save(Request $request, Article $article)
199
    {
200
        $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...
201
202
        // set attribute for the model.
203
        $article->setAttribute('title', $request['title']);
204
        $article->setAttribute('content', $request['content']);
205
        $article->setAttribute('category_id', $request['category']);
206
        $article->setAttribute('status', $request['status']);
207
        $article->setAttribute('featured_img', $request['image']);
208
209
        return $article->auditSave();
210
    }
211
}
212