Completed
Push — develop ( e54750...4239da )
by Mohamed
08:00
created

ProjectController   A

Complexity

Total Complexity 35

Size/Duplication

Total Lines 384
Duplicated Lines 11.46 %

Coupling/Cohesion

Components 1
Dependencies 11

Test Coverage

Coverage 98.59%

Importance

Changes 8
Bugs 3 Features 0
Metric Value
wmc 35
c 8
b 3
f 0
lcom 1
cbo 11
dl 44
loc 384
ccs 140
cts 142
cp 0.9859
rs 9

16 Methods

Rating   Name   Duplication   Size   Complexity  
A getCreated() 12 12 1
A getEdit() 0 8 1
A postEdit() 0 15 2
A postAssign() 10 10 2
A postUnassign() 10 10 2
A postAddNote() 0 8 1
A postEditNote() 0 12 2
A getDeleteNote() 0 6 1
A postExportIssues() 0 23 1
A getDownloadExport() 0 8 1
A getInactiveUsers() 0 6 1
A getIndex() 0 21 3
A getIssues() 0 15 2
A getAssigned() 12 12 1
A getNotes() 0 13 1
C projectMainViewTabs() 0 58 13

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
/*
4
 * This file is part of the Tinyissue package.
5
 *
6
 * (c) Mohamed Alsharaf <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Tinyissue\Http\Controllers;
13
14
use Illuminate\Database\Eloquent\Relations\Relation;
15
use Illuminate\Http\Request;
16
use Tinyissue\Form\FilterIssue as FilterForm;
17
use Tinyissue\Form\Note as NoteForm;
18
use Tinyissue\Form\Project as Form;
19
use Tinyissue\Http\Requests\FormRequest;
20
use Tinyissue\Model\Project;
21
use Tinyissue\Model\Project\Issue;
22
use Tinyissue\Model\Project\Note;
23
use Tinyissue\Services\Exporter;
24
25
/**
26
 * ProjectController is the controller class for managing request related to a project.
27
 *
28
 * @author Mohamed Alsharaf <[email protected]>
29
 */
