Completed
Push — develop ( 688bc1...4964b4 )
by Mohamed
07:24
created

ProjectController::getNotes()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 1

Importance

Changes 4
Bugs 1 Features 0
Metric Value
c 4
b 1
f 0
dl 0
loc 13
ccs 9
cts 9
cp 1
rs 9.4285
cc 1
eloc 9
nc 1
nop 2
crap 1
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\Http\Request;
15
use Tinyissue\Form\FilterIssue as FilterForm;
16
use Tinyissue\Form\Note as NoteForm;
17
use Tinyissue\Form\Project as Form;
18
use Tinyissue\Http\Requests\FormRequest;
19
use Tinyissue\Model\Project;
20
use Tinyissue\Model\Project\Issue;
21
use Tinyissue\Model\Project\Note;
22
use Tinyissue\Services\Exporter;
23
24
/**
25
 * ProjectController is the controller class for managing request related to a project.
26
 *
27
 * @author Mohamed Alsharaf <[email protected]>
28
 */
29
class ProjectController extends Controller
30
{
31
    /**
32
     * Display activity for a project.
33
     *
34
     * @param Project $project
35
     *
36
     * @return \Illuminate\View\View
37
     */
38 11
    public function getIndex(Project $project)
39
    {
40 11
        $activities = $project->activities()
41 11
            ->with('activity', 'issue', 'user', 'assignTo', 'comment', 'note')
42 11
            ->orderBy('created_at', 'DESC')
43 11
            ->take(10)
44 11
            ->get();
45
46 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 46 which is incompatible with the return type documented by Tinyissue\Http\Controlle...ectController::getIndex of type Illuminate\View\View.
Loading history...
47 11
            'tabs'       => $this->projectMainViewTabs($project, 'index'),
48 11
            'project'    => $project,
49 11
            'active'     => 'activity',
50 11
            'activities' => $activities,
51 11
            'sidebar'    => 'project',
52
        ]);
53
    }
54
55
    /**
56
     * Display issues for a project.
57
     *
58
     * @param FilterForm $filterForm
59
     * @param Request    $request
60
     * @param Project    $project
61
     * @param int        $status
62
     *
63
     * @return \Illuminate\View\View
64
     */
65 2
    public function getIssues(FilterForm $filterForm, Request $request, Project $project, $status = Issue::STATUS_OPEN)
66
    {
67 2
        $active = $status == Issue::STATUS_OPEN ? 'open_issue' : 'closed_issue';
68 2
        $issues = $project->listIssues($status, $request->all());
69
70 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 70 which is incompatible with the return type documented by Tinyissue\Http\Controlle...ctController::getIssues of type Illuminate\View\View.
Loading history...
71 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...
72 2
            'project'    => $project,
73 2
            'active'     => $active,
74 2
            'issues'     => $issues,
75 2
            'sidebar'    => 'project',
76 2
            'filterForm' => $filterForm,
77
        ]);
78
    }
79
80
    /**
81
     * Display issues assigned to current user for a project.
82
     *
83
     * @param Project $project
84
     *
85
     * @return \Illuminate\View\View
86
     */
87 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...
88
    {
89 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...
90
91 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 91 which is incompatible with the return type documented by Tinyissue\Http\Controlle...Controller::getAssigned of type Illuminate\View\View.
Loading history...
92 1
            'tabs'    => $this->projectMainViewTabs($project, 'assigned', $issues),
93 1
            'project' => $project,
94 1
            'active'  => 'issue_assigned_to_you',
95 1
            'issues'  => $issues,
96 1
            'sidebar' => 'project',
97
        ]);
98
    }
99
100
    /**
101
     * Display issues created to current user for a project.
102
     *
103
     * @param Project $project
104
     *
105
     * @return \Illuminate\View\View
106
     */
107 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...
108
    {
109
        $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...
110
111
        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 111 which is incompatible with the return type documented by Tinyissue\Http\Controlle...tController::getCreated of type Illuminate\View\View.
Loading history...
112
            'tabs'    => $this->projectMainViewTabs($project, 'created', $issues),
113
            'project' => $project,
114
            'active'  => 'issue_created_by_you',
115
            'issues'  => $issues,
116
            'sidebar' => 'project',
117
        ]);
118
    }
119
120
    /**
121
     * Display notes for a project.
122
     *
123
     * @param Project  $project
124
     * @param NoteForm $form
125
     *
126
     * @return \Illuminate\View\View
127
     */
128 7
    public function getNotes(Project $project, NoteForm $form)
