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

UserScopes::scopePrivate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
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;
13
14
/**
15
 * QueryTrait is trait class containing the database queries methods for the User model.
16
 *
17
 * @author Mohamed Alsharaf <[email protected]>
18
 *
19
 * @property static $this
20
 */
21
trait UserScopes
22
{
23
    public function scopePrivate($query, $status = false)
24
    {
25
        return $query->where('private', '=', $status);
26
    }
27
28
    public function scopeDeveloperOrHigher($query)
29
    {
30
        //        return $query->where('role_id', '>', 1);
31
32
        return $query->where('users.role_id', '>', 1);
33
    }
34
35
    public function scopeNotDeleted($query)
36
    {
37
        return $query->where('deleted', '=', static::NOT_DELETED_USERS);
38
39
        return $query->where('users.deleted', '=', static::NOT_DELETED_USERS);
0 ignored issues
show
Unused Code introduced by
return $query->where('us...ic::NOT_DELETED_USERS); 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...
40
    }
41
42
    public function scopeDeleted($query)
43
    {
44
        return $query->where('deleted', '=', static::DELETED_USERS);
45
46
        return $query->where('users.deleted', '=', static::NOT_DELETED_USERS);
0 ignored issues
show
Unused Code introduced by
return $query->where('us...ic::NOT_DELETED_USERS); 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...
47
    }
48
49
    public function scopeNotMemberOfProject($query, Project $project)
50
    {
51
        if ($project->id > 0) {
52
            return $query->whereNotIn('id', $project->users(['user_id'])->dropdown('user_id'));
0 ignored issues
show
Unused Code introduced by
The call to Project::users() has too many arguments starting with array('user_id').

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
53
        }
54
55
        return $query;
56
    }
57
}
58