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/Itil/Controllers/ChangesController.php (23 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\Itil\Controllers;
4
5
use App\Itil\Controllers\BaseServiceDeskController;
6
use App\Itil\Models\Changes\SdChanges;
7
use App\Itil\Models\Changes\SdChangestatus;
8
use App\Itil\Models\Changes\SdChangepriorities;
9
use App\Itil\Models\Changes\SdChangetypes;
10
use App\Itil\Models\Changes\SdImpacttypes;
11
use App\Itil\Models\Releases\SdLocations;
12
use App\Itil\Requests\CreateChangesRequest;
13
use App\User;
14
use App\Itil\Models\Common\Cab;
15
use Exception;
16
use App\Itil\Requests\CreateReleaseRequest;
17
use Illuminate\Http\Request;
18
19
class ChangesController extends BaseServiceDeskController {
20
21
    public function __construct() {
22
        $this->middleware('auth');
23
    }
24
25
    public function changesindex() {
26
        try {
27
            return view('itil::changes.index');
28
        } catch (Exception $ex) {
29
            return redirect()->back()->with('fails', $ex->getMessage());
30
        }
31
    }
32
33 View Code Duplication
    public function getChanges() {
0 ignored issues
show
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...
34
        try {
35
            $change = new SdChanges();
36
            $changes = $change->select('id', 'description', 'subject', 'status_id', 'priority_id', 'change_type_id', 'impact_id', 'location_id', 'approval_id')->get();
0 ignored issues
show
Documentation Bug introduced by
The method select does not exist on object<App\Itil\Models\Changes\SdChanges>? 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...
37
            return \Datatable::Collection($changes)
38
                            ->showColumns('subject', 'reason')
39
                            ->addColumn('action', function($model) {
40
                                $url = url('service-desk/changes/' . $model->id . '/delete');
41
                                $delete = \App\Itil\Controllers\UtilityController::deletePopUp($model->id, $url, "Delete $model->subject");
42
                                //dd($delete);
43
                                return "<a href=" . url('service-desk/changes/' . $model->id . '/edit') . " class='btn btn-info btn-sm'>Edit</a> "
44
                                        . $delete
45
                                        . " <a href=" . url('service-desk/changes/' . $model->id . '/show') . " class='btn btn-primary btn-sm'>View</a>";
46
                            })
47
                            ->searchColumns('description')
48
                            ->orderColumns('description', 'subject', 'reason', 'status_id', 'priority_id', 'change_type_id', 'impact_id', 'location_id', 'approval_id')
49
                            ->make();
50
        } catch (Exception $ex) {
51
            return redirect()->back()->with('fails', $ex->getMessage());
52
        }
53
    }
54
55
    public function changescreate() {
56
        try {
57
            $statuses = SdChangestatus::lists('name', 'id')->toArray();
58
            $sd_changes_priorities = SdChangepriorities::lists('name', 'id')->toArray();
59
            $sd_changes_types = SdChangetypes::lists('name', 'id')->toArray();
60
            $sd_impact_types = SdImpacttypes::lists('name', 'id')->toArray();
61
            $sd_locations = SdLocations::lists('title', 'id')->toArray();
62
            $users = Cab::lists('name', 'id')->toArray();
63
//            $assets = SdAssets::lists('name', 'id')->toArray();
0 ignored issues
show
Unused Code Comprehensibility introduced by
58% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
64
            $requester = User::where('role', 'agent')->orWhere('role', 'admin')->lists('email', 'id')->toArray();
65
66
            return view('itil::changes.create', compact('statuses', 'sd_changes_priorities', 'sd_changes_types', 'sd_impact_types', 'sd_locations', 'users', 'requester'));
67
        } catch (Exception $ex) {
68
            return redirect()->back()->with('fails', $ex->getMessage());
69
        }
70
    }
71
72
    public function changeshandleCreate(CreateChangesRequest $request, $attach = false) {
73
        //  dd($request->all());
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
74
        try {
75
            $sd_changes = new SdChanges;
76
            $sd_changes->fill($request->input())->save();
0 ignored issues
show
It seems like $request->input() targeting Illuminate\Http\Request::input() can also be of type string; however, Illuminate\Database\Eloquent\Model::fill() does only seem to accept array, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
77
            \App\Itil\Controllers\UtilityController::attachment($sd_changes->id, 'sd_changes', $request->file('attachments'));
0 ignored issues
show
The property id does not exist on object<App\Itil\Models\Changes\SdChanges>. 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...
78
            if (isAsset() == true) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
79
                \App\Itil\Controllers\UtilityController::storeAssetRelation('sd_changes', $sd_changes->id, $request->input('asset'));
0 ignored issues
show
The property id does not exist on object<App\Itil\Models\Changes\SdChanges>. 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...
It seems like $request->input('asset') targeting Illuminate\Http\Request::input() can also be of type string; however, App\Itil\Controllers\Uti...r::storeAssetRelation() does only seem to accept array, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
80
            }
81
            if ($attach == false) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
82
                return \Redirect::route('service-desk.changes.index')->with('message', 'Changes successfull !!!');
83
            }
84
            return $sd_changes;
85
        } catch (Exception $ex) {
86
            return redirect()->back()->with('fails', $ex->getMessage());
87
        }
88
    }
