Completed
Push — master ( 50f309...1f3d4e )
by Mohamed
06:23
created

IssueController::postChangeProject()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4285
cc 1
eloc 3
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\Project;
13
14
use Illuminate\Http\Request;
15
use Illuminate\Http\Response;
16
use Tinyissue\Form\Comment as CommentForm;
17
use Tinyissue\Form\Issue as IssueForm;
18
use Tinyissue\Http\Controllers\Controller;
19
use Tinyissue\Http\Requests\FormRequest;
20
use Tinyissue\Model\Project;
21
use Tinyissue\Model\Project\Issue;
22
use Tinyissue\Model\Project\Issue\Attachment;
23
use Tinyissue\Model\Project\Issue\Comment;
24
use Tinyissue\Model\Tag;
25
use Tinyissue\Model\User\Activity as UserActivity;
26
27
/**
28
 * IssueController is the controller class for managing request related to projects issues.
29
 *
30
 * @author Mohamed Alsharaf <[email protected]>
31
 */
32
class IssueController extends Controller
33
{
34
    /**
35
     * Project issue index page (List project issues).
36
     *
37
     * @param Project     $project
38
     * @param Issue       $issue
39
     * @param CommentForm $form
40
     *
41
     * @return \Illuminate\View\View
42
     */
43 18
    public function getIndex(Project $project, Issue $issue, CommentForm $form)
44
    {
45
        $issue->attachments->each(function (Attachment $attachment) use ($issue) {
0 ignored issues
show
Documentation introduced by
The property attachments does not exist on object<Tinyissue\Model\Project\Issue>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
46 1
            $attachment->setRelation('issue', $issue);
47 18
        });
48 18
        $activities = $issue->activities()->with('activity', 'user', 'comment', 'assignTo',
49 18
            'comment.attachments')->get();
50 18
        $activities->each(function (UserActivity $activity) use ($issue) {
51 18
            $activity->setRelation('issue', $issue);
52 18
        });
53
54
        // Projects should be limited to issue-modify
55 18
        $projects = null;
56 18
        if (!$this->auth->guest() && $this->auth->user()->permission('issue-modify')) {
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 permission() 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...
57 15
            $projects = $this->auth->user()->projects()->get();
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 projects() 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...
58
        }
59
60 18
        return view('project.issue.index', [
0 ignored issues
show
Bug Compatibility introduced by
The expression view('project.issue.inde...ojects' => $projects)); of type Illuminate\View\View|Ill...\Contracts\View\Factory adds the type Illuminate\Contracts\View\Factory to the return on line 60 which is incompatible with the return type documented by Tinyissue\Http\Controlle...sueController::getIndex of type Illuminate\View\View.
Loading history...
61 18
            'issue'       => $issue,
62 18
            'project'     => $project,
63 18
            'commentForm' => $form,
64 18
            'activities'  => $activities,
65 18
            'sidebar'     => 'project',
66 18
            'projects'    => $projects,
67
        ]);
68
    }
69
70
    /**
71
     * Ajax: Assign new user to an issue.
72
     *
73
     * @param Issue   $issue
74
     * @param Request $request
75
     *
76
     * @return \Symfony\Component\HttpFoundation\Response
77
     */
