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/LocationController.php (33 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\Common\Location;
7
use App\Itil\Models\Changes\SdLocationcategories;
8
use App\Model\helpdesk\Agent\Department;
9
use App\Itil\Requests\CreateLocationRequest;
10
use Exception;
11
use Illuminate\Http\Request;
12
class LocationController extends BaseServiceDeskController {
13
14
    /**
15
     * 
16
     * @return type
17
     */
18
    public function index() {
19
        try {
20
            return view('itil::location.index');
21
        } catch (Exception $ex) {
22
            return redirect()->back()->with('fails', $ex->getMessage());
23
        }
24
    }
25
26
    /**
27
     * 
28
     * @return type
29
     */
30 View Code Duplication
    public function getLocation() {
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...
31
        try {
32
            $locationcategorys = new Location();
33
            $locationcategory = $locationcategorys->select('id', 'location_category_id', 'title', 'email', 'phone', 'address', 'all_department_access', 'departments', 'status', 'created_at', 'updated_at')->get();
0 ignored issues
show
Documentation Bug introduced by
The method select does not exist on object<App\Itil\Models\Common\Location>? 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...
34
            return \Datatable::Collection($locationcategory)
35
                            ->addColumn('location_category_id', function($model) {
36
                                $name = "--";
37
                                $location_categories = new SdLocationcategories;
38
                                $location_category = $location_categories->where('id', $model->location_category_id)->first();
0 ignored issues
show
Documentation Bug introduced by
The method where does not exist on object<App\Itil\Models\C...s\SdLocationcategories>? 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...
39
                                if($location_category){
40
                                    $name = $location_category->name;
41
                                }
42
                                return $name;
43
                            })
44
                            ->showColumns('title', 'email', 'phone', 'address')
45
                            ->addColumn('action', function($model) {
46
                                return "<a href=" . url('service-desk/location-types/' . $model->id . '/edit') . " class='btn btn-info btn-sm'>Edit</a> <a href=" . url('service-desk/location-types/' . $model->id . '/show') . " class='btn btn-primary btn-sm'>View</a>";
47
                            })
48
                            ->searchColumns('title', 'email', 'phone', 'address')
49
                            ->orderColumns('location_category_id', 'title', 'email', 'phone', 'address')
50
                            ->make();
51
        } catch (Exception $ex) {
52
            return redirect()->back()->with('fails', $ex->getMessage());
0 ignored issues
show
Bug Best Practice introduced by
The return type of return redirect()->back(...s', $ex->getMessage()); (Illuminate\Http\RedirectResponse) is incompatible with the return type documented by App\Itil\Controllers\Loc...Controller::getLocation of type App\Itil\Controllers\type.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
53
        }
54
    }
55
56
    /**
57
     * 
58
     * @return type
59
     */
60 View Code Duplication
    public function create() {
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...
61
        try {
62
            $departments = Department::all(array('id', 'name'));
63
            $location_category = SdLocationcategories::all(array('id', 'name'));
64
            $organizations = \App\Model\helpdesk\Agent_panel\Organization::lists('name', 'id')->toArray();
65
            return view('itil::location.create', compact('departments', 'location_category', 'organizations'));
66
        } catch (Exception $ex) {
67
            return redirect()->back()->with('fails', $ex->getMessage());
68
        }
69
    }
70
71
    /**
72
     * 
73
     * @param CreateLocationRequest $request
74
     * @return type
75
     */
76 View Code Duplication
    public function handleCreate(CreateLocationRequest $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...
77
78
        try {
79
            $sd_location = new Location();
80
            $sd_location->title = $request->title;
0 ignored issues
show
The property title does not exist on object<App\Itil\Models\Common\Location>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write 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.");
        }
    }

}

Since the property has write access only, you can use the @property-write 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...
The property title does not seem to exist in App\Itil\Requests\CreateLocationRequest.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
81
            $sd_location->email = $request->email;
0 ignored issues
show
The property email does not exist on object<App\Itil\Models\Common\Location>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write 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.");
        }
    }

}

Since the property has write access only, you can use the @property-write 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...
The property email does not seem to exist in App\Itil\Requests\CreateLocationRequest.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
82
            $sd_location->phone = $request->phone;
0 ignored issues
show
The property phone does not exist on object<App\Itil\Models\Common\Location>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write 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.");
        }
    }

}

Since the property has write access only, you can use the @property-write 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...
The property phone does not seem to exist in App\Itil\Requests\CreateLocationRequest.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
83
            $sd_location->address = $request->address;
0 ignored issues
show
The property address does not exist on object<App\Itil\Models\Common\Location>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write 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.");
        }
    }

}

Since the property has write access only, you can use the @property-write 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...
The property address does not seem to exist in App\Itil\Requests\CreateLocationRequest.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
84
            $sd_location->location_category_id = $request->location_category;
0 ignored issues
show
The property location_category_id does not exist on object<App\Itil\Models\Common\Location>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write 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.");
        }
    }

}

Since the property has write access only, you can use the @property-write 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...
The property location_category does not seem to exist in App\Itil\Requests\CreateLocationRequest.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
85
            $sd_location->departments = $request->department;
0 ignored issues
show
The property departments does not exist on object<App\Itil\Models\Common\Location>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write 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.");
        }
    }

}

Since the property has write access only, you can use the @property-write 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...
The property department does not seem to exist in App\Itil\Requests\CreateLocationRequest.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
86
            $sd_location->organization = $request->organization;
