Code Duplication    Length = 28-28 lines in 2 locations

app/Model/Project/UserScopes.php 1 location

@@ 21-48 (lines=28) @@
18
 *
19
 * @property static $this
20
 */
21
trait UserScopes
22
{
23
    public function _scopeLoadRelatedDetails($query)
24
    {
25
        return $query->with('activity', 'issue', 'user', 'assignTo', 'comment', 'note')
26
            ->orderBy('users_activity.created_at', 'DESC');
27
    }
28
29
    public function _scopeLimitResultForUserRole($query)
30
    {
31
        // For logged users with role User, show issues that are created by them in internal projects
32
        // of issue create by any for other project statuses
33
        $user = $this->getLoggedUser();
34
        if (!is_null($user) && !$user->isUser()) {
35
            $query->join('projects_issues', 'projects_issues.id', '=', 'item_id');
36
            $query->join('projects', 'projects.id', '=', 'parent_id');
37
            $query->where(function (Eloquent\Builder $query) use ($user) {
38
                $query->where(function (Eloquent\Builder $query) use ($user) {
39
                    $query->where('created_by', '=', $user->id);
40
                    $query->where('private', '=', Project::INTERNAL_YES);
41
                });
42
                $query->orWhere('private', '<>', Project::INTERNAL_YES);
43
            });
44
        }
45
46
        return $query;
47
    }
48
}
49

app/Model/User/ActivityScopes.php 1 location

@@ 24-51 (lines=28) @@
21
 *
22
 * @property static $this
23
 */
24
trait ActivityScopes
25
{
26
    public function scopeLoadRelatedDetails(Builder $query)
27
    {
28
        return $query->with('activity', 'issue', 'user', 'assignTo', 'comment', 'note')
29
            ->orderBy('users_activity.created_at', 'DESC');
30
    }
31
32
    public function scopeLimitResultForUserRole(Builder $query)
33
    {
34
        // For logged users with role User, show issues that are created by them in internal projects
35
        // of issue create by any for other project statuses
36
        $user = $this->getLoggedUser();
37
        if (!is_null($user) && !$user->isUser()) {
38
            $query->join('projects_issues', 'projects_issues.id', '=', 'item_id');
39
            $query->join('projects', 'projects.id', '=', 'parent_id');
40
            $query->where(function (Builder $query) use ($user) {
41
                $query->where(function (Builder $query) use ($user) {
42
                    $query->where('created_by', '=', $user->id);
43
                    $query->where('private', '=', Project::INTERNAL_YES);
44
                });
45
                $query->orWhere('private', '<>', Project::INTERNAL_YES);
46
            });
47
        }
48
49
        return $query;
50
    }
51
}
52