89
90
    public function changesedit($id) {
91
        try {
92
93
            $change = SdChanges::findOrFail($id);
94
            $statuses = SdChangestatus::lists('name', 'id')->toArray();
95
            $sd_changes_status = "";
96
            $sd_changes_priorities = SdChangepriorities::lists('name', 'id')->toArray();
97
            $sd_changes_types = SdChangetypes::lists('name', 'id')->toArray();
98
            $sd_impact_types = SdImpacttypes::lists('name', 'id')->toArray();
99
            $sd_locations = SdLocations::lists('title', 'id')->toArray();
100
            $users = Cab::lists('name', 'id')->toArray();
101
//            $assets = SdAssets::lists('name', 'id')->toArray();
0 ignored issues
show
Unused Code Comprehensibility introduced by
58% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
102
            $requester = User::where('role', 'agent')->orWhere('role', 'admin')->lists('email', 'id')->toArray();
103
            return view('itil::changes.edit', compact('sd_changes_status', 'change', 'statuses', 'sd_changes_priorities', 'sd_changes_types', 'sd_impact_types', 'sd_locations', 'users', 'requester'));
104
        } catch (Exception $ex) {
105
            return redirect()->back()->with('fails', $ex->getMessage());
106
        }
107
    }
108
109
    public function changeshandleEdit($id, CreateChangesRequest $request) {
110
        try {
111
112
            $sd_changes = SdChanges::findOrFail($id);
113
            $sd_changes->fill($request->input())->save();
114
            \App\Itil\Controllers\UtilityController::attachment($sd_changes->id, 'sd_changes', $request->file('attachments'));
115
            if (isAsset() == true) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
116
                \App\Itil\Controllers\UtilityController::storeAssetRelation('sd_changes', $sd_changes->id, $request->input('asset'));
0 ignored issues
show
It seems like $request->input('asset') targeting Illuminate\Http\Request::input() can also be of type string; however, App\Itil\Controllers\Uti...r::storeAssetRelation() does only seem to accept array, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
117
            }
118
            return \Redirect::route('service-desk.changes.index')->with('message', 'Changes successfully Edit !!!');
119
        } catch (Exception $ex) {
120
            dd($ex);
121
            return redirect()->back()->with('fails', $ex->getMessage());
122
        }
123
    }
124
125
    public function changesHandledelete($id) {
126
        try {
127
            $sd_changes = SdChanges::findOrFail($id);
128
            $sd_changes->delete();
129
            return \Redirect::route('service-desk.changes.index')->with('message', 'Changes successfully Delete !!!');
130
        } catch (Exception $ex) {
131
            return redirect()->back()->with('fails', $ex->getMessage());
132
        }
133
    }
