InterfaceController   A
last analyzed

Complexity

Total Complexity 24

Size/Duplication

Total Lines 116
Duplicated Lines 59.48 %

Coupling/Cohesion

Components 0
Dependencies 7

Importance

Changes 0
Metric Value
dl 69
loc 116
rs 10
c 0
b 0
f 0
wmc 24
lcom 0
cbo 7

12 Methods

Rating   Name   Duplication   Size   Complexity  
A agentSidebar() 0 4 1
A agentTopbar() 0 4 1
A agentTopSubbar() 0 4 1
A adminSidebar() 0 4 1
A adminTopbar() 0 4 1
A adminTopSubbar() 0 4 1
A adminSettings() 0 4 1
A ticketDetailTable() 0 4 1
A generalInfo() 13 13 3
A deleteAttachments() 14 14 3
A downloadAttachments() 16 16 4
B deleteGeneralByIdentifier() 26 26 6

How to fix   Duplicated Code   

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:

1
<?php
2
3
namespace App\Itil\Controllers;
4
5
use App\Itil\Controllers\BaseServiceDeskController;
6
use Exception;
7
use Illuminate\Http\Request;
8
9
class InterfaceController extends BaseServiceDeskController {
10
11
    public function agentSidebar() {
12
       
13
        return view('itil::interface.agent.sidebar');
14
    }
15
16
    public function agentTopbar() {
17
        
18
        return view('itil::interface.agent.topbar');
19
    }
20
21
    public function agentTopSubbar() {
22
        
23
        return view('itil::interface.agent.topsubbar');
24
    }
25
26
    public function adminSidebar() {
27
        
28
        return view('itil::interface.admin.sidebar');
29
    }
30
31
    public function adminTopbar() {
32
        
33
        return view('itil::interface.admin.topbar');
34
    }
35
36
    public function adminTopSubbar() {
37
        
38
        return view('itil::interface.admin.topsubbar');
39
    }
40
41
    public function adminSettings() {
42
        
43
        return view('itil::interface.admin.settings');
44
    }
45
46
    public function ticketDetailTable($event) {
47
        $id = $event->para1;
48
        return view("itil::interface.agent.ticket-head", compact('id'));
49
    }
50
51 View Code Duplication
    public function generalInfo($id, $table, 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...
52
        //dd($request);
53
        try {
54
            $store = UtilityController::storeGeneralInfo($id, $table, $request);
55
            //dd($store);
56
            if ($store == "success") {
57
                return redirect()->back()->with('success', 'Updated');
58
            }
59
            throw new Exception("Sorry we can not process your request");
60
        } catch (Exception $ex) {
61
            return redirect()->back()->with('fails', $ex->getMessage());
62
        }
63
    }
64
65 View Code Duplication
    public function deleteAttachments($attachid, $owner) {
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...
66
        try {
67
            $attachments = new \App\Itil\Models\Common\Attachments();
68
            $attachment = $attachments->where('id', $attachid)->where('owner', $owner)->first();
0 ignored issues
show
Documentation Bug introduced by
The method where does not exist on object<App\Itil\Models\Common\Attachments>? 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...
69
            if ($attachment) {
70
                UtilityController::removeAttachment($attachment);
71
            } else {
72
                throw new Exception("Sorry we can not find your request");
73
            }
74
            return redirect()->back()->with('success', 'Updated');
75
        } catch (Exception $ex) {
76
            return redirect()->back()->with('fails', $ex->getMessage());
77
        }
78
    }
79
80 View Code Duplication
    public function downloadAttachments($attachid, $owner) {
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...
81
        try {
82
            $attachments = new \App\Itil\Models\Common\Attachments();
83
            $attachment = $attachments->where('id', $attachid)->where('owner', $owner)->first();
0 ignored issues
show
Documentation Bug introduced by
The method where does not exist on object<App\Itil\Models\Common\Attachments>? 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...
84
            if ($attachment) {
85
                $attach = UtilityController::downloadAttachment($attachment);
86
                if ($attachment->saved == 2) {
87
                    return response()->download($attach);
88
                }
89
            } else {
90
                throw new Exception("Sorry we can not find your request");
91
            }
92
        } catch (Exception $ex) {
93
            return redirect()->back()->with('fails', $ex->getMessage());
94
        }
95
    }
96
97 View Code Duplication
    public function deleteGeneralByIdentifier($owner, $identifier) {
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...
98
        try {
99
            $genereals = new \App\Itil\Models\Common\GeneralInfo();
100
            $genereal = $genereals->where('owner', $owner)->where('key', $identifier)->first();
0 ignored issues
show
Documentation Bug introduced by
The method where does not exist on object<App\Itil\Models\Common\GeneralInfo>? 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...
101
            if ($genereal) {
102
                $attachments = new \App\Itil\Models\Common\Attachments();
103
                $atach_owner = str_replace(":", ":$identifier:", $owner);
104
                $attachment = $attachments->where('owner', $atach_owner)->first();
0 ignored issues
show
Documentation Bug introduced by
The method where does not exist on object<App\Itil\Models\Common\Attachments>? 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...
105
                if($attachment){
106
                    UtilityController::removeAttachment($attachment);
107
                }
108
                if ($identifier == "solution") {
109
                    $title = $genereals->where('owner', $owner)->where('key', "solution-title")->first();
0 ignored issues
show
Documentation Bug introduced by
The method where does not exist on object<App\Itil\Models\Common\GeneralInfo>? 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...
110
                    if ($title) {
111
                        $title->delete();
112
                    }
113
                }
114
                $genereal->delete();
115
            } else {
116
                throw new Exception("Sorry we can not find your request");
117
            }
118
            return redirect()->back()->with('success', 'Updated');
119
        } catch (Exception $ex) {
120
            return redirect()->back()->with('fails', $ex->getMessage());
121
        }
122
    }
123
124
}
125