129
    {
130 7
        $notes = $project->notes()->with('createdBy')->get();
131
132 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 132 which is incompatible with the return type documented by Tinyissue\Http\Controlle...ectController::getNotes of type Illuminate\View\View.
Loading history...
133 7
            'tabs'     => $this->projectMainViewTabs($project, 'notes', $notes),
134 7
            'project'  => $project,
135 7
            'active'   => 'notes',
136 7
            'notes'    => $notes,
137 7
            'sidebar'  => 'project',
138 7
            'noteForm' => $form,
139
        ]);
140
    }
141
142
    /**
143
     * @param Project $project
144
     * @param string  $view
145
     * @param null    $data
146
     * @param bool    $status
147
     *
148
     * @return array
149
     */
150 21
    protected function projectMainViewTabs(Project $project, $view, $data = null, $status = false)
151
    {
152 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...
153
154 21
        $assignedIssuesCount = 0;
155 21
        if ($view !== 'assigned' && !$this->auth->guest()) {
156 19
            $method = auth()->user()->isUser()? 'createdIssuesCount' : 'assignedIssuesCount';
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...
157 19
            $assignedIssuesCount = $this->auth->user()->$method($project->id);
158 2
        } elseif ($view === 'assigned' || $view === 'created') {
159 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...
160
        }
161
162 21
        if ($view === 'issues') {
163 2
            if ($status == Issue::STATUS_OPEN) {
164 2
                $closedIssuesCount = $project->closedIssuesCount()->count();
165 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...
166
            } else {
167 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...
168 2
                $openIssuesCount   = $project->openIssuesCount()->count();
169
            }
170
        } else {
171 19
            $openIssuesCount   = $project->openIssuesCount()->count();
172 19
            $closedIssuesCount = $project->closedIssuesCount()->count();
173
        }
174
175 21
        $tabs   = [];
176 21
        $tabs[] = [
177 21
            'url'  => $project->to(),
178 21
            'page' => 'activity',
179
        ];
180 21
        $tabs[] = [
181 21
            'url'    => $project->to('issues'),
182 21
            'page'   => 'open_issue',
183 21
            'prefix' => $openIssuesCount,
184
        ];
185 21
        $tabs[] = [
186 21
            'url'    => $project->to('issues') . '/0',
187 21
            'page'   => 'closed_issue',
188 21
            'prefix' => $closedIssuesCount,
189
        ];
190 21
        if (!$this->auth->guest()) {
191 20
            $tabs[] = [
192 20
                'url'    => $project->to(auth()->user()->isUser()? 'created' : 'assigned'),
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...
193 20
                'page'   => (auth()->user()->isUser()? 'issue_created_by_you' : 'issue_assigned_to_you'),
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...
194 20
                'prefix' => $assignedIssuesCount,
195
            ];
196
        }
197 21
        $tabs[] = [
198 21
            'url'    => $project->to('notes'),
199 21
            'page'   => 'notes',
200 21
            'prefix' => $notesCount,
201
        ];
202
203 21
        return $tabs;
204
    }
205
206
    /**
207
     * Edit the project.
208
     *
209
     * @param Project $project
210
     * @param Form    $form
211
     *
212
     * @return \Illuminate\View\View
213
     */
214 2
    public function getEdit(Project $project, Form $form)
215
    {
216 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 216 which is incompatible with the return type documented by Tinyissue\Http\Controlle...jectController::getEdit of type Illuminate\View\View.
Loading history...
217 2
            'form'    => $form,
218 2
            'project' => $project,
219 2
            'sidebar' => 'project',
220
        ]);
221
    }
222
223
    /**
224
     * To update project details.
225
     *
226
     * @param Project             $project
227
     * @param FormRequest\Project $request
228
     *
229
     * @return \Illuminate\Http\RedirectResponse
230
     */
231 2
    public function postEdit(Project $project, FormRequest\Project $request)
232
    {
233
        // Delete the project
234 2
        if ($request->has('delete-project')) {
235 1
            $project->delete();
236
237 1
            return redirect('projects')
238 1
                ->with('notice', trans('tinyissue.project_has_been_deleted'));
239
        }
240
241 1
        $project->update($request->all());
242
243 1
        return redirect($project->to())
244 1
            ->with('notice', trans('tinyissue.project_has_been_updated'));
245
    }
246
247
    /**
248
     * Ajax: returns list of users that are not in the project.
249
     *
250
     * @param Project $project
251
     *
252
     * @return \Symfony\Component\HttpFoundation\Response
253
     */