134
135 View Code Duplication
    public function show($id) {
0 ignored issues
show
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...
136
        try {
137
            $changes = new SdChanges();
138
            $change = $changes->find($id);
0 ignored issues
show
Documentation Bug introduced by
The method find does not exist on object<App\Itil\Models\Changes\SdChanges>? 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...
139
            if ($change) {
140
                return view('itil::changes.show', compact('change'));
141
            } else {
142
                throw new \Exception('Sorry we can not find your request');
143
            }
144
        } catch (Exception $ex) {
145
            return redirect()->back()->with('fails', $ex->getMessage());
146
        }
147
    }
148
149
    public function close($id) {
150
        try {
151
            $changes = new SdChanges();
152
            $change = $changes->find($id);
0 ignored issues
show
Documentation Bug introduced by
The method find does not exist on object<App\Itil\Models\Changes\SdChanges>? 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...
153
            if ($change) {
154
                $change->status_id = 6;
155
                $change->save();
156
                return redirect()->back()->with('success', 'Updated');
157
            } else {
158
                throw new \Exception('Sorry we can not find your request');
159
            }
160
        } catch (\Exception $ex) {
161
            return redirect()->back()->with('fails', $ex->getMessage());
162
        }
163
    }
164
165 View Code Duplication
    public function getReleases() {
0 ignored issues
show
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...
166
        $release = new \App\Itil\Models\Releases\SdReleases();
167
        $releases = $release->select('id', 'subject')->get();
0 ignored issues
show
Documentation Bug introduced by
The method select does not exist on object<App\Itil\Models\Releases\SdReleases>? 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...
168
        return \Datatable::Collection($releases)
169
                        ->addColumn('id', function($model) {
170
                            return "<input type='radio' name='release' value='" . $model->id . "'>";
171
                        })
172
                        ->addColumn('subject', function($model) {
173
                            return str_limit($model->subject, 20);
174
                        })
175
                        ->orderColumns('subject')
176
                        ->searchColumns('subject')
177
                        ->make();
178
    }
179
180 View Code Duplication
    public function attachNewRelease($id, CreateReleaseRequest $request) {
0 ignored issues
show
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...
181
        try {
182
            $release_controller = new RelesesController();
183
            $release = $release_controller->releaseshandleCreate($request, true);
184
            $this->releaseAttach($id, $release->id);
185
            if ($release) {
186
                return redirect()->back()->with('success', 'Updated');
187
            }
188
        } catch (\Exception $ex) {
189
            dd($ex);
190
            return redirect()->back()->with('fails', $ex->getMessage());
191
        }
192
    }
193
194
    public function attachExistingRelease($id, Request $request) {
195
        try {
196
            $releaseid = $request->input('release');
197
            $store = $this->releaseAttach($id, $releaseid);
198
            if ($store) {
199
                return redirect()->back()->with('success', 'Updated');
200
            }
201
        } catch (\Exception $ex) {
202
            return redirect()->back()->with('fails', $ex->getMessage());
203
        }
204
    }
205
206 View Code Duplication
    public function releaseAttach($changeid, $releaseid) {
0 ignored issues
show
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...
207
        $relation = new \App\Itil\Models\Changes\ChangeReleaseRelation();
208
        $relations = $relation->where('change_id', $changeid)->first();
0 ignored issues
show
Documentation Bug introduced by
The method where does not exist on object<App\Itil\Models\C...\ChangeReleaseRelation>? 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...
209
        if ($relations) {
210
            $relations->delete();
211
        }
212
213
        return $relation->create([
214
                    'release_id' => $releaseid,
215
                    'change_id' => $changeid,
216
        ]);
217
    }
218
219 View Code Duplication
    public function detachRelease($changeid) {
0 ignored issues
show
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...
220
        try {
221
            $relations = new \App\Itil\Models\Changes\ChangeReleaseRelation();
222
            $relation = $relations->where('change_id', $changeid)->first();
0 ignored issues
show
Documentation Bug introduced by
The method where does not exist on object<App\Itil\Models\C...\ChangeReleaseRelation>? 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...
223
            if ($relation) {
224
                $relation->delete();
225
            }
226
            return redirect()->back()->with('success', 'Updated');
227
        } catch (\Exception $ex) {
228
            return redirect()->back()->with('fails', $ex->getMessage());
229
        }
230
    }
231
232
}
233