Completed
Branch develop-3.0 (4fe777)
by Mohamed
11:06
created

ProjectController::indexView()   B

Complexity

Conditions 7
Paths 4

Size

Total Lines 18
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 18
rs 8.2222
c 0
b 0
f 0
cc 7
eloc 12
nc 4
nop 3
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\Collection;
15
use Illuminate\Http\Request;
16
use Tinyissue\Contracts\Repository\Project\ProjectRepository;
17
use Tinyissue\Form\FilterIssue as FilterForm;
18
use Tinyissue\Form\Note as NoteForm;
19
use Tinyissue\Form\Project as Form;
20
use Tinyissue\Http\Requests\FormRequest;
21
use Tinyissue\Model\Project;
22
use Tinyissue\Model\Project\Issue;
23
use Tinyissue\Model\Project\Note;
24
use Tinyissue\Repository\Project\Note\NoteRepository;
25
use Tinyissue\Repository\Role\RoleRepository;
26
use Tinyissue\Services\Exporter;
27
28
/**
29
 * ProjectController is the controller class for managing request related to a project.
30
 *
31
 * @author Mohamed Alsharaf <[email protected]>
32
 */
33
class ProjectController extends Controller
34
{
35
    protected function indexView($data, $active, ProjectRepository $project)
36
    {
37
        $isUser            = $this->isLoggedIn() && $this->getLoggedUser()->isUser();
38
        $isInternalProject = $project->isPrivateInternal();
0 ignored issues
show
Bug introduced by
The method isPrivateInternal() does not seem to exist on object<Tinyissue\Contrac...ject\ProjectRepository>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
39
40
        if (array_key_exists('assigned_issues_count', $data) && $this->isLoggedIn() && (!$isInternalProject || (!$isUser && $isInternalProject))) {
41
            $data['created_issues_count'] = $project->countCreatedIssues($this->getLoggedUser());
0 ignored issues
show
Bug introduced by
The method countCreatedIssues() does not seem to exist on object<Tinyissue\Contrac...ject\ProjectRepository>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
42
        } else {
43
            $data['assigned_issues_count'] = $project->countAssignedIssues($this->getLoggedUser());
0 ignored issues
show
Bug introduced by
The method countAssignedIssues() does not seem to exist on object<Tinyissue\Contrac...ject\ProjectRepository>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
44
        }
45
46
        $data['sidebar']           = 'project';
47
        $data['active']            = $active;
48
        $data['project']           = $project;
49
        $data['usersCanFixIssues'] = $project->getUsersCanFixIssue();
50
51
        return view('project.index', $data);
52
    }
53
54
    /**
55
     * Display activity for a project.
56
     *
57
     * @param ProjectRepository $project
58
     *
59
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
60
     */
61 View Code Duplication
    public function getIndex(ProjectRepository $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...
62
    {
63
        $activities = $project->getRecentActivities($this->getLoggedUser());
64
65
        return $this->indexView([
66
            'activities'          => $activities,
67
            'notes_count'         => $project->countNotes(),
0 ignored issues
show
Bug introduced by
The method countNotes() does not seem to exist on object<Tinyissue\Contrac...ject\ProjectRepository>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
68
            'open_issues_count'   => $project->countOpenIssues($this->getLoggedUser()),
0 ignored issues
show
Bug introduced by
The method countOpenIssues() does not seem to exist on object<Tinyissue\Contrac...ject\ProjectRepository>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
69
            'closed_issues_count' => $project->countClosedIssues($this->getLoggedUser()),
0 ignored issues
show
Bug introduced by
The method countClosedIssues() does not seem to exist on object<Tinyissue\Contrac...ject\ProjectRepository>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
70
        ], 'activity', $project);
71
    }
72
73
    /**
74
     * Display issues for a project.
75
     *
76
     * @param FilterForm        $filterForm
77
     * @param Request           $request
78
     * @param ProjectRepository $project
79
     * @param int               $status
80
     *
81
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
82
     */
83
    public function getIssues(FilterForm $filterForm, Request $request, ProjectRepository $project, $status = Issue::STATUS_OPEN)
84
    {
85
        if ($project->isPrivateInternal() && $this->getLoggedUser()->isUser()) {
0 ignored issues
show
Bug introduced by
The method isPrivateInternal() does not seem to exist on object<Tinyissue\Contrac...ject\ProjectRepository>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
86
            $request['created_by'] = $this->getLoggedUser()->id;
0 ignored issues
show
Bug introduced by
Accessing id on the interface Tinyissue\Contracts\Model\UserInterface 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...
87
        }
88
        $issues = $project->getIssues($status, $request->all());
89
90
        if ($status === Issue::STATUS_OPEN) {
91
            $data = $this->getOpenIssuesViewData($issues, $project);
92
        } else {
93
            $data = $this->getClosedIssuesViewData($issues, $project);
94
        }
95
96
        $data['notes_count'] = $project->countNotes();
0 ignored issues
show
Bug introduced by
The method countNotes() does not seem to exist on object<Tinyissue\Contrac...ject\ProjectRepository>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
97
        $data['issues']      = $issues;
98
        $data['filterForm']  = $filterForm;
99
100
        return $this->indexView($data, $data['active'], $project);
101
    }
102
103
    protected function getOpenIssuesViewData(Collection $issues, ProjectRepository $project)
104
    {
105
        return [
106
            'open_issues_count'   => $issues->count(),
107
            'closed_issues_count' => $project->countClosedIssues($this->getLoggedUser()),
0 ignored issues
show
Bug introduced by
The method countClosedIssues() does not seem to exist on object<Tinyissue\Contrac...ject\ProjectRepository>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
108
            'active'              => 'open_issues',
109
        ];
110
    }
111
112
    protected function getClosedIssuesViewData(Collection $issues, ProjectRepository $project)
113
    {
114
        return [
115
            'open_issues_count'   => $project->countOpenIssues($this->getLoggedUser()),
0 ignored issues
show
Bug introduced by
The method countOpenIssues() does not seem to exist on object<Tinyissue\Contrac...ject\ProjectRepository>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
116
            'closed_issues_count' => $issues->count(),
117
            'active'              => 'closed_issues',
118
        ];
119
    }
120
121
    /**
122
     * Display issues assigned to current user for a project.
123
     *
124
     * @param ProjectRepository $project
125
     *
126
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
127
     */
128 View Code Duplication
    public function getAssigned(ProjectRepository $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...
129
    {
130
        $issues = $project->getAssignedOrCreatedIssues($this->getLoggedUser());
131
132
        return $this->indexView([
133
            'notes_count'           => $project->countNotes(),
0 ignored issues
show
Bug introduced by
The method countNotes() does not seem to exist on object<Tinyissue\Contrac...ject\ProjectRepository>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
134
            'open_issues_count'     => $project->countOpenIssues($this->getLoggedUser()),
0 ignored issues
show
Bug introduced by
The method countOpenIssues() does not seem to exist on object<Tinyissue\Contrac...ject\ProjectRepository>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
135
            'closed_issues_count'   => $project->countClosedIssues($this->getLoggedUser()),
0 ignored issues
show
Bug introduced by
The method countClosedIssues() does not seem to exist on object<Tinyissue\Contrac...ject\ProjectRepository>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
136
            'assigned_issues_count' => $issues->count(),
137
            'issues'                => $issues,
138
        ], 'activity', $project);
139
    }
140
141
    /**
142
     * Display issues created to current user for a project.
143
     *
144
     * @param ProjectRepository $project
145
     *
146
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
147
     */
148 View Code Duplication
    public function getCreated(ProjectRepository $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...
149
    {
150
        $issues = $project->getAssignedOrCreatedIssues($this->getLoggedUser());
151
152
        return $this->indexView([
153
            'notes_count'           => $project->countNotes(),
0 ignored issues
show
Bug introduced by
The method countNotes() does not seem to exist on object<Tinyissue\Contrac...ject\ProjectRepository>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
154
            'open_issues_count'     => $project->countOpenIssues($this->getLoggedUser()),
0 ignored issues
show
Bug introduced by
The method countOpenIssues() does not seem to exist on object<Tinyissue\Contrac...ject\ProjectRepository>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
155
            'closed_issues_count'   => $project->countClosedIssues($this->getLoggedUser()),
0 ignored issues
show
Bug introduced by
The method countClosedIssues() does not seem to exist on object<Tinyissue\Contrac...ject\ProjectRepository>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
156
            'assigned_issues_count' => $issues->count(),
157
            'issues'                => $issues,
158
        ], 'issue_created_by_you', $project);
159
    }
160
161
    /**
162
     * Display notes for a project.
163
     *
164
     * @param ProjectRepository $project
165
     * @param NoteForm          $form
166
     *
167
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
168
     */
169 View Code Duplication
    public function getNotes(ProjectRepository $project, NoteForm $form)
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...
Unused Code introduced by
The parameter $form 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...
170
    {
171
        $notes = $project->getNotes();
172
173
        return $this->indexView([
174
            'notes_count'         => $project->countNotes(),
0 ignored issues
show
Bug introduced by
The method countNotes() does not seem to exist on object<Tinyissue\Contrac...ject\ProjectRepository>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
175
            'open_issues_count'   => $project->countOpenIssues($this->getLoggedUser()),
0 ignored issues
show
Bug introduced by
The method countOpenIssues() does not seem to exist on object<Tinyissue\Contrac...ject\ProjectRepository>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
176
            'closed_issues_count' => $project->countClosedIssues($this->getLoggedUser()),
0 ignored issues
show
Bug introduced by
The method countClosedIssues() does not seem to exist on object<Tinyissue\Contrac...ject\ProjectRepository>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
177
            'notes'               => $notes,
178
            'notes_count'         => $notes->count(),
179
        ], 'notes', $project);
180
    }
181
182
    /**
183
     * @param Project $project
184
     * @param string  $view
185
     * @param null    $data
186
     * @param bool    $status
187
     *
188
     * @return array
189
     */
190
    protected function projectMainViewTabs(ProjectRepository $project, $view, $data = null, $status = false)
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...
Unused Code introduced by
The parameter $view 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...
Unused Code introduced by
The parameter $data 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...
Unused Code introduced by
The parameter $status 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...
191
    {
192
        return null;
193
        $user              = $this->getLoggedUser();
0 ignored issues
show
Unused Code introduced by
$user = $this->getLoggedUser(); does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
194
        $isLoggedIn        = !$this->auth->guest();
195
        $isUser            = $isLoggedIn && $user->isUser();
196
        $isInternalProject = $project->isPrivateInternal();
197
198
        if ($view === 'note') {
199
            $notesCount = !is_null($data) ? $data->count() : 0;
200
        } else {
201
            $notesCount = $project->countNotes();
202
        }
203
204
        if ($view === 'issues') {
205
            if ($status == Issue::STATUS_OPEN) {
206
                $closedIssuesCount = $project->closedIssuesCount($user)->count();
207
                $openIssuesCount   = !is_null($data) ? $data->count() : 0;
208
            } else {
209
                $closedIssuesCount = !is_null($data) ? $data->count() : 0;
210
                $openIssuesCount   = $project->openIssuesCount($user)->count();
211
            }
212
        } else {
213
            $openIssuesCount   = $project->openIssuesCount($user)->count();
214
            $closedIssuesCount = $project->closedIssuesCount($user)->count();
215
        }
216
217
        $tabs   = [];
218
        $tabs[] = [
219
            'url'  => $project->to(),
220
            'page' => 'activity',
221
        ];
222
        $tabs[] = [
223
            'url'    => $project->to('issues'),
224
            'page'   => 'open_issue',
225
            'prefix' => $openIssuesCount,
226
        ];
227
        $tabs[] = [
228
            'url'    => $project->to('issues') . '/0',
229
            'page'   => 'closed_issue',
230
            'prefix' => $closedIssuesCount,
231
        ];
232
        if ($isLoggedIn && (!$isInternalProject || (!$isUser && $isInternalProject))) {
233
            if ($view !== 'assigned') {
234
                $method              = $isUser ? 'createdIssuesCount' : 'assignedIssuesCount';
235
                $assignedIssuesCount = $this->getLoggedUser()->$method($project->id);
236
            } else {
237
                $assignedIssuesCount = !is_null($data) ? $data->count() : 0;
238
            }
239
240
            $tabs[] = [
241
                'url'    => $project->to($isUser ? 'created' : 'assigned'),
242
                'page'   => ($isUser ? 'issue_created_by_you' : 'issue_assigned_to_you'),
243
                'prefix' => $assignedIssuesCount,
244
            ];
245
        }
246
        $tabs[] = [
247
            'url'    => $project->to('notes'),
248
            'page'   => 'notes',
249
            'prefix' => $notesCount,
250
        ];
251
252
        return $tabs;
253
    }
254
255
    /**
256
     * Edit the project.
257
     *
258
     * @param Project $project
259
     * @param Form    $form
260
     *
261
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
262
     */
263
    public function getEdit(ProjectRepository $project, Form $form)
264
    {
265
        return view('project.edit', [
266
            'form'    => $form,
267
            'project' => $project,
268
            'sidebar' => 'project',
269
        ]);
270
    }
271
272
    /**
273
     * To update project details.
274
     *
275
     * @param Project             $project
276
     * @param FormRequest\Project $request
277
     *
278
     * @return \Illuminate\Http\RedirectResponse
279
     */
280
    public function postEdit(ProjectRepository $project, FormRequest\Project $request)
281
    {
282
        // Delete the project
283
        if ($request->has('delete-project')) {
284
            $project->delete();
0 ignored issues
show
Bug introduced by
The method delete() does not seem to exist on object<Tinyissue\Contrac...ject\ProjectRepository>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
285
286
            return redirect('projects')
287
                ->with('notice', trans('tinyissue.project_has_been_deleted'));
288
        }
289
290
        $project->update($request->all());
0 ignored issues
show
Bug introduced by
The method update() does not exist on Tinyissue\Contracts\Repo...oject\ProjectRepository. Did you maybe mean updater()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
291
292
        return redirect($project->to())
0 ignored issues
show
Bug introduced by
The method to() does not seem to exist on object<Tinyissue\Contrac...ject\ProjectRepository>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
293
            ->with('notice', trans('tinyissue.project_has_been_updated'));
294
    }
295
296
    /**
297
     * Ajax: returns list of users that are not in the project.
298
     *
299
     * @param Project $project
300
     *
301
     * @return \Symfony\Component\HttpFoundation\Response
302
     */
303
    public function getInactiveUsers(ProjectRepository $project)
304
    {
305
        $users = $project->getNotMembers()->dropdown('fullname');
0 ignored issues
show
Bug introduced by
The method dropdown cannot be called on $project->getNotMembers() (of type array).

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...
306
307
        return response()->json($users);
308
    }
309
310
    /**
311
     * Ajax: add user to the project.
312
     *
313
     * @param Project $project
314
     * @param Request $request
315
     *
316
     * @return \Symfony\Component\HttpFoundation\Response
317
     */
318
    public function postAssign(ProjectRepository $project, Request $request)
319
    {
320
        $status = $project->assignUser((int) $request->input('user_id'));
0 ignored issues
show
Bug introduced by
The method assignUser() does not seem to exist on object<Tinyissue\Contrac...ject\ProjectRepository>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
321
322
        return response()->json(['status' => (bool) $status]);
323
    }
324
325
    /**
326
     * Ajax: remove user from the project.
327
     *
328
     * @param Project $project
329
     * @param Request $request
330
     *
331
     * @return \Symfony\Component\HttpFoundation\Response
332
     */
333
    public function postUnassign(RoleRepository $project, Request $request)
334
    {
335
        $status = $project->unassignUser((int) $request->input('user_id'));
0 ignored issues
show
Documentation Bug introduced by
The method unassignUser does not exist on object<Tinyissue\Repository\Role\RoleRepository>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
336
337
        return response()->json(['status' => (bool) $status]);
338
    }
339
340
    /**
341
     * To add a new note to the project.
342
     *
343
     * @param Project          $project
344
     * @param Note             $note
345
     * @param FormRequest\Note $request
346
     *
347
     * @return \Illuminate\Http\RedirectResponse
348
     */
349
    public function postAddNote(ProjectRepository $project, NoteRepository $note, FormRequest\Note $request)
350
    {
351
        $note->setRelation('project', $project);
0 ignored issues
show
Documentation Bug introduced by
The method setRelation does not exist on object<Tinyissue\Reposit...ct\Note\NoteRepository>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
352
        $note->setRelation('createdBy', $this->getLoggedUser());
0 ignored issues
show
Documentation Bug introduced by
The method setRelation does not exist on object<Tinyissue\Reposit...ct\Note\NoteRepository>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
353
        $note->createNote($request->all());
0 ignored issues
show
Documentation Bug introduced by
The method createNote does not exist on object<Tinyissue\Reposit...ct\Note\NoteRepository>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
354
355
        return redirect($note->to())->with('notice', trans('tinyissue.your_note_added'));
0 ignored issues
show
Documentation Bug introduced by
The method to does not exist on object<Tinyissue\Reposit...ct\Note\NoteRepository>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
356
    }
357
358
    /**
359
     * Ajax: To update project note.
360
     *
361
     * @param Project $project
362
     * @param Note    $note
363
     * @param Request $request
364
     *
365
     * @return \Symfony\Component\HttpFoundation\Response
366
     */
367
    public function postEditNote(ProjectRepository $project, \Tinyissue\Contracts\Repository\Project\NoteRepository $note, Request $request)
368
    {
369
        $body = '';
370
        if ($request->has('body')) {
371
            $note->setRelation('project', $project);
372
            $note->updateBody($request->input('body'), $this->getLoggedUser());
373
374
            $body = \Html::format($note->body);
375
        }
376
377
        return response()->json(['status' => true, 'text' => $body]);
378
    }
379
380
    /**
381
     * Ajax: to delete a project note.
382
     *
383
     * @param Project $project
384
     * @param Note    $note
385
     *
386
     * @return \Symfony\Component\HttpFoundation\Response
387
     */
388
    public function getDeleteNote(ProjectRepository $project, \Tinyissue\Contracts\Repository\Project\NoteRepository $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...
389
    {
390
        $note->deleteNote($this->getLoggedUser());
391
392
        return response()->json(['status' => true]);
393
    }
394
395
    /**
396
     * Ajax: generate the issues export file.
397
     *
398
     * @param Project  $project
399
     * @param Exporter $exporter
400
     * @param Request  $request
401
     *
402
     * @return \Symfony\Component\HttpFoundation\Response
403
     */
404
    public function postExportIssues(ProjectRepository $project, Exporter $exporter, Request $request)
405
    {
406
        // Generate export file
407
        $info = $exporter->exportFile(
408
            'Project\Issue',
409
            $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...
410
            $request->all()
411
        );
412
413
        // Download link
414
        $link = link_to(
415
            $project->to('download_export/' . $info['file']),
0 ignored issues
show
Bug introduced by
The method to() does not seem to exist on object<Tinyissue\Contrac...ject\ProjectRepository>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
416
            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...
417
            ['class' => 'btn btn-link']
418
        );
419
420
        return response()->json([
421
            'link'  => $link,
422
            'title' => $info['title'],
423
            'file'  => $info['file'],
424
            'ext'   => $info['ext'],
425
        ]);
426
    }
427
428
    /**
429
     * Download and then delete an export file.
430
     *
431
     * @param Project $project
432
     * @param string  $file
433
     *
434
     * @return \Symfony\Component\HttpFoundation\BinaryFileResponse
435
     */
436
    public function getDownloadExport(ProjectRepository $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...
437
    {
438
        // Filter out any characters that are not in pattern
439
        $file = preg_replace('/[^a-z0-9\_\.]/mi', '', $file);
440
441
        // Download export
442
        return response()->download(storage_path('exports/' . $file), $file)->deleteFileAfterSend(true);
443
    }
444
}
445