Issues (3884)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

app/Http/ViewComposers/AgentLayout.php (9 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace App\Http\ViewComposers;
4
5
use App\Model\helpdesk\Agent\Department;
6
use App\Model\helpdesk\Settings\Company;
7
use App\Model\helpdesk\Ticket\Tickets;
8
use App\User;
9
use Auth;
10
use Illuminate\View\View;
11
12
class AgentLayout
13
{
14
    /**
15
     * The user repository implementation.
16
     *
17
     * @var UserRepository
18
     */
19
    protected $company;
20
    protected $users;
21
    protected $tickets;
22
    protected $department;
23
24
    /**
25
     * Create a new profile composer.
26
     *
27
     * @param
28
     *
29
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
30
     */
31
    public function __construct(Company $company, User $users, Tickets $tickets, Department $department)
32
    {
33
        $this->company = $company;
0 ignored issues
show
Documentation Bug introduced by
It seems like $company of type object<App\Model\helpdesk\Settings\Company> is incompatible with the declared type object<App\Http\ViewComposers\UserRepository> of property $company.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
34
        $this->auth = Auth::user();
0 ignored issues
show
The property auth does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
35
        $this->users = $users;
36
        $this->tickets = $tickets;
37
        $this->department = $department;
38
    }
39
40
    /**
41
     * Bind data to the view.
42
     *
43
     * @param View $view
44
     *
45
     * @return void
46
     */
47
    public function compose(View $view)
48
    {
49
        $notifications = \App\Http\Controllers\Common\NotificationController::getNotifications();
50
        $view->with([
51
            'company'         => $this->company,
52
            'notifications'   => $notifications,
53
            'myticket'        => $this->myTicket(),
54
            'unassigned'      => $this->unassigned(),
55
            'followup_ticket' => $this->followupTicket(),
56
            'deleted'         => $this->deleted(),
57
            'tickets'         => $this->inbox(),
58
            'department'      => $this->departments(),
59
            'overdues'        => $this->overdues(),
60
            'due_today'       => $this->getDueToday(),
61
        ]);
62
    }
63
64
    public function users()
65
    {
66
        return $this->users->select('id', 'profile_pic');
0 ignored issues
show
Documentation Bug introduced by
The method select does not exist on object<App\User>? 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...
67
    }
68
69
    public function tickets()
70
    {
71
        return $this->tickets->select('id', 'ticket_number');
0 ignored issues
show
Documentation Bug introduced by
The method select does not exist on object<App\Model\helpdesk\Ticket\Tickets>? 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...
72
    }
73
74
    public function departments()
75
    {
76
        $array = [];
0 ignored issues
show
$array is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
77
        $tickets = $this->tickets;
78
        if (\Auth::user()->role == 'agent') {
79
            $tickets = $tickets->where('tickets.dept_id', '=', \Auth::user()->primary_dpt);
0 ignored issues
show
Documentation Bug introduced by
The method where does not exist on object<App\Model\helpdesk\Ticket\Tickets>? 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...
80
        }
81
        $tickets = $tickets
82
                ->leftJoin('department as dep', 'tickets.dept_id', '=', 'dep.id')
83
                ->leftJoin('ticket_status', 'tickets.status', '=', 'ticket_status.id')
84
                ->select('dep.name as name', 'ticket_status.name as status', \DB::raw('COUNT(ticket_status.name) as count'))
85
                ->groupBy('dep.name', 'ticket_status.name')
86
                ->get();
87
        $grouped = $tickets->groupBy('name');
88
        $status = [];
89
        foreach ($grouped as $key => $group) {
90
            $status[$key] = $group->keyBy('status');
91
        }
92
93
        return collect($status);
94
    }
95
96
    public function myTicket()
97
    {
98
        $ticket = $this->tickets();
99
        if ($this->auth->role == 'admin') {
100
            return $ticket->where('assigned_to', $this->auth->id)
101
                    ->where('status', '1');
102
        } elseif ($this->auth->role == 'agent') {
103
            return $ticket->where('assigned_to', $this->auth->id)
104
                    ->where('status', '1');
105
        }
106
    }
107
108
    public function unassigned()
109
    {
110
        $ticket = $this->tickets();
111
        if ($this->auth->role == 'admin') {
112
            return $ticket->where('assigned_to', '=', null)
113
                    ->where('status', '=', '1')
114
                    ->select('id');
115
        } elseif ($this->auth->role == 'agent') {
116
            return $ticket->where('assigned_to', '=', null)
117
                    ->where('status', '=', '1')
118
                    ->where('dept_id', '=', $this->auth->primary_dpt)
119
                    ->select('id');
120
        }
121
    }
122
123
    public function followupTicket()
124
    {
125
        $ticket = $this->tickets();
126
        if ($this->auth->role == 'admin') {
127
            return $ticket->where('status', '1')->where('follow_up', '1')->select('id');
128
        } elseif ($this->auth->role == 'agent') {
129
            return $ticket->where('status', '1')->where('follow_up', '1')->select('id');
130
        }
131
    }
132
133
    public function deleted()
134
    {
135
        $ticket = $this->tickets();
136
        if ($this->auth->role == 'admin') {
137
            return $ticket->where('status', '5')->select('id');
138
        } elseif ($this->auth->role == 'agent') {
139
            return $ticket->where('status', '5')->where('dept_id', '=', $this->auth->primary_dpt)
140
                    ->select('id');
141
        }
142
    }
143
144
    public function inbox()
145
    {
146
        $table = $this->tickets();
147
        if (Auth::user()->role == 'agent') {
148
            $id = Auth::user()->primary_dpt;
149
            $table = $table->where('tickets.dept_id', '=', $id)->orWhere('assigned_to', '=', Auth::user()->id);
150
        }
151
152
        return $table->Join('ticket_status', function ($join) {
153
            $join->on('ticket_status.id', '=', 'tickets.status')
154
                        ->whereIn('ticket_status.id', [1, 7]);
155
        });
156
    }
157
158
    public function overdues()
159
    {
160
        $ticket = $this->tickets();
161
        if ($this->auth->role == 'admin') {
162
            return $ticket->where('status', '=', 1)
163
                            ->where('isanswered', '=', 0)
164
                            ->whereNotNull('tickets.duedate')
165
                            ->where('tickets.duedate', '!=', '00-00-00 00:00:00')
166
                            ->where('tickets.duedate', '<', \Carbon\Carbon::now())
167
                            ->select('tickets.id');
168 View Code Duplication
        } elseif ($this->auth->role == 'agent') {
0 ignored issues
show
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...
169
            return $ticket->where('status', '=', 1)
170
                            ->where('isanswered', '=', 0)
171
                            ->whereNotNull('tickets.duedate')
172
                            ->where('dept_id', '=', $this->auth->primary_dpt)
173
                            ->where('tickets.duedate', '!=', '00-00-00 00:00:00')
174
                            ->where('tickets.duedate', '<', \Carbon\Carbon::now())
175
                            ->select('tickets.id');
176
        }
177
    }
178
179
    public function getDueToday()
180
    {
181
        $ticket = $this->tickets();
182
        if ($this->auth->role == 'admin') {
183
            return $ticket->where('status', '=', 1)
184
                            ->where('status', '=', 1)
185
                            ->where('isanswered', '=', 0)
186
                            ->whereNotNull('duedate')
187
                            ->whereRaw('date(duedate) = ?', [date('Y-m-d')]);
188 View Code Duplication
        } elseif ($this->auth->role == 'agent') {
0 ignored issues
show
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...
189
            return $ticket->where('status', '=', 1)
190
                            ->where('status', '=', 1)
191
                            ->where('isanswered', '=', 0)
192
                            ->whereNotNull('duedate')
193
                            ->where('dept_id', '=', $this->auth->primary_dpt)
194
                            ->whereRaw('date(duedate) = ?', [date('Y-m-d')]);
195
        }
196
    }
197
}
198