78 1 View Code Duplication
    public function postAssign(Issue $issue, 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...
79
    {
80 1
        $response = ['status' => false];
81 1
        if ($issue->reassign((int) $request->input('user_id'), $this->auth->user()->id)) {
0 ignored issues
show
Bug introduced by
Accessing id on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?

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

Available Fixes

  1. Adding an additional type check:

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

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
82 1
            $response['status'] = true;
83
        }
84
85 1
        return response()->json($response);
86
    }
87
88
    /**
89
     * Ajax: save comment.
90
     *
91
     * @param Comment $comment
92
     * @param Request $request
93
     *
94
     * @return \Symfony\Component\HttpFoundation\Response
95
     */
96 1
    public function postEditComment(Comment $comment, Request $request)
97
    {
98 1
        $body = '';
99 1
        if ($request->has('body')) {
100 1
            $comment->fill(['comment' => $request->input('body')])->save();
101 1
            $body = \Html::format($comment->comment);
102
        }
103
104 1
        return response()->json(['text' => $body]);
105
    }
106
107
    /**
108
     * To add new comment to an issue.
109
     *
110
     * @param Project             $project
111
     * @param Issue               $issue
112
     * @param Comment             $comment
113
     * @param FormRequest\Comment $request
114
     *
115
     * @return \Illuminate\Http\RedirectResponse
116
     */
117 4
    public function getAddComment(Project $project, Issue $issue, Comment $comment, FormRequest\Comment $request)
118
    {
119 4
        $comment->setRelation('project', $project);
120 4
        $comment->setRelation('issue', $issue);
121 4
        $comment->setRelation('user', $this->auth->user());
122 4
        $comment->createComment($request->all());
123
124 4
        return redirect($issue->to() . '#comment' . $comment->id)
125 4
            ->with('notice', trans('tinyissue.your_comment_added'));
126
    }
127
128
    /**
129
     * Ajax: to delete a comment.
130
     *
131
     * @param Comment $comment
132
     *
133
     * @return \Symfony\Component\HttpFoundation\Response
134
     */
135 1
    public function getDeleteComment(Comment $comment)
136
    {
137 1
        $comment->deleteComment();
138
139 1
        return response()->json(['status' => true]);
140
    }
141
142
    /**
143
     * New issue form.
144
     *
145
     * @param Project   $project
146
     * @param IssueForm $form
147
     *
148
     * @return \Illuminate\View\View
149
     */
150 5
    public function getNew(Project $project, IssueForm $form)
151
    {
152 5
        return view('project.issue.new', [
0 ignored issues
show
Bug Compatibility introduced by
The expression view('project.issue.new'...idebar' => 'project')); of type Illuminate\View\View|Ill...\Contracts\View\Factory adds the type Illuminate\Contracts\View\Factory to the return on line 152 which is incompatible with the return type documented by Tinyissue\Http\Controlle...IssueController::getNew of type Illuminate\View\View.
Loading history...
153 5
            'project' => $project,
154 5
            'form'    => $form,
155 5
            'sidebar' => 'project',
156
        ]);
157
    }
158
159
    /**
160
     * To create a new issue.
161
     *
162
     * @param Project           $project
163
     * @param Issue             $issue
164
     * @param FormRequest\Issue $request
165
     *
166
     * @return \Illuminate\Http\RedirectResponse
167
     */
168 2 View Code Duplication
    public function postNew(Project $project, Issue $issue, FormRequest\Issue $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...
169
    {
170 2
        $issue->setRelation('project', $project);
171 2
        $issue->setRelation('user', $this->auth->user());
172 2
        $issue->createIssue($request->all());
173
174 2
        return redirect($issue->to())
175 2
            ->with('notice', trans('tinyissue.issue_has_been_created'));
176
    }
177
178
    /**
179
     * Edit an existing issue form.
180
     *
181
     * @param Project   $project
182
     * @param Issue     $issue
183
     * @param IssueForm $form
184
     *
185
     * @return \Illuminate\View\View
186
     */
187 2
    public function getEdit(Project $project, Issue $issue, IssueForm $form)
188
    {
189
        // Cannot edit closed issue
190 2
        if ($issue->status == Issue::STATUS_CLOSED) {
191 1
            return redirect($issue->to())
0 ignored issues
show
Bug Best Practice introduced by
The return type of return redirect($issue->...t_edit_closed_issue')); (Illuminate\Http\RedirectResponse) is incompatible with the return type documented by Tinyissue\Http\Controlle...ssueController::getEdit of type Illuminate\View\View.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
192 1
                ->with('notice', trans('tinyissue.cant_edit_closed_issue'));
193
        }
194
195 2
        return view('project.issue.edit', [
0 ignored issues
show
Bug Compatibility introduced by
The expression view('project.issue.edit...idebar' => 'project')); of type Illuminate\View\View|Ill...\Contracts\View\Factory adds the type Illuminate\Contracts\View\Factory to the return on line 195 which is incompatible with the return type documented by Tinyissue\Http\Controlle...ssueController::getEdit of type Illuminate\View\View.
Loading history...
196 2
            'issue'   => $issue,
197 2
            'project' => $project,
198 2
            'form'    => $form,
199 2
            'sidebar' => 'project',
200
        ]);
201
    }
202
203
    /**
204
     * To update an existing issue details.
205
     *
206
     * @param Project           $project
207
     * @param Issue             $issue
208
     * @param FormRequest\Issue $request
209
     *
210
     * @return \Illuminate\Http\RedirectResponse
211
     */
212 1 View Code Duplication
    public function postEdit(Project $project, Issue $issue, FormRequest\Issue $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...
213
    {
214 1
        $issue->setRelation('project', $project);
215 1
        $issue->setRelation('updatedBy', $this->auth->user());
216 1
        $issue->updateIssue($request->all());
217
218 1
        return redirect($issue->to())
219 1
            ->with('notice', trans('tinyissue.issue_has_been_updated'));
220
    }
221
222
    /**
223
     * To close or reopen an issue.
224
     *
225
     * @param Project $project
226
     * @param Issue   $issue
227
     * @param int     $status
228
     *
229
     * @return \Illuminate\Http\RedirectResponse
230
     */
231 2
    public function getClose(Project $project, Issue $issue, $status = 0)
232
    {
233 2
        if ($status == 0) {
234 2
            $message = trans('tinyissue.issue_has_been_closed');
235
        } else {
236 1
            $message = trans('tinyissue.issue_has_been_reopened');
237
        }
238
239 2
        $issue->setRelation('project', $project);
240 2
        $issue->changeStatus($status, $this->auth->user()->id);
0 ignored issues
show
Bug introduced by
Accessing id on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?

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

Available Fixes

  1. Adding an additional type check:

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

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
241
242 2
        return redirect($issue->to())
243 2
            ->with('notice', $message);
244
    }
245
246
    /**
247
     * To upload an attachment file.
248
     *
249
     * @param Project    $project
250
     * @param Attachment $attachment
251
     * @param Request    $request
252
     *
253
     * @return \Symfony\Component\HttpFoundation\Response
254
     */
255 3
    public function postUploadAttachment(Project $project, Attachment $attachment, Request $request)
256
    {
257
        try {
258 3
            if (!$this->auth->user()->permission('project-all')) {
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 permission() 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...
259
                abort(404);
260
            }
261
262 3
            $attachment->upload($request->all(), $project, $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...
263
264
            $response = [
265
                'upload' => [
266
                    [
267 3
                        'name'   => $attachment->filename,
268 3
                        'size'   => $attachment->filesize,
269 3
                        'fileId' => $attachment->id,
270
                    ],
271
                ],
272
            ];
273
        } catch (\Exception $exception) {
274
            $file = $request->file('upload');
275
276
            $response = [
277
                'status' => false,
278
                'name'   => $file->getClientOriginalName(),
279
                'error'  => $exception->getMessage(),
280
                'trace'  => $exception->getTraceAsString(),
281
            ];
282
        }
283
284 3
        return response()->json($response);
285
    }
286
287
    /**
288
     * Ajax: to remove an attachment file.
289
     *
290
     * @param Project    $project
291
     * @param Attachment $attachment
292
     * @param Request    $request
293
     *
294
     * @return \Symfony\Component\HttpFoundation\Response
295
     */
296 1
    public function postRemoveAttachment(Project $project, Attachment $attachment, Request $request)
297
    {
298 1
        $attachment->remove($request->all(), $project, $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...
299
300 1
        return response()->json(['status' => true]);
301
    }
302
303
    /**
304
     * Display an attachment file such as image.
305
     *
306
     * @param Project    $project
307
     * @param Issue      $issue
308
     * @param Attachment $attachment
309
     * @param Request    $request
310
     *
311
     * @return Response
312
     */
313 2
    public function getDisplayAttachment(Project $project, Issue $issue, Attachment $attachment, Request $request)
314
    {
315 2
        $issue->setRelation('project', $project);
316 2
        $attachment->setRelation('issue', $issue);
317
318 2
        $path    = config('tinyissue.uploads_dir') . '/' . $issue->project_id . '/' . $attachment->upload_token . '/' . $attachment->filename;
319 2
        $storage = \Storage::disk('local');
320 2
        $length  = $storage->size($path);
321 2
        $time    = $storage->lastModified($path);
322 2
        $type    = $storage->getDriver()->getMimetype($path);
323
324 2
        $response = new Response();
325 2
        $response->setEtag(md5($time . $path));
326 2
        $response->setExpires(new \DateTime('@' . ($time + 60)));
327 2
        $response->setLastModified(new \DateTime('@' . $time));
328 2
        $response->setPublic();
329 2
        $response->setStatusCode(200);
330
331 2
        $response->header('Content-Type', $type);
332 2
        $response->header('Content-Length', $length);
333 2
        $response->header('Content-Disposition', 'inline; filename="' . $attachment->filename . '"');
334 2
        $response->header('Cache-Control', 'must-revalidate');
335
336 2
        if ($response->isNotModified($request)) {
337
            // Return empty response if not modified
338
            return $response;
339
        }
340
341
        // Return file if first request / modified
342 2
        $response->setContent($storage->get($path));
343
344 2
        return $response;
345
    }
346
347
    /**
348
     * Download an attachment file.
349
     *
350
     * @param Project    $project
351
     * @param Issue      $issue
352
     * @param Attachment $attachment
353
     *
354
     * @return \Symfony\Component\HttpFoundation\BinaryFileResponse
355
     */
356 1
    public function getDownloadAttachment(Project $project, Issue $issue, Attachment $attachment)
357
    {
358 1
        $issue->setRelation('project', $project);
359 1
        $attachment->setRelation('issue', $issue);
360
361 1
        $path = config('filesystems.disks.local.root') . '/' . config('tinyissue.uploads_dir') . '/' . $issue->project_id . '/' . $attachment->upload_token . '/' . $attachment->filename;
362
363 1
        return response()->download($path, $attachment->filename);
364
    }
365
366
    /**
367
     * Ajax: move an issue to another project.
368
     *
369
     * @param Issue   $issue
370
     * @param Request $request
371
     *
372
     * @return \Symfony\Component\HttpFoundation\Response
373
     */
374 1
    public function postChangeProject(Issue $issue, Request $request)
375
    {
376 1
        $issue->changeProject($request->input('project_id'));
0 ignored issues
show
Documentation introduced by
$request->input('project_id') is of type string|array, but the function expects a integer.

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...
377
378 1
        return response()->json(['status' => true, 'url' => $issue->to()]);
379
    }
380
381
    /**
382
     * Ajax: change status of an issue.
383
     *
384
     * @param Issue   $issue
385
     * @param Request $request
386
     *
387
     * @return \Symfony\Component\HttpFoundation\Response
388
     */
389
    public function postChangeStatusTag(Issue $issue, Request $request)
390
    {
391
        $newTag = Tag::find((int) $request->input('newtag'));
392
        $oldTag = Tag::find((int) $request->input('oldtag'));
393
        $issue->setCurrentTag($newTag, $oldTag, $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...
394
395
        return response()->json(['status' => true, 'issue' => $issue->id]);
396
    }
397
}
398