254 1
    public function getInactiveUsers(Project $project = null)
255
    {
256 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...
257
258 1
        return response()->json($users);
259
    }
260
261
    /**
262
     * Ajax: add user to the project.
263
     *
264
     * @param Project $project
265
     * @param Request $request
266
     *
267
     * @return \Symfony\Component\HttpFoundation\Response
268
     */
269 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...
270
    {
271 1
        $status = false;
272 1
        if ($request->has('user_id')) {
273 1
            $project->assignUser((int) $request->input('user_id'));
274 1
            $status = true;
275
        }
276
277 1
        return response()->json(['status' => $status]);
278
    }
279
280
    /**
281
     * Ajax: remove user from the project.
282
     *
283
     * @param Project $project
284
     * @param Request $request
285
     *
286
     * @return \Symfony\Component\HttpFoundation\Response
287
     */
288 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...
289
    {
290 1
        $status = false;
291 1
        if ($request->has('user_id')) {
292 1
            $project->unassignUser((int) $request->input('user_id'));
293 1
            $status = true;
294
        }
295
296 1
        return response()->json(['status' => $status]);
297
    }
298
299
    /**
300
     * To add a new note to the project.
301
     *
302
     * @param Project          $project
303
     * @param Note             $note
304
     * @param FormRequest\Note $request
305
     *
306
     * @return \Illuminate\Http\RedirectResponse
307
     */
308 2
    public function postAddNote(Project $project, Note $note, FormRequest\Note $request)
309
    {
310 2
        $note->setRelation('project', $project);
311 2
        $note->setRelation('createdBy', $this->auth->user());
312 2
        $note->createNote($request->all());
313
314 2
        return redirect($note->to())->with('notice', trans('tinyissue.your_note_added'));
315
    }
316
317
    /**
318
     * Ajax: To update project note.
319
     *
320
     * @param Project $project
321
     * @param Note    $note
322
     * @param Request $request
323
     *
324
     * @return \Symfony\Component\HttpFoundation\Response
325
     */
326 1
    public function postEditNote(Project $project, Project\Note $note, Request $request)
327
    {
328 1
        $body = '';
329 1
        if ($request->has('body')) {
330 1
            $note->setRelation('project', $project);
331 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...
332
333 1
            $body = \Html::format($note->body);
334
        }
335
336 1
        return response()->json(['status' => true, 'text' => $body]);
337
    }
338
339
    /**
340
     * Ajax: to delete a project note.
341
     *
342
     * @param Project $project
343
     * @param Note    $note
344
     *
345
     * @return \Symfony\Component\HttpFoundation\Response
346
     */
347 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...
348
    {
349 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...
350
351 1
        return response()->json(['status' => true]);
352
    }
353
354
    /**
355
     * Ajax: generate the issues export file.
356
     *
357
     * @param Project  $project
358
     * @param Exporter $exporter
359
     * @param Request  $request
360
     *
361
     * @return \Symfony\Component\HttpFoundation\Response
362
     */
363 4
    public function postExportIssues(Project $project, Exporter $exporter, Request $request)
364
    {
365
        // Generate export file
366 4
        $info = $exporter->exportFile(
367 4
            'Project\Issue',
368 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...
369 4
            $request->all()
370
        );
371
372
        // Download link
373 4
        $link = link_to(
374 4
            $project->to('download_export/' . $info['file']),
375 4
            trans('tinyissue.download_export'),
0 ignored issues
show
Bug introduced by
It seems like trans('tinyissue.download_export') targeting trans() can also be of type object<Symfony\Component...on\TranslatorInterface>; however, link_to() 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...
376 4
            ['class' => 'btn btn-link']
377
        );
378
379 4
        return response()->json([
380 4
            'link'  => $link,
381 4
            'title' => $info['title'],
382 4
            'file'  => $info['file'],
383 4
            'ext'   => $info['ext'],
384
        ]);
385
    }
386
387
    /**
388
     * Download and then delete an export file.
389
     *
390
     * @param Project $project
391
     * @param string  $file
392
     *
393
     * @return \Symfony\Component\HttpFoundation\BinaryFileResponse
394
     */
395 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...
396
    {
397
        // Filter out any characters that are not in pattern
398 4
        $file = preg_replace('/[^a-z0-9\_\.]/mi', '', $file);
399
400
        // Download export
401 4
        return response()->download(storage_path('exports/' . $file), $file)->deleteFileAfterSend(true);
402
    }
403
}
404