ProblemController   C
last analyzed

Complexity

Total Complexity 55

Size/Duplication

Total Lines 361
Duplicated Lines 61.22 %

Coupling/Cohesion

Components 0
Dependencies 11

Importance

Changes 0
Metric Value
dl 221
loc 361
rs 6
c 0
b 0
f 0
wmc 55
lcom 0
cbo 11

24 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A index() 0 7 2
B getProblems() 41 41 4
A create() 17 17 2
A handleCreate() 0 10 2
A edit() 0 19 2
A handleEdit() 8 8 2
A delete() 0 9 2
A attachNewProblemToTicket() 20 20 4
A attachExistingProblemToTicket() 10 10 2
A store() 0 16 3
A update() 17 17 3
B getAttachableProblem() 27 27 2
A timelineMarble() 0 6 2
A marble() 6 6 1
A marbleHtml() 22 22 1
A detach() 0 10 3
A show() 14 14 3
A close() 0 15 3
A getChanges() 14 14 1
A attachNewChange() 13 13 3
A attachExistingChange() 0 11 3
A changeAttach() 0 7 1
A detachChange() 12 12 3

How to fix   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like ProblemController often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use ProblemController, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
namespace App\Itil\Controllers;
4
5
use App\Itil\Controllers\BaseServiceDeskController;
6
use App\Itil\Models\Problem\SdProblem;
7
use App\Itil\Models\Problem\Impact;
8
use App\Itil\Models\Problem\Location;
9
use App\Model\helpdesk\Ticket\Ticket_Priority as Priority;
10
use App\Itil\Requests\CreateProblemRequest;
11
use Illuminate\Http\Request;
12
use App\User;
13
use App\Model\helpdesk\Agent\Groups as Group;
14
use App\Model\helpdesk\Ticket\Ticket_Status as TicketType;
15
use App\Model\helpdesk\Agent\Department;
16
use App\Itil\Requests\CreateChangesRequest;
17
18
class ProblemController extends BaseServiceDeskController {
19
20
    public function __construct() {
21
        $this->middleware('auth');
22
    }
23
24
    public function index() {
25
        try {
26
            return view('itil::problem.index');
27
        } catch (Exception $ex) {
0 ignored issues
show
Bug introduced by
The class App\Itil\Controllers\Exception does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
28
            return redirect()->back()->with('fails', $ex->getMessage());
29
        }
30
    }
31
32 View Code Duplication
    public function getProblems() {
0 ignored issues
show
Duplication introduced by
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...
33
        try {
34
            $problem = new SdProblem();
35
            $problems = $problem->select('id', 'department', 'status_type_id', 'from', 'subject')->get();
0 ignored issues
show
Documentation Bug introduced by
The method select does not exist on object<App\Itil\Models\Problem\SdProblem>? 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...
36
            return \Datatable::Collection($problems)
37
                            ->showColumns('from')
38
                            ->addColumn('subject', function($model) {
39
                                return str_limit($model->subject, 10);
40
                            })
41
                            ->addColumn('department', function($model) {
42
                                $depertment_type_name = "Common";
43
                                $depertment_types = new Department;
44
                                $depertment_type = $depertment_types->where('id', $model->department)->first();
0 ignored issues
show
Documentation Bug introduced by
The method where does not exist on object<App\Model\helpdesk\Agent\Department>? 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...
45
                                if ($depertment_type) {
46
                                    $depertment_type_name = $depertment_type->name;
47
                                }
48
                                return $depertment_type_name;
49
                            })
50
                            ->addColumn('ticket_type', function($model) {
51
                                $ticket_status_name = "";
52
                                $ticket_statuses = new TicketType;
53
                                $ticket_status = $ticket_statuses->where('id', $model->status_type_id)->first();
0 ignored issues
show
Documentation Bug introduced by
The method where does not exist on object<App\Model\helpdesk\Ticket\Ticket_Status>? 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...
54
                                if ($ticket_status) {
55
                                    $ticket_status_name = $ticket_status->name;
56
                                }
57
                                return $ticket_status_name;
58
                            })
59
                            ->addColumn('Action', function($model) {
60
                                $url = url('service-desk/problem/' . $model->id . '/delete');
61
                                $delete = \App\Itil\Controllers\UtilityController::deletePopUp($model->id, $url, "Delete $model->subject");
62
                                return "<a href=" . url('service-desk/problem/' . $model->id . '/edit') . " class='btn btn-info btn-sm'>Edit</a> "
63
                                        . $delete
64
                                        . " <a href=" . url('service-desk/problem/' . $model->id . '/show') . " class='btn btn-primary btn-sm'>View</a>";
65
                            })
66
                            ->searchColumns('description')
67
                            ->orderColumns('department', 'ticket_type', 'priority_id', 'location_type_id', 'agent_id')
68
                            ->make();
69
        } catch (Exception $ex) {
0 ignored issues
show
Bug introduced by
The class App\Itil\Controllers\Exception does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
70
            return redirect()->back()->with('fails', $ex->getMessage());
71
        }
72
    }
73
74 View Code Duplication
    public function create() {
0 ignored issues
show
Duplication introduced by
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...
75
        try {
76
            $assigned_ids = User::where('role', '!=', 'user')->lists('email', 'id')->toArray();
77
            $group_ids = Group::lists('name', 'id')->toArray();
78
            $impact_ids = Impact::lists('name', 'id')->toArray();
79
            $location_type_ids = Location::lists('title', 'id')->toArray();
80
            $priority_ids = Priority::lists('priority', 'priority_id')->toArray();
81
            $status_type_ids = TicketType::lists('name', 'id')->toArray();
82
            $departments = Department::lists('name', 'id')->toArray();
83
            $from = User::lists('email', 'email')->toArray();
84
            //            $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...
85
86
            return view('itil::problem.create', compact('departments', 'assigned_ids', 'group_ids', 'impact_ids', 'location_type_ids', 'priority_ids', 'status_type_ids', 'from'));
87
        } catch (Exception $ex) {
0 ignored issues
show
Bug introduced by
The class App\Itil\Controllers\Exception does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
88
            return redirect()->back()->with('fails', $ex->getMessage());
89
        }
90
    }
91
92
    public function handleCreate(CreateProblemRequest $request) {
93
        // dd($request);
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...
94
95
        try {
96
            $this->store($request);
97
            return \Redirect::route('service-desk.problem.index')->with('success', 'Problem Created Successfully');
98
        } catch (Exception $ex) {
0 ignored issues
show
Bug introduced by
The class App\Itil\Controllers\Exception does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
99
            return redirect()->back()->with('fails', $ex->getMessage());
100
        }
101
    }
102
103
    public function edit($id) {
104
// 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...
105
        try {
106
107
            $problem = SdProblem::findOrFail($id);
108
            $assigned_ids = User::where('role', '!=', 'user')->lists('email', 'id')->toArray();
109
            $group_ids = Group::lists('name', 'id')->toArray();
110
            $impact_ids = Impact::lists('name', 'id')->toArray();
111
            $location_type_ids = Location::lists('title', 'id')->toArray();
112
            $priority_ids = Priority::lists('priority', 'priority_id')->toArray();
113
            $status_type_ids = TicketType::lists('name', 'id')->toArray();
114
            $departments = Department::lists('name', 'id')->toArray();
115
//            $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...
116
            $from = User::lists('email', 'email')->toArray();
117
            return view('itil::problem.edit', compact('assets', 'problem', 'assigned_ids', 'group_ids', 'impact_ids', 'location_type_ids', 'priority_ids', 'status_type_ids', 'departments', 'from'));
118
        } catch (Exception $ex) {
0 ignored issues
show
Bug introduced by
The class App\Itil\Controllers\Exception does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
119
            return redirect()->back()->with('fails', $ex->getMessage());
120
        }
121
    }
122
123 View Code Duplication
    public function handleEdit($id, CreateProblemRequest $request) {
0 ignored issues
show
Duplication introduced by
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...
124
        try {
125
            $this->update($id, $request);
126
            return \Redirect::route('service-desk.problem.index')->with('success', 'Problem Updated Successfully');
127
        } catch (Exception $ex) {
0 ignored issues
show
Bug introduced by
The class App\Itil\Controllers\Exception does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
128
            return redirect()->back()->with('fails', $ex->getMessage());
129
        }
130
    }
131
132
    public function delete($id) {
133
        try {
134
            $sdproblems = SdProblem::findOrFail($id);
135
            $sdproblems->delete();
136
            return \Redirect::route('service-desk.problem.index')->with('success', 'Problem Deleted Successfully');
137
        } catch (Exception $ex) {
0 ignored issues
show
Bug introduced by
The class App\Itil\Controllers\Exception does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
138
            return redirect()->back()->with('fails', $ex->getMessage());
139
        }
140
    }
141
142 View Code Duplication
    public function attachNewProblemToTicket(Request $request) {
0 ignored issues
show
Duplication introduced by
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...
143
        try {
144
            $ticketid = $request->input('ticketid');
145
            $store = $this->store($request, $ticketid);
0 ignored issues
show
Unused Code introduced by
The call to ProblemController::store() has too many arguments starting with $ticketid.

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...
146
            if ($store) {
147
                \App\Itil\Controllers\UtilityController::saveTicketRelation($ticketid, 'sd_problem', $store->id);
148
                if (is_array($store->assets())) {
149
                    $assetid = $store->assets();
0 ignored issues
show
Bug introduced by
The method assets does only exist in App\Itil\Models\Problem\SdProblem, but not in Illuminate\Http\RedirectResponse.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
150
151
                    \App\Itil\Controllers\UtilityController::saveTicketRelation($ticketid, 'sd_assets', $assetid);
152
                }
153
154
                return redirect()->back()->with('success', 'Created new Problem and attached to this ticket');
155
            }
156
            return redirect()->back()->with('fails', 'Sorry! We can not processs your request');
157
        } catch (\Exception $ex) {
158
            dd($ex);
159
            return redirect()->back()->with('fails', $ex->getMessage());
160
        }
161
    }
162
163 View Code Duplication
    public function attachExistingProblemToTicket(Request $request) {
0 ignored issues
show
Duplication introduced by
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...
164
        try {
165
            $ticketid = $request->input('ticketid');
166
            $problemid = $request->input('problemid');
167
            \App\Itil\Controllers\UtilityController::saveTicketRelation($ticketid, 'sd_problem', $problemid);
168
            return redirect()->back()->with('success', 'Problem attached to this ticket');
169
        } catch (Exception $ex) {
0 ignored issues
show
Bug introduced by
The class App\Itil\Controllers\Exception does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
170
            dd($ex);
171
        }
172
    }
173
174
    public function store($request) {
175
        try {
176
            $sd_problems = new SdProblem;
177
            $assetid = $request->input('asset');
178
            $attachments = $request->file('attachment');
179
            $sd_problems->fill($request->input())->save();
180
            \App\Itil\Controllers\UtilityController::attachment($sd_problems->id, 'sd_problem', $attachments);
0 ignored issues
show
Documentation introduced by
The property id does not exist on object<App\Itil\Models\Problem\SdProblem>. 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...
181
            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...
182
                \App\Itil\Controllers\UtilityController::storeAssetRelation('sd_problem', $sd_problems->id, $assetid);
0 ignored issues
show
Documentation introduced by
The property id does not exist on object<App\Itil\Models\Problem\SdProblem>. 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...
183
            }
184
            return $sd_problems;
185
        } catch (Exception $ex) {
0 ignored issues
show
Bug introduced by
The class App\Itil\Controllers\Exception does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
186
            dd($ex);
187
            return redirect()->back()->with('fails', $ex->getMessage());
188
        }
189
    }
