Completed
Branch develop-3.0 (ae28cb)
by Mohamed
08:28
created

ProjectController::getCreated()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 9

Duplication

Lines 12
Ratio 100 %

Importance

Changes 0
Metric Value
dl 12
loc 12
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 9
nc 1
nop 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\Contracts\View\Factory|\Illuminate\View\View
37
     */
38 View Code Duplication
    public function getIndex(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...
39
    {
40
        $activities = $project->getRecentActivities($this->getLoggedUser());
0 ignored issues
show
Bug introduced by
The method getRecentActivities() does not exist on Tinyissue\Model\Project. Did you maybe mean activities()?

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...
41
42
        return $this->indexView([
43
            'activities'          => $activities,
44
            'notes_count'         => $project->countNotes(),
0 ignored issues
show
Documentation Bug introduced by
The method countNotes does not exist on object<Tinyissue\Model\Project>? 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...
45
            'open_issues_count'   => $project->countOpenIssues($this->getLoggedUser()),
0 ignored issues
show
Bug introduced by
The method countOpenIssues() does not exist on Tinyissue\Model\Project. Did you maybe mean issues()?

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...
46
            'closed_issues_count' => $project->countClosedIssues($this->getLoggedUser()),
0 ignored issues
show
Bug introduced by
The method countClosedIssues() does not exist on Tinyissue\Model\Project. Did you maybe mean issues()?

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...
47
        ], 'activity', $project);
48
    }
49
50
    /**
51
     * Display issues for a project.
52
     *
53
     * @param FilterForm $filterForm
54
     * @param Request    $request
55
     * @param Project    $project
56
     * @param int        $status
57
     *
58
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
59
     */
60
    public function getIssues(FilterForm $filterForm, Request $request, Project $project, $status = Issue::STATUS_OPEN)
61
    {
62
        if ($status === Issue::STATUS_OPEN) {
63
            return $this->getOpenIssues($filterForm, $request, $project);
64
        }
65
66
        return $this->getClosedIssues($filterForm, $request, $project);
67
    }
68
69
    /**
70
     * Display open issues.
71
     *
72
     * @param FilterForm $filterForm
73
     * @param Request    $request
74
     * @param Project    $project
75
     *
76
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
77
     */
78 View Code Duplication
    public function getOpenIssues(FilterForm $filterForm, Request $request, 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...
79
    {
80
        $issues = $project->getIssuesForLoggedUser(Issue::STATUS_OPEN, $request->all());
0 ignored issues
show
Bug introduced by
The method getIssuesForLoggedUser() does not exist on Tinyissue\Model\Project. Did you maybe mean issues()?

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...
81
82
        return $this->indexView([
83
            'notes_count'         => $project->countNotes(),
0 ignored issues
show
Documentation Bug introduced by
The method countNotes does not exist on object<Tinyissue\Model\Project>? 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...
84
            'issues'              => $issues,
85
            'filterForm'          => $filterForm,
86
            'open_issues_count'   => $issues->count(),
87
            'closed_issues_count' => $project->countClosedIssues($this->getLoggedUser()),
0 ignored issues
show
Bug introduced by
The method countClosedIssues() does not exist on Tinyissue\Model\Project. Did you maybe mean issues()?

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...
88
        ], 'open_issues', $project);
89
    }
90
91
    /**
92
     * Display closed issues.
93
     *
94
     * @param FilterForm $filterForm
95
     * @param Request    $request
96
     * @param Project    $project
97
     *
98
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
99
     */
100 View Code Duplication
    public function getClosedIssues(FilterForm $filterForm, Request $request, 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...
101
    {
102
        $issues = $project->getIssuesForLoggedUser(Issue::STATUS_CLOSED, $request->all());
0 ignored issues
show
Bug introduced by
The method getIssuesForLoggedUser() does not exist on Tinyissue\Model\Project. Did you maybe mean issues()?

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...
103
104
        return $this->indexView([
105
            'notes_count'         => $project->countNotes(),
0 ignored issues
show
Documentation Bug introduced by
The method countNotes does not exist on object<Tinyissue\Model\Project>? 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...
106
            'issues'              => $issues,
107
            'filterForm'          => $filterForm,
108
            'open_issues_count'   => $project->countOpenIssues($this->getLoggedUser()),
0 ignored issues
show
Bug introduced by
The method countOpenIssues() does not exist on Tinyissue\Model\Project. Did you maybe mean issues()?

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...
109
            'closed_issues_count' => $issues->count(),
110
        ], 'closed_issues', $project);
111
    }
112
113
    /**
114
     * Display issues assigned to current user for a project.
115
     *
116
     * @param Project $project
117
     *
118
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
119
     */
120 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...
121
    {
122
        $issues = $project->getAssignedOrCreatedIssues($this->getLoggedUser());
0 ignored issues
show
Bug introduced by
The method getAssignedOrCreatedIssues() does not exist on Tinyissue\Model\Project. Did you maybe mean create()?

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...
123
124
        return $this->indexView([
125
            'notes_count'           => $project->countNotes(),
0 ignored issues
show
Documentation Bug introduced by
The method countNotes does not exist on object<Tinyissue\Model\Project>? 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...
126
            'open_issues_count'     => $project->countOpenIssues($this->getLoggedUser()),
0 ignored issues
show
Bug introduced by
The method countOpenIssues() does not exist on Tinyissue\Model\Project. Did you maybe mean issues()?

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...
127
            'closed_issues_count'   => $project->countClosedIssues($this->getLoggedUser()),
0 ignored issues
show
Bug introduced by
The method countClosedIssues() does not exist on Tinyissue\Model\Project. Did you maybe mean issues()?

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...
128
            'assigned_issues_count' => $issues->count(),
129
            'issues'                => $issues,
130
        ], 'activity', $project);
131
    }
132
133
    /**
134
     * Display issues created to current user for a project.
135
     *
136
     * @param Project $project
137
     *
138
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
139
     */
140 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...
141
    {
142
        $issues = $project->getAssignedOrCreatedIssues($this->getLoggedUser());
0 ignored issues
show
Bug introduced by
The method getAssignedOrCreatedIssues() does not exist on Tinyissue\Model\Project. Did you maybe mean create()?

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...
143
144
        return $this->indexView([
145
            'notes_count'           => $project->countNotes(),
0 ignored issues
show
Documentation Bug introduced by
The method countNotes does not exist on object<Tinyissue\Model\Project>? 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...
146
            'open_issues_count'     => $project->countOpenIssues($this->getLoggedUser()),
0 ignored issues
show
Bug introduced by
The method countOpenIssues() does not exist on Tinyissue\Model\Project. Did you maybe mean issues()?

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...
147
            'closed_issues_count'   => $project->countClosedIssues($this->getLoggedUser()),
0 ignored issues
show
Bug introduced by
The method countClosedIssues() does not exist on Tinyissue\Model\Project. Did you maybe mean issues()?

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...
148
            'assigned_issues_count' => $issues->count(),
149
            'issues'                => $issues,
150
        ], 'issue_created_by_you', $project);
151
    }
152
153
    /**
154
     * Display notes for a project.
155
     *
156
     * @param Project  $project
157
     * @param NoteForm $form
158
     *
159
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
160
     */
161 View Code Duplication
    public function getNotes(Project $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...
162
    {
163
        $notes = $project->getNotes();
0 ignored issues
show
Documentation Bug introduced by
The method getNotes does not exist on object<Tinyissue\Model\Project>? 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...
164
165
        return $this->indexView([
166
            'notes_count'         => $project->countNotes(),
0 ignored issues
show
Documentation Bug introduced by
The method countNotes does not exist on object<Tinyissue\Model\Project>? 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...
167
            'open_issues_count'   => $project->countOpenIssues($this->getLoggedUser()),
0 ignored issues
show
Bug introduced by
The method countOpenIssues() does not exist on Tinyissue\Model\Project. Did you maybe mean issues()?

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...
168
            'closed_issues_count' => $project->countClosedIssues($this->getLoggedUser()),
0 ignored issues
show
Bug introduced by
The method countClosedIssues() does not exist on Tinyissue\Model\Project. Did you maybe mean issues()?

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...
169
            'notes'               => $notes,
170
            'notes_count'         => $notes->count(),
171
            'noteForm'            => $form,
172
        ], 'notes', $project);
173
    }
174
175
    /**
176
     * @param mixed   $data
177
     * @param string  $active
178
     * @param Project $project
179
     *
180
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
181
     */
182
    protected function indexView($data, $active, Project $project)
183
    {
184
        // For logged users that is not a normal user
185
        if (!array_key_exists('assigned_issues_count', $data) && $this->isLoggedIn() && !$this->isLoggedNormalUser()) {
186
            $data['assigned_issues_count'] = $project->countAssignedIssues($this->getLoggedUser());
0 ignored issues
show
Bug introduced by
The method countAssignedIssues() does not exist on Tinyissue\Model\Project. Did you maybe mean issues()?

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...
187
        } elseif ($this->isLoggedNormalUser() && $project->isPrivateInternal()) {
188
            $data['created_issues_count'] = $project->countCreatedIssues($this->getLoggedUser());
0 ignored issues
show
Bug introduced by
The method countCreatedIssues() does not exist on Tinyissue\Model\Project. Did you maybe mean create()?

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...
189
        }
190
191
        $data['sidebar']           = 'project';
192
        $data['active']            = $active;
193
        $data['project']           = $project;
194
        $data['usersCanFixIssues'] = $project->getUsersCanFixIssue();
0 ignored issues
show
Documentation Bug introduced by
The method getUsersCanFixIssue does not exist on object<Tinyissue\Model\Project>? 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...
195
196
        return view('project.index', $data);
197
    }
198
199
    /**
200
     * Edit the project.
201
     *
202
     * @param Project $project
203
     * @param Form    $form
204
     *
205
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
206
     */
207
    public function getEdit(Project $project, Form $form)
208
    {
209
        return view('project.edit', [
210
            'form'    => $form,
211
            'project' => $project,
212
            'sidebar' => 'project',
213
        ]);
214
    }
215
216
    /**
217
     * To update project details.
218
     *
219
     * @param Project             $project
220
     * @param FormRequest\Project $request
221
     *
222
     * @return \Illuminate\Http\RedirectResponse
223
     */
224
    public function postEdit(Project $project, FormRequest\Project $request)
225
    {
226
        // Delete the project
227
        if ($request->has('delete-project')) {
228
            $project->updater()->delete();
229
230
            return redirect('projects')
231
                ->with('notice', trans('tinyissue.project_has_been_deleted'));
232
        }
233
234
        $project->updater()->update($request->all());
235
236
        return redirect($project->to())
237
            ->with('notice', trans('tinyissue.project_has_been_updated'));
238
    }
239
240
    /**
241
     * Ajax: returns list of users that are not in the project.
242
     *
243
     * @param Project $project
244
     *
245
     * @return \Symfony\Component\HttpFoundation\Response
246
     */
247
    public function getInactiveUsers(Project $project)
248
    {
249
        $users = $project->getNotMembers()->dropdown('fullname');
0 ignored issues
show
Documentation Bug introduced by
The method getNotMembers does not exist on object<Tinyissue\Model\Project>? 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...
250
251
        return response()->json($users);
252
    }
253
254
    /**
255
     * Ajax: add user to the project.
256
     *
257
     * @param Project $project
258
     * @param Request $request
259
     *
260
     * @return \Symfony\Component\HttpFoundation\Response
261
     */
262
    public function postAssign(Project $project, Request $request)
263
    {
264
        $status = $project->assignUser((int) $request->input('user_id'));
0 ignored issues
show
Documentation Bug introduced by
The method assignUser does not exist on object<Tinyissue\Model\Project>? 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...
265
266
        return response()->json(['status' => (bool) $status]);
267
    }
268
269
    /**
270
     * Ajax: remove user from the project.
271
     *
272
     * @param Project $project
273
     * @param Request $request
274
     *
275
     * @return \Symfony\Component\HttpFoundation\Response
276
     */
277
    public function postUnassign(Project $project, Request $request)
278
    {
279
        $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\Model\Project>? 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...
280
281
        return response()->json(['status' => (bool) $status]);
282
    }
283
284
    /**
285
     * To add a new note to the project.
286
     *
287
     * @param Project          $project
288
     * @param Note             $note
289
     * @param FormRequest\Note $request
290
     *
291
     * @return \Illuminate\Http\RedirectResponse
292
     */
293 View Code Duplication
    public function postAddNote(Project $project, Note $note, FormRequest\Note $request)
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...
294
    {
295
        $note->setRelation('project', $project);
296
        $note->setRelation('createdBy', $this->getLoggedUser());
297
        $note->updater($this->getLoggedUser())->create($request->all());
298
299
        return redirect($note->to())->with('notice', trans('tinyissue.your_note_added'));
300
    }
301
302
    /**
303
     * Ajax: To update project note.
304
     *
305
     * @param Project $project
306
     * @param Note    $note
307
     * @param Request $request
308
     *
309
     * @return \Symfony\Component\HttpFoundation\Response
310
     */
311
    public function postEditNote(Project $project, Note $note, Request $request)
312
    {
313
        $body = '';
314 View Code Duplication
        if ($request->has('body')) {
1 ignored issue
show
Duplication introduced by
This code seems to be duplicated across 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...
315
            $note->setRelation('project', $project);
316
            $note->updater($this->getLoggedUser())->updateBody($request->input('body'), $this->getLoggedUser());
317
318
            $body = \Html::format($note->body);
319
        }
320
321
        return response()->json(['status' => true, 'text' => $body]);
322
    }
323
324
    /**
325
     * Ajax: to delete a project note.
326
     *
327
     * @param Project $project
328
     * @param Note    $note
329
     *
330
     * @return \Symfony\Component\HttpFoundation\Response
331
     */
332
    public function getDeleteNote(Project $project, Note $note)
333
    {
334
        $note->setRelation('project', $project);
335
        $note->updater($this->getLoggedUser())->delete();
336
337
        return response()->json(['status' => true]);
338
    }
339
340
    /**
341
     * Ajax: generate the issues export file.
342
     *
343
     * @param Project  $project
344
     * @param Exporter $exporter
345
     * @param Request  $request
346
     *
347
     * @return \Symfony\Component\HttpFoundation\Response
348
     */
349
    public function postExportIssues(Project $project, Exporter $exporter, Request $request)
350
    {
351
        // Generate export file
352
        $info = $exporter->exportFile(
353
            'Project\Issue',
354
            $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...
355
            $request->all()
356
        );
357
358
        // Download link
359
        $link = link_to(
360
            $project->to('download_export/' . $info['file']),
361
            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...
362
            ['class' => 'btn btn-link']
363
        );
364
365
        return response()->json([
366
            'link'  => $link,
367
            'title' => $info['title'],
368
            'file'  => $info['file'],
369
            'ext'   => $info['ext'],
370
        ]);
371
    }
372
373
    /**
374
     * Download and then delete an export file.
375
     *
376
     * @param Project $project
377
     * @param string  $file
378
     *
379
     * @return \Symfony\Component\HttpFoundation\BinaryFileResponse
380
     */
381
    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...
382
    {
383
        // Filter out any characters that are not in pattern
384
        $file = preg_replace('/[^a-z0-9\_\.]/mi', '', $file);
385
386
        // Download export
387
        return response()->download(storage_path('exports/' . $file), $file)->deleteFileAfterSend(true);
388
    }
389
}
390