30
class ProjectController extends Controller
31
{
32
    /**
33
     * Display activity for a project.
34
     *
35
     * @param Project $project
36
     *
37
     * @return \Illuminate\View\View
38
     */
39 11
    public function getIndex(Project $project)
40
    {
41 11
        $activities = $project->activities()
42 11
            ->with('activity', 'issue', 'user', 'assignTo', 'comment', 'note')
43 11
            ->orderBy('users_activity.created_at', 'DESC')
44 11
            ->take(10);
45
46
        // Internal project and logged user can see created only
47 11
        if ($project->isPrivateInternal() && $this->auth->user()->isUser()) {
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface Illuminate\Contracts\Auth\Authenticatable as the method isUser() does only exist in the following implementations of said interface: Tinyissue\Model\User.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
48
            $activities->join('projects_issues', 'projects_issues.id', '=', 'item_id');
49
            $activities->where('created_by', '=', $this->auth->user()->id);
0 ignored issues
show
Bug introduced by
Accessing id on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
50
        }
51
52 11
        return view('project.index', [
0 ignored issues
show
Bug Compatibility introduced by
The expression view('project.index', ar...idebar' => 'project')); of type Illuminate\View\View|Ill...\Contracts\View\Factory adds the type Illuminate\Contracts\View\Factory to the return on line 52 which is incompatible with the return type documented by Tinyissue\Http\Controlle...ectController::getIndex of type Illuminate\View\View.
Loading history...
53 11
            'tabs'       => $this->projectMainViewTabs($project, 'index'),
54 11
            'project'    => $project,
55 11
            'active'     => 'activity',
56 11
            'activities' => $activities->get(),
57 11
            'sidebar'    => 'project',
58
        ]);
59
    }
60
61
    /**
62
     * Display issues for a project.
63
     *
64
     * @param FilterForm $filterForm
65
     * @param Request    $request
66
     * @param Project    $project
67
     * @param int        $status
68
     *
69
     * @return \Illuminate\View\View
70
     */
71 2
    public function getIssues(FilterForm $filterForm, Request $request, Project $project, $status = Issue::STATUS_OPEN)
72
    {
73 2
        $request['created_by'] = auth()->user()->id;
0 ignored issues
show
Bug introduced by
Accessing id on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
74 2
        $active                = $status == Issue::STATUS_OPEN ? 'open_issue' : 'closed_issue';
75 2
        $issues                = $project->listIssues($status, $request->all());
76
77 2
        return view('project.index', [
0 ignored issues
show
Bug Compatibility introduced by
The expression view('project.index', ar...Form' => $filterForm)); of type Illuminate\View\View|Ill...\Contracts\View\Factory adds the type Illuminate\Contracts\View\Factory to the return on line 77 which is incompatible with the return type documented by Tinyissue\Http\Controlle...ctController::getIssues of type Illuminate\View\View.
Loading history...
78 2
            'tabs'       => $this->projectMainViewTabs($project, 'issues', $issues, $status),
0 ignored issues
show
Documentation introduced by
$status is of type integer, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
79 2
            'project'    => $project,
80 2
            'active'     => $active,
81 2
            'issues'     => $issues,
82 2
            'sidebar'    => 'project',
83 2
            'filterForm' => $filterForm,
84
        ]);
85
    }
86
87
    /**
88
     * Display issues assigned to current user for a project.
89
     *
90
     * @param Project $project
91
     *
92
     * @return \Illuminate\View\View
93
     */
94 1 View Code Duplication
    public function getAssigned(Project $project)
1 ignored issue
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...
95
    {
96 1
        $issues = $project->listAssignedOrCreatedIssues($this->auth->user());
0 ignored issues
show
Documentation introduced by
$this->auth->user() is of type object<Illuminate\Contra...h\Authenticatable>|null, but the function expects a object<Tinyissue\Model\User>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
97
98 1
        return view('project.index', [
0 ignored issues
show
Bug Compatibility introduced by
The expression view('project.index', ar...idebar' => 'project')); of type Illuminate\View\View|Ill...\Contracts\View\Factory adds the type Illuminate\Contracts\View\Factory to the return on line 98 which is incompatible with the return type documented by Tinyissue\Http\Controlle...Controller::getAssigned of type Illuminate\View\View.
Loading history...
99 1
            'tabs'    => $this->projectMainViewTabs($project, 'assigned', $issues),
100 1
            'project' => $project,
101 1
            'active'  => 'issue_assigned_to_you',
102 1
            'issues'  => $issues,
103 1
            'sidebar' => 'project',
104
        ]);
105
    }
106
107
    /**
108
     * Display issues created to current user for a project.
109
     *
110
     * @param Project $project
111
     *
112
     * @return \Illuminate\View\View
113
     */
114 View Code Duplication
    public function getCreated(Project $project)
1 ignored issue
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...
115
    {
116
        $issues = $project->listAssignedOrCreatedIssues($this->auth->user());
0 ignored issues
show
Documentation introduced by
$this->auth->user() is of type object<Illuminate\Contra...h\Authenticatable>|null, but the function expects a object<Tinyissue\Model\User>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
117
118
        return view('project.index', [
0 ignored issues
show
Bug Compatibility introduced by
The expression view('project.index', ar...idebar' => 'project')); of type Illuminate\View\View|Ill...\Contracts\View\Factory adds the type Illuminate\Contracts\View\Factory to the return on line 118 which is incompatible with the return type documented by Tinyissue\Http\Controlle...tController::getCreated of type Illuminate\View\View.
Loading history...
119
            'tabs'    => $this->projectMainViewTabs($project, 'created', $issues),
120
            'project' => $project,
121
            'active'  => 'issue_created_by_you',
122
            'issues'  => $issues,
123
            'sidebar' => 'project',
124
        ]);
125
    }
126
127
    /**
128
     * Display notes for a project.
129
     *
130
     * @param Project  $project
131
     * @param NoteForm $form
132
     *
133
     * @return \Illuminate\View\View
134
     */
135 7
    public function getNotes(Project $project, NoteForm $form)
136
    {
137 7
        $notes = $project->notes()->with('createdBy')->get();
138
139 7
        return view('project.index', [
0 ignored issues
show
Bug Compatibility introduced by
The expression view('project.index', ar... 'noteForm' => $form)); of type Illuminate\View\View|Ill...\Contracts\View\Factory adds the type Illuminate\Contracts\View\Factory to the return on line 139 which is incompatible with the return type documented by Tinyissue\Http\Controlle...ectController::getNotes of type Illuminate\View\View.
Loading history...
140 7
            'tabs'     => $this->projectMainViewTabs($project, 'notes', $notes),
141 7
            'project'  => $project,
142 7
            'active'   => 'notes',
143 7
            'notes'    => $notes,
144 7
            'sidebar'  => 'project',
145 7
            'noteForm' => $form,
146
        ]);
147
    }
148
149
    /**
150
     * @param Project $project
151
     * @param string  $view
152
     * @param null    $data
153
     * @param bool    $status
154
     *
155
     * @return array
156
     */
157 21
    protected function projectMainViewTabs(Project $project, $view, $data = null, $status = false)
158
    {
159 21
        $notesCount        = $view === 'note' ? $data->count() : $project->notes()->count();
0 ignored issues
show
Bug introduced by
The method count cannot be called on $data (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
160 21
        $user              = $this->auth->user();
161 21
        $isLoggedIn        = !$this->auth->guest();
162 21
        $isUser            = $isLoggedIn && $user->isUser();
163 21
        $isInternalProject = $project->isPrivateInternal();
164
165 21
        if ($view === 'issues') {
166 2
            if ($status == Issue::STATUS_OPEN) {
167 2
                $closedIssuesCount = $project->closedIssuesCount($user)->count();
0 ignored issues
show
Bug introduced by
It seems like $user defined by $this->auth->user() on line 160 can also be of type object<Illuminate\Contracts\Auth\Authenticatable>; however, Tinyissue\Model\Traits\P...it::closedIssuesCount() does only seem to accept object<Tinyissue\Model\User>|null, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
168 2
                $openIssuesCount   = $data->count();
0 ignored issues
show
Bug introduced by
The method count cannot be called on $data (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
169
            } else {
170 1
                $closedIssuesCount = $data->count();
0 ignored issues
show
Bug introduced by
The method count cannot be called on $data (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
171 2
                $openIssuesCount   = $project->openIssuesCount($user)->count();
0 ignored issues
show
Bug introduced by
It seems like $user defined by $this->auth->user() on line 160 can also be of type object<Illuminate\Contracts\Auth\Authenticatable>; however, Tinyissue\Model\Traits\P...rait::openIssuesCount() does only seem to accept null|object<Tinyissue\Model\User>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
172
            }
173
        } else {
174 19
            $openIssuesCount   = $project->openIssuesCount($user)->count();
0 ignored issues
show
Bug introduced by
It seems like $user defined by $this->auth->user() on line 160 can also be of type object<Illuminate\Contracts\Auth\Authenticatable>; however, Tinyissue\Model\Traits\P...rait::openIssuesCount() does only seem to accept null|object<Tinyissue\Model\User>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
175 19
            $closedIssuesCount = $project->closedIssuesCount($user)->count();
0 ignored issues
show
Bug introduced by
It seems like $user defined by $this->auth->user() on line 160 can also be of type object<Illuminate\Contracts\Auth\Authenticatable>; however, Tinyissue\Model\Traits\P...it::closedIssuesCount() does only seem to accept object<Tinyissue\Model\User>|null, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
176
        }
177
178 21
        $tabs   = [];
179 21
        $tabs[] = [
180 21
            'url'  => $project->to(),
181 21
            'page' => 'activity',
182
        ];
183 21
        $tabs[] = [
184 21
            'url'    => $project->to('issues'),
185 21
            'page'   => 'open_issue',
186 21
            'prefix' => $openIssuesCount,
187
        ];
188 21
        $tabs[] = [
189 21
            'url'    => $project->to('issues') . '/0',
190 21
            'page'   => 'closed_issue',
191 21
            'prefix' => $closedIssuesCount,
192
        ];
193 21
        if ($isLoggedIn && (!$isInternalProject || (!$isUser && $isInternalProject))) {
194 20
            if ($view !== 'assigned') {
195 19
                $method              = $isUser ? 'createdIssuesCount' : 'assignedIssuesCount';
196 19
                $assignedIssuesCount = $this->auth->user()->$method($project->id);
197
            } else {
198 1
                $assignedIssuesCount = $data->count();
0 ignored issues
show
Bug introduced by
The method count cannot be called on $data (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
199
            }
200
201 20
            $tabs[] = [
202 20
                'url'    => $project->to($isUser ? 'created' : 'assigned'),
203 20
                'page'   => ($isUser ? 'issue_created_by_you' : 'issue_assigned_to_you'),
204 20
                'prefix' => $assignedIssuesCount,
205
            ];
206
        }
207 21
        $tabs[] = [
208 21
            'url'    => $project->to('notes'),
209 21
            'page'   => 'notes',
210 21
            'prefix' => $notesCount,
211
        ];
212
213 21
        return $tabs;
214
    }
215
216
    /**
217
     * Edit the project.
218
     *
219
     * @param Project $project
220
     * @param Form    $form
221
     *
222
     * @return \Illuminate\View\View
223
     */
224 2
    public function getEdit(Project $project, Form $form)
225
    {
226 2
        return view('project.edit', [
0 ignored issues
show
Bug Compatibility introduced by
The expression view('project.edit', arr...idebar' => 'project')); of type Illuminate\View\View|Ill...\Contracts\View\Factory adds the type Illuminate\Contracts\View\Factory to the return on line 226 which is incompatible with the return type documented by Tinyissue\Http\Controlle...jectController::getEdit of type Illuminate\View\View.
Loading history...
227 2
            'form'    => $form,
228 2
            'project' => $project,
229 2
            'sidebar' => 'project',
230
        ]);
231
    }
232
233
    /**
234
     * To update project details.
235
     *
236
     * @param Project             $project
237
     * @param FormRequest\Project $request
238
     *
239
     * @return \Illuminate\Http\RedirectResponse
240
     */
241 2
    public function postEdit(Project $project, FormRequest\Project $request)
242
    {
243
        // Delete the project
244 2
        if ($request->has('delete-project')) {
245 1
            $project->delete();
246
247 1
            return redirect('projects')
248 1
                ->with('notice', trans('tinyissue.project_has_been_deleted'));
249
        }
250
251 1
        $project->update($request->all());
252
253 1
        return redirect($project->to())
254 1
            ->with('notice', trans('tinyissue.project_has_been_updated'));
255
    }
256
257
    /**
258
     * Ajax: returns list of users that are not in the project.
259
     *
260
     * @param Project $project
261
     *
262
     * @return \Symfony\Component\HttpFoundation\Response
263
     */
264 1
    public function getInactiveUsers(Project $project = null)
265
    {
266 1
        $users = $project->usersNotIn();
0 ignored issues
show
Bug introduced by
It seems like $project is not always an object, but can also be of type null. Maybe add an additional type check?

If a variable is not always an object, we recommend to add an additional type check to ensure your method call is safe:

function someFunction(A $objectMaybe = null)
{
    if ($objectMaybe instanceof A) {
        $objectMaybe->doSomething();
    }
}
Loading history...
267
268 1
        return response()->json($users);
269
    }
270
271
    /**
272
     * Ajax: add user to the project.
273
     *
274
     * @param Project $project
275
     * @param Request $request
276
     *
277
     * @return \Symfony\Component\HttpFoundation\Response
278
     */
279 1 View Code Duplication
    public function postAssign(Project $project, 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...
280
    {
281 1
        $status = false;
282 1
        if ($request->has('user_id')) {
283 1
            $project->assignUser((int) $request->input('user_id'));
284 1
            $status = true;
285
        }
286
287 1
        return response()->json(['status' => $status]);
288
    }
289
290
    /**
291
     * Ajax: remove user from the project.
292
     *
293
     * @param Project $project
294
     * @param Request $request
295
     *
296
     * @return \Symfony\Component\HttpFoundation\Response
297
     */
298 1 View Code Duplication
    public function postUnassign(Project $project, 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...
299
    {
300 1
        $status = false;
301 1
        if ($request->has('user_id')) {
302 1
            $project->unassignUser((int) $request->input('user_id'));
303 1
            $status = true;
304
        }
305
306 1
        return response()->json(['status' => $status]);
307
    }
308
309
    /**
310
     * To add a new note to the project.
311
     *
312
     * @param Project          $project
313
     * @param Note             $note
314
     * @param FormRequest\Note $request
315
     *
316
     * @return \Illuminate\Http\RedirectResponse
317
     */
318 2
    public function postAddNote(Project $project, Note $note, FormRequest\Note $request)
319
    {
320 2
        $note->setRelation('project', $project);
321 2
        $note->setRelation('createdBy', $this->auth->user());
322 2
        $note->createNote($request->all());
323
324 2
        return redirect($note->to())->with('notice', trans('tinyissue.your_note_added'));
325
    }
326
327
    /**
328
     * Ajax: To update project note.
329
     *
330
     * @param Project $project
331
     * @param Note    $note
332
     * @param Request $request
333
     *
334
     * @return \Symfony\Component\HttpFoundation\Response
335
     */
336 1
    public function postEditNote(Project $project, Project\Note $note, Request $request)
337
    {
338 1
        $body = '';
339 1
        if ($request->has('body')) {
340 1
            $note->setRelation('project', $project);
341 1
            $note->updateBody($request->input('body'), $this->auth->user());
0 ignored issues
show
Bug introduced by
It seems like $request->input('body') targeting Illuminate\Http\Request::input() can also be of type array; however, Tinyissue\Model\Traits\P...CrudTrait::updateBody() does only seem to accept string, 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...
Documentation introduced by
$this->auth->user() is of type object<Illuminate\Contra...h\Authenticatable>|null, but the function expects a object<Tinyissue\Model\User>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
342
343 1
            $body = \Html::format($note->body);
344
        }
345
346 1
        return response()->json(['status' => true, 'text' => $body]);
347
    }
348
349
    /**
350
     * Ajax: to delete a project note.
351
     *
352
     * @param Project $project
353
     * @param Note    $note
354
     *
355
     * @return \Symfony\Component\HttpFoundation\Response
356
     */
357 1
    public function getDeleteNote(Project $project, Project\Note $note)
0 ignored issues
show
Unused Code introduced by
The parameter $project 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...
358
    {
359 1
        $note->deleteNote($this->auth->user());
0 ignored issues
show
Documentation introduced by
$this->auth->user() is of type object<Illuminate\Contra...h\Authenticatable>|null, but the function expects a object<Tinyissue\Model\User>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
360
361 1
        return response()->json(['status' => true]);
362
    }
363
364
    /**
365
     * Ajax: generate the issues export file.
366
     *
367
     * @param Project  $project
368
     * @param Exporter $exporter
369
     * @param Request  $request
370
     *
371
     * @return \Symfony\Component\HttpFoundation\Response
372
     */
373 4
    public function postExportIssues(Project $project, Exporter $exporter, Request $request)
374
    {
375
        // Generate export file
376 4
        $info = $exporter->exportFile(
377 4
            'Project\Issue',
378 4
            $request->input('format', Exporter::TYPE_CSV),
0 ignored issues
show
Bug introduced by
It seems like $request->input('format'...ces\Exporter::TYPE_CSV) targeting Illuminate\Http\Request::input() can also be of type array; however, Tinyissue\Services\Exporter::exportFile() does only seem to accept string, 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...
379 4
            $request->all()
380
        );
381
382
        // Download link
383 4
        $link = link_to(
384 4
            $project->to('download_export/' . $info['file']),
385 4
            trans('tinyissue.download_export'),
386 4
            ['class' => 'btn btn-link']
387
        );
388
389 4
        return response()->json([
390 4
            'link'  => $link,
391 4
            'title' => $info['title'],
392 4
            'file'  => $info['file'],
393 4
            'ext'   => $info['ext'],
394
        ]);
395
    }
396
397
    /**
398
     * Download and then delete an export file.
399
     *
400
     * @param Project $project
401
     * @param string  $file
402
     *
403
     * @return \Symfony\Component\HttpFoundation\BinaryFileResponse
404
     */
405 4
    public function getDownloadExport(Project $project, $file)
0 ignored issues
show
Unused Code introduced by
The parameter $project 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...
406
    {
407
        // Filter out any characters that are not in pattern
408 4
        $file = preg_replace('/[^a-z0-9\_\.]/mi', '', $file);
409
410
        // Download export
411 4
        return response()->download(storage_path('exports/' . $file), $file)->deleteFileAfterSend(true);
412
    }
413
}
414