190
191 View Code Duplication
    public function update($id, $request) {
0 ignored issues
show
Duplication introduced by
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...
192
        try {
193
            $sd_problems = new SdProblem;
194
            $sd_problem = $sd_problems->find($id);
0 ignored issues
show
Documentation Bug introduced by
The method find does not exist on object<App\Itil\Models\Problem\SdProblem>? 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...
195
            $assetid = $request->input('asset');
196
            $attachments = $request->file('attachment');
197
            $sd_problem->fill($request->input())->save();
198
            \App\Itil\Controllers\UtilityController::attachment($sd_problem->id, 'sd_problem', $attachments);
199
            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...
200
                \App\Itil\Controllers\UtilityController::storeAssetRelation('sd_problem', $sd_problems->id, $assetid);
0 ignored issues
show
Documentation introduced by
The property id does not exist on object<App\Itil\Models\Problem\SdProblem>. 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...
201
            }
202
            return "success";
203
        } catch (Exception $ex) {
0 ignored issues
show
Bug introduced by
The class App\Itil\Controllers\Exception does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
204
            dd($ex);
205
            return redirect()->back()->with('fails', $ex->getMessage());
206
        }
207
    }
208
209 View Code Duplication
    public function getAttachableProblem() {
0 ignored issues
show
Duplication introduced by
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...
210
        $model = new SdProblem();
211
        $select = ['id', 'subject'];
212
        $problems = \App\Itil\Controllers\UtilityController::getModelWithSelect($model, $select);
213
        return \Datatable::Collection($problems->get())
214
                        ->addColumn('id', function($model) {
215
                            return \Form::radio('problemid', $model->id);
216
                        })
217
                        ->addColumn('subject', function($model) {
218
                            $subject = str_limit($model->subject, 20, '...');
219
                            return "<p title=$model->subject>$subject<p>";
220
                        })
221
                        ->addColumn('status', function($model) {
222
                            $status = "";
223
                            $statusid = $model->status_type_id;
224
                            $ticket_statuses = new \App\Model\helpdesk\Ticket\Ticket_Status();
225
                            $ticket_status = $ticket_statuses->find($statusid);
0 ignored issues
show
Documentation Bug introduced by
The method find does not exist on object<App\Model\helpdesk\Ticket\Ticket_Status>? 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...
226
                            if ($ticket_status) {
227
                                $status = $ticket_status->name;
228
                            }
229
230
                            return $status;
231
                        })
232
                        ->searchColumns('subject')
233
                        ->orderColumns('subject')
234
                        ->make();
235
    }
