Completed
Push — develop-3.0 ( 4fe777...24fc5d )
by Mohamed
09:15
created

AttachmentScopes::scopeByUser()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 3
nc 2
nop 2
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\Model\Project\Issue;
13
14
use Tinyissue\Contracts\Model\UserInterface;
15
16
/**
17
 * @property static $this
18
 */
19
trait AttachmentScopes
20
{
21
    public function scopeByUser($query, $userOrId)
22
    {
23
        $userId = $userOrId instanceof UserInterface ? $userOrId->id : $userOrId;
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...
24
25
        return $query->where('uploaded_by', '=', $userId);
26
    }
27
28
    public function scopeForToken($query, $token)
29
    {
30
        return $query->where('upload_token', '=', $token);
31
    }
32
33
    public function scopeFilename($query, $name)
34
    {
35
        return $query->where('filename', '=', $name);
36
    }
37
}
38