0 ignored issues
show
The property organization does not exist on object<App\Itil\Models\Common\Location>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write 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.");
        }
    }

}

Since the property has write access only, you can use the @property-write 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...
The property organization does not seem to exist in App\Itil\Requests\CreateLocationRequest.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
87
            $sd_location->save();
88
            return \Redirect::route('service-desk.location.index')->with('message', 'Location successfully created');
89
        } catch (Exception $ex) {
90
            return redirect()->back()->with('fails', $ex->getMessage());
91
        }
92
    }
93
94
    /**
95
     * 
96
     * @param type $id
97
     * @return type
98
     */
99
    public function edit($id) {
100
        try {
101
            // dd($id);
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% 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
            $location_category_name = "";
103
            $departments_name = "";
104
            $sd_location = Location::findOrFail($id);
105
            $departments = Department::whereid($sd_location->departments)->first();
106
            if($departments){
107
                $departments_name = $departments->name;
108
            }
109
            $location_category = SdLocationcategories::whereid($sd_location->location_category_id)->first();
110
            if($location_category){
111
                $location_category_name = $location_category->name;
112
            }
113
            $departments = Department::all(array('id', 'name'));
114
            $location_category = SdLocationcategories::all(array('id', 'name'));
115
            $organizations = \App\Model\helpdesk\Agent_panel\Organization::lists('name', 'id')->toArray();
116
            return view('itil::location.edit', compact('departments', 'location_category', 'location_category_name', 'departments_name', 'sd_location', 'organizations'));
117
        } catch (Exception $ex) {
118
            return redirect()->back()->with('fails', $ex->getMessage());
119
        }
120
    }
121
122
    /**
123
     * 
124
     * @param CreateLocationRequest $request
125
     * @return type
126
     */
127 View Code Duplication
    public function handleEdit(CreateLocationRequest $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...
128
        try {
129
            $id = $request->location_id;
0 ignored issues
show
The property location_id does not seem to exist in App\Itil\Requests\CreateLocationRequest.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
130
            $sd_location = Location::findOrFail($id);
131
            $sd_location->email = $request->email;
0 ignored issues
show
The property email does not seem to exist in App\Itil\Requests\CreateLocationRequest.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
132
            $sd_location->title = $request->title;
0 ignored issues
show
The property title does not seem to exist in App\Itil\Requests\CreateLocationRequest.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
133
            $sd_location->phone = $request->phone;
0 ignored issues
show
The property phone does not seem to exist in App\Itil\Requests\CreateLocationRequest.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
134
            $sd_location->address = $request->address;
0 ignored issues
show
The property address does not seem to exist in App\Itil\Requests\CreateLocationRequest.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
135
            $sd_location->location_category_id = $request->location_category;
0 ignored issues
show
The property location_category does not seem to exist in App\Itil\Requests\CreateLocationRequest.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
136
            $sd_location->departments = $request->department;
0 ignored issues
show
The property department does not seem to exist in App\Itil\Requests\CreateLocationRequest.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
137
            $sd_location->organization = $request->organization;
0 ignored issues
show
The property organization does not seem to exist in App\Itil\Requests\CreateLocationRequest.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
138
            $sd_location->save();
139
            return \Redirect::route('service-desk.location.index')->with('message', 'Location  successfully Updated');
140
        } catch (Exception $ex) {
141
            return redirect()->back()->with('fails', $ex->getMessage());
142
        }
143
    }
144
145
    /**
146
     * 
147
     * @param type $id
148
     * @return type
149
     */
150
    public function handledelete($id) {
151
        try {
152
            $sd_location = Location::findOrFail($id);
153
            $sd_location->delete();
154
            return \Redirect::route('service-desk.location-category.index')->with('message', 'Location  successfully delete !!!');
155
        } catch (Exception $ex) {
156
            return redirect()->back()->with('fails', $ex->getMessage());
157
        }
158
    }
159
160 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...
161
        try {
162
            $locations = new Location();
163
            $location = $locations->find($id);
0 ignored issues
show
Documentation Bug introduced by
The method find does not exist on object<App\Itil\Models\Common\Location>? 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...
164
            if ($location) {
165
                return view('itil::location.show', compact('location'));
166
            } else {
167
                throw new \Exception('Sorry we can not find your request');
168
            }
169
        } catch (Exception $ex) {
170
            return redirect()->back()->with('fails', $ex->getMessage());
171
        }
172
    }
173
174
    public function getLocationsForForm(Request $request) {
175
        $id = $request->input('id');
176
        $assets = new \App\Itil\Model\Assets\SdAssets();
177
        $asset = $assets->find($id);
178
        $location_id = '';
179
        $select = "";
180
        if($asset){
181
            $location_id = $asset->location_id;
182
        }
183
        $html = "<option value=''>Select</option>";
184
        $orgid = $request->input('org');
185
        $location = $this->getLocationsByOrg($orgid);
186
        $locations = $location->lists('title', 'id')->toArray();
187
        if (count($locations) > 0) {
188
            foreach ($locations as $key => $value) {
189
                if($key==$location_id){
190
                    $select = 'selected';
191
                }
192
                $html .= "<option value='" . $key . "' $select>" . $value . "</option>";
193
            }
194
        }
195
        return $html;
196
    }
197
198
    public function getLocationsByOrg($orgid) {
199
        $location = new Location();
200
        $locations = $location->where('organization', $orgid);
0 ignored issues
show
Documentation Bug introduced by
The method where does not exist on object<App\Itil\Models\Common\Location>? 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...
201
        return $locations;
202
    }
203
204
}
205