236
237
    public function timelineMarble($problem, $ticketid) {
238
        if ($problem) {
239
            echo $this->marble($problem, $ticketid);
240
        }
241
        echo "";
242
    }
243
244 View Code Duplication
    public function marble($problem, $ticketid) {
0 ignored issues
show
Duplication introduced by
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...
245
        $subject = $problem->subject;
246
        $content = $problem->description;
247
        $problemid = $problem->id;
248
        return $this->marbleHtml($ticketid, $problemid, $subject, $content);
249
    }
250
251 View Code Duplication
    public function marbleHtml($ticketid, $problemid, $subject, $content) {
0 ignored issues
show
Duplication introduced by
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...
252
        $subject_trim = str_limit($subject, 20);
253
        $content_trim = str_limit($content, 20);
254
        $url = url('service-desk/problem/detach/' . $ticketid . '/' . $problemid);
255
        $detach_popup = \App\Itil\Controllers\UtilityController::deletePopUp($problemid, $url, "Delete", " ", "Delete", true);
256
        return "<div class='box box-primary'>"
257
                . "<div class='box-header'>"
258
                . "<h3 class='box-title'>Associated Problems</h3>"
259
                . "</div>"
260
                . "<div class='box-body row'>"
261
                . "<div class='col-md-12'>"
262
                . "<table class='table'>"
263
                . "<tr>"
264
                . "<th>" . ucfirst($subject_trim) . "</th>"
265
                . "<th>" . ucfirst($content_trim) . "</th>"
266
                . "<th>" . $detach_popup
267
                . "  | <a href=" . url('service-desk/problem/' . $problemid . '/show') . ">View</a></th>"
268
                . "</table>"
269
                . "</div>"
270
                . "</div>"
271
                . "</div>";
272
    }
273
274
    public function detach($ticketid, $problemid) {
275
        $relation = \App\Itil\Controllers\UtilityController::getRelationOfTicketByTable($ticketid, 'sd_problem');
276
        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...
277
            \App\Itil\Controllers\UtilityController::detachAsset('sd_problem', $problemid);
278
        }
279
        if ($relation) {
280
            $relation->delete();
281
        }
282
        return redirect()->back()->with('success', 'Detached successfully');
283
    }
284
285 View Code Duplication
    public function show($id) {
0 ignored issues
show
Duplication introduced by
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...
286
        try {
287
            $problems = new SdProblem();
288
            $problem = $problems->find($id);
0 ignored issues
show
Documentation Bug introduced by
The method find does not exist on object<App\Itil\Models\Problem\SdProblem>? 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...
289
            if ($problem) {
290
291
                return view('itil::problem.show', compact('problem'));
292
            } else {
293
                throw new \Exception('Sorry we can not find your request');
294
            }
295
        } catch (\Exception $ex) {
296
            return redirect()->back()->with('fails', $ex->getMessage());
297
        }
298
    }
299
300
    public function close($id) {
301
        try {
302
            $problems = new SdProblem();
303
            $problem = $problems->find($id);
0 ignored issues
show
Documentation Bug introduced by
The method find does not exist on object<App\Itil\Models\Problem\SdProblem>? 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...
304
            if ($problem) {
305
                $problem->status_type_id = 3;
306
                $problem->save();
307
                return redirect()->back()->with('success', 'Updated');
308
            } else {
309
                throw new \Exception('Sorry we can not find your request');
310
            }
311
        } catch (\Exception $ex) {
312
            return redirect()->back()->with('fails', $ex->getMessage());
313
        }
314
    }
315
316 View Code Duplication
    public function getChanges() {
0 ignored issues
show
Duplication introduced by
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...
317
        $change = new \App\Itil\Models\Changes\SdChanges();
318
        $changes = $change->select('id', 'subject')->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...
319
        return \Datatable::Collection($changes)
320
                        ->addColumn('id', function($model) {
321
                            return "<input type='radio' name='change' value='" . $model->id . "'>";
322
                        })
323
                        ->addColumn('subject', function($model) {
324
                            return str_limit($model->subject, 20);
325
                        })
326
                        ->orderColumns('subject')
327
                        ->searchColumns('subject')
328
                        ->make();
329
    }
330
331 View Code Duplication
    public function attachNewChange($id, CreateChangesRequest $request) {
0 ignored issues
show
Duplication introduced by
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...
332
        try {
333
            $change_controller = new ChangesController();
334
            $change = $change_controller->changeshandleCreate($request, true);
335
336
            $this->changeAttach($id, $change->id);
337
            if ($change) {
338
                return redirect()->back()->with('success', 'Updated');
339
            }
340
        } catch (\Exception $ex) {
341
            return redirect()->back()->with('fails', $ex->getMessage());
342
        }
343
    }
344
345
    public function attachExistingChange($id, Request $request) {
346
        try {
347
            $changeid = $request->input('change');
348
            $store = $this->changeAttach($id, $changeid);
349
            if ($store) {
350
                return redirect()->back()->with('success', 'Updated');
351
            }
352
        } catch (\Exception $ex) {
353
            return redirect()->back()->with('fails', $ex->getMessage());
354
        }
355
    }
356
357
    public function changeAttach($problemid, $changeid) {
358
        $relation = new \App\Itil\Models\Problem\ProblemChangeRelation();
359
        return $relation->create([
360
                    'problem_id' => $problemid,
361
                    'change_id' => $changeid,
362
        ]);
363
    }
364
365 View Code Duplication
    public function detachChange($problemid) {
0 ignored issues
show
Duplication introduced by
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...
366
        try {
367
            $relations = new \App\Itil\Models\Problem\ProblemChangeRelation();
368
            $relation = $relations->where('problem_id', $problemid)->first();
0 ignored issues
show
Documentation Bug introduced by
The method where does not exist on object<App\Itil\Models\P...\ProblemChangeRelation>? 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...
369
            if ($relation) {
370
                $relation->delete();
371
            }
372
            return redirect()->back()->with('success', 'Updated');
373
        } catch (\Exception $ex) {
374
            return redirect()->back()->with('fails', $ex->getMessage());
375
        }
376
    }
377
378
}
379