UtilityController::getUserByAssetId()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 7

Duplication

Lines 8
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
eloc 7
nc 1
nop 1
dl 8
loc 8
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace App\Itil\Controllers;
4
5
use App\Http\Controllers\Controller;
6
use App\Itil\Models\Common\Attachments;
7
use Exception;
8
use Auth;
9
use App\Itil\Models\Common\GeneralInfo;
10
11
class UtilityController extends Controller {
12
13 View Code Duplication
    public static function assetSearch($query, $format = 'json') {
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...
14
        $assets = new SdAssets();
15
        $asset = $assets->where('name', 'LIKE', '%' . $query . '%')->select('name as label', 'id as value');
16
17
        if ($format == 'json') {
18
            $asset = $asset->get()->toJson();
19
        }
20
        return $asset;
21
    }
22
23
    public static function assetByTypeId($typeid) {
24
        $assets = new SdAssets();
25
        $asset = $assets->where('asset_type_id', $typeid);
26
        return $asset;
27
    }
28
29 View Code Duplication
    public static function getModelWithSelect($model, $select = []) {
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...
30
        try {
31
            if (count($select) > 0) {
32
                $model = $model->select($select);
33
            }
34
            return $model;
35
        } catch (Exception $ex) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
36
            
37
        }
38
    }
39
40 View Code Duplication
    public static function saveTicketRelation($ticketid, $table, $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...
41
42
        $relation = new \App\Itil\Models\Common\TicketRelation();
43
        $relations = $relation->where('ticket_id', $ticketid)->where('owner', 'LIKE', $table . "%")->get();
0 ignored issues
show
Documentation Bug introduced by
The method where does not exist on object<App\Itil\Models\Common\TicketRelation>? 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...
44
        if ($relations->count() > 0) {
45
            foreach ($relations as $del) {
46
                $del->delete();
47
            }
48
        }
49
        if (is_array($id)) {
50
            foreach ($id as $i) {
51
                $relation->create([
52
                    'ticket_id' => $ticketid,
53
                    'owner' => "$table:$i",
54
                ]);
55
            }
56
        } else {
57
            $owner = "$table:$id";
58
            $relation->create([
59
                'ticket_id' => $ticketid,
60
                'owner' => $owner,
61
            ]);
62
        }
63
    }
64
65 View Code Duplication
    public static function saveAssetRelation($assetid, $table, $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...
66
        if (is_array($assetid)) {
67
            $assetid = implode(',', $assetid);
68
        }
69
        $owner = "$table:$id";
70
        $relation = new \App\Itil\Models\Common\AssetRelation();
71
        $relations = $relation->where('owner', $owner)->get();
72
        if ($relations->count() > 0) {
73
            foreach ($relations as $del) {
74
                $del->delete();
75
            }
76
        }
77
        $relation->create([
78
            'asset_ids' => $assetid,
79
            'owner' => $owner,
80
        ]);
81
    }
82
83 View Code Duplication
    public static function getAssetByTicketid($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...
84
        $relation = new \App\Itil\Models\Common\AssetRelation();
85
        $model = $relation->where('owner', "tickets:$ticketid")->first();
86
        $asset = false;
87
        if ($model) {
88
            if ($model->asset_ids) {
89
                $assets = new SdAssets();
90
                $asset = $assets->where('id', $model->asset_id)->first();
91
            }
92
        }
93
        return $asset;
94
    }
95
96
    public static function detachAsset($table,$id) {
97
        $relation = new \App\Itil\Models\Common\AssetRelation();
98
        $model = $relation->where('owner', "$table:$id")->first();
99
        if ($model) {
100
            $model->delete();
101
        }
102
    }
103
104 View Code Duplication
    public static function getRelationOfTicketByTable($ticketid, $table) {
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...
105
        $realtions = new \App\Itil\Models\Common\TicketRelation();
106
        $realtion = $realtions->where('ticket_id', $ticketid)->where('owner', 'LIKE', $table . "%")->first();
0 ignored issues
show
Documentation Bug introduced by
The method where does not exist on object<App\Itil\Models\Common\TicketRelation>? 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...
107
        if ($realtion) {
108
            return $realtion;
109
        }
110
    }
111
112 View Code Duplication
    public static function getTicketByThreadId($threadid) {
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...
113
        $thread = \App\Model\helpdesk\Ticket\Ticket_Thread::where('id', $threadid)->first();
114
        $tickets = new \App\Itil\Models\Common\Ticket();
115
        $ticket = $tickets->where('id', $thread->ticket_id)->first();
0 ignored issues
show
Documentation Bug introduced by
The method where does not exist on object<App\Itil\Models\Common\Ticket>? 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...
116
        return $ticket;
117
    }
118
119 View Code Duplication
    public static function getUserByAssetId($assetid) {
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...
120
        $assets = new SdAssets();
121
        $asset = $assets->find($assetid);
122
        $userid = $asset->used_by;
123
        $users = new \App\User();
124
        $user = $users->find($userid);
0 ignored issues
show
Documentation Bug introduced by
The method find does not exist on object<App\User>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
125
        return $user;
126
    }
127
128 View Code Duplication
    public static function getManagedByAssetId($assetid) {
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...
129
        $assets = new SdAssets();
130
        $asset = $assets->find($assetid);
131
        $userid = $asset->managed_by;
132
        $users = new \App\User();
133
        $user = $users->find($userid);
0 ignored issues
show
Documentation Bug introduced by
The method find does not exist on object<App\User>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
134
        return $user;
135
    }
136
137
    public static function getRelationOfTicket($id) {
138
        $relations = new \App\Itil\Models\Common\TicketRelation();
139
        $relation = $relations->where('ticket_id', $id)->get();
0 ignored issues
show
Documentation Bug introduced by
The method where does not exist on object<App\Itil\Models\Common\TicketRelation>? 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...
140
        return $relation;
141
    }
142
143 View Code Duplication
    public static function getRelationOfAsset($table, $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...
144
        $relations = new \App\Itil\Models\Common\AssetRelation();
145
        $owner = "$table:$id";
146
        $relation = $relations->where('owner', $owner)->first();
147
        return $relation;
148
    }
149
150 View Code Duplication
    public static function getSubjectByThreadId($threadid) {
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...
151
        $threads = new \App\Model\helpdesk\Ticket\Ticket_Thread();
152
        $thread = $threads->find($threadid);
0 ignored issues
show
Documentation Bug introduced by
The method find does not exist on object<App\Model\helpdesk\Ticket\Ticket_Thread>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
153
        $ticketid = $thread->ticket_id;
154
        $thread_first = $threads->where('ticket_id', $ticketid)->first();
0 ignored issues
show
Documentation Bug introduced by
The method where does not exist on object<App\Model\helpdesk\Ticket\Ticket_Thread>? 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...
155
        return $thread_first->title;
156
    }
157
158 View Code Duplication
    public static function getBodyByThreadId($threadid) {
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...
159
        $threads = new \App\Model\helpdesk\Ticket\Ticket_Thread();
160
        $thread = $threads->find($threadid);
0 ignored issues
show
Documentation Bug introduced by
The method find does not exist on object<App\Model\helpdesk\Ticket\Ticket_Thread>? 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...
161
        $ticketid = $thread->ticket_id;
162
        $thread_first = $threads->where('ticket_id', $ticketid)->first();
0 ignored issues
show
Documentation Bug introduced by
The method where does not exist on object<App\Model\helpdesk\Ticket\Ticket_Thread>? 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...
163
        return $thread_first->body;
164
    }
165
166
    public static function getBodyByThreadMaxId($threadid) {
167
        $threads = new \App\Model\helpdesk\Ticket\Ticket_Thread();
168
        $thread = $threads->find($threadid);
0 ignored issues
show
Documentation Bug introduced by
The method find does not exist on object<App\Model\helpdesk\Ticket\Ticket_Thread>? 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...
169
        return $thread->body;
170
    }
171
172 View Code Duplication
    public static function attachment($id, $table, $attachments, $saved = 2) {
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...
173
        //dd($id);
174
        $owner = "$table:$id";
175
        $value = "";
0 ignored issues
show
Unused Code introduced by
$value is not used, you could remove the assignment.

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

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

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

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

Loading history...
176
        $type = "";
0 ignored issues
show
Unused Code introduced by
$type is not used, you could remove the assignment.

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

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

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

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

Loading history...
177
        $size = "";
0 ignored issues
show
Unused Code introduced by
$size is not used, you could remove the assignment.

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

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

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

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

Loading history...
178
179
        if (count($attachments) > 0) {
180
            foreach ($attachments as $attachment) {
181
                if ($attachment) {
182
                    $name = $attachment->getClientOriginalName();
183
                    $destinationPath = public_path('uploads/service-desk/attachments');
184
                    $value = rand(0000, 9999) . '.' . $name;
185
                    $type = $attachment->getClientOriginalExtension();
186
                    $size = $attachment->getSize();
187
                    if ($saved == 2) {
188
                        $attachment->move($destinationPath, $value);
189
                    } else {
190
                        $value = file_get_contents($attachment->getRealPath());
191
                    }
192
                    self::storeAttachment($saved, $owner, $value, $type, $size);
193
                }
194
            }
195
        }
196
    }
197
198 View Code Duplication
    public static function storeAttachment($saved, $owner, $value, $type, $size) {
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...
199
        $attachments = new Attachments();
200
        $attachments->create([
201
            'saved' => $saved,
202
            'owner' => $owner,
203
            'value' => $value,
204
            'type' => $type,
205
            'size' => $size,
206
        ]);
207
    }
208
209 View Code Duplication
    public static function deleteAttachments($id, $table) {
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
        $owner = "$table:$id";
211
        $attachments = new Attachments();
212
        $attachment = $attachments->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...
213
214
        if ($attachment) {
215
            self::removeAttachment($attachment);
216
        }
217
    }
218
219 View Code Duplication
    public static function removeAttachment($attachment) {
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...
220
        $saved = $attachment->saved;
221
        if ($saved == 2) {
222
            $file = $attachment->value;
223
            $path = public_path('uploads' . DIRECTORY_SEPARATOR . 'service-desk' . DIRECTORY_SEPARATOR . 'attachments' . DIRECTORY_SEPARATOR . $file);
224
            unlink($path);
225
        }
226
        $attachment->delete();
227
    }
228
229 View Code Duplication
    public static function downloadAttachment($attachment) {
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...
230
        $saved = $attachment->saved;
231
        if ($saved == 2) {
232
            $file = $attachment->value;
233
            $attach = public_path('uploads' . DIRECTORY_SEPARATOR . 'service-desk' . DIRECTORY_SEPARATOR . 'attachments' . DIRECTORY_SEPARATOR . $file);
234
        } else {
235
            $attach = $attachment->value;
236
        }
237
        return $attach;
238
    }
239
240 View Code Duplication
    public static function storeAssetRelation($table, $id, $asset_ids = [], $update = false) {
0 ignored issues
show
Unused Code introduced by
The parameter $update is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
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...
241
        $relations = new AssetRelation();
242
        $owner = "$table:$id";
243
        $relationses = $relations->where('owner', $owner)->get();
244
        if ($relationses->count() > 0) {
245
            foreach ($relationses as $relationse) {
246
                $relationse->delete();
247
            }
248
        }
249
        if (count($asset_ids) > 0) {
250
            if (is_array($asset_ids)) {
251
                $asset_ids = implode(',', $asset_ids);
252
            }
253
254
            $relations->asset_ids = $asset_ids;
255
            $relations->owner = $owner;
256
            $relations->save();
257
        }
258
    }
259
260 View Code Duplication
    public static function deleteAssetRelation($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...
261
        $relations = new AssetRelation();
262
        $relation = $relations->where('asset_ids', '!=', '')->get();
263
        $asset_ids = "";
0 ignored issues
show
Unused Code introduced by
$asset_ids is not used, you could remove the assignment.

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

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

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

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

Loading history...
264
        //dd($relation->asset_ids);
0 ignored issues
show
Unused Code Comprehensibility introduced by
72% 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...
265
        foreach ($relation as $del) {
266
            $array = $del->asset_ids;
267
            $array = array_diff($array, [$id]);
268
            if (count($array) > 0) {
269
                $asset_ids = implode(',', $array);
270
                $del->asset_ids = $asset_ids;
271
                $del->save();
272
            } else {
273
                $del->delete();
274
            }
275
        }
276
    }
277
278 View Code Duplication
    public static function xmlToArray($xml, $options = array()) {
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...
279
        $defaults = array(
280
            'namespaceSeparator' => ':', //you may want this to be something other than a colon
281
            'attributePrefix' => '', //to distinguish between attributes and nodes with the same name
282
            'alwaysArray' => array(), //array of xml tag names which should always become arrays
283
            'autoArray' => true, //only create arrays for tags which appear more than once
284
            'textContent' => 'option-name', //key used for the text content of elements
285
            'autoText' => true, //skip textContent key if node has no attributes or child nodes
286
            'keySearch' => false, //optional search and replace on tag and attribute names
287
            'keyReplace' => false       //replace values for above search values (as passed to str_replace())
288
        );
289
        $options = array_merge($defaults, $options);
290
        $namespaces = $xml->getDocNamespaces();
291
        $namespaces[''] = null; //add base (empty) namespace
0 ignored issues
show
Unused Code Comprehensibility introduced by
45% 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...
292
        //get attributes from all namespaces
293
        $attributesArray = array();
294
        foreach ($namespaces as $prefix => $namespace) {
295
            foreach ($xml->attributes($namespace) as $attributeName => $attribute) {
296
                //replace characters in attribute name
297
                if ($options['keySearch'])
298
                    $attributeName = str_replace($options['keySearch'], $options['keyReplace'], $attributeName);
299
                $attributeKey = $options['attributePrefix']
300
                        . ($prefix ? $prefix . $options['namespaceSeparator'] : '')
301
                        . $attributeName;
302
                $attributesArray[$attributeKey] = (string) $attribute;
303
            }
304
        }
305
306
        //get child nodes from all namespaces
307
        $tagsArray = array();
308
        foreach ($namespaces as $prefix => $namespace) {
309
            foreach ($xml->children($namespace) as $childXml) {
310
                //recurse into child nodes
311
                $childArray = self::xmlToArray($childXml, $options);
312
                list($childTagName, $childProperties) = each($childArray);
313
314
                //replace characters in tag name
315
                if ($options['keySearch'])
316
                    $childTagName = str_replace($options['keySearch'], $options['keyReplace'], $childTagName);
317
                //add namespace prefix, if any
318
                if ($prefix)
319
                    $childTagName = $prefix . $options['namespaceSeparator'] . $childTagName;
320
321
                if (!isset($tagsArray[$childTagName])) {
322
                    //only entry with this key
323
                    //test if tags of this type should always be arrays, no matter the element count
324
                    $tagsArray[$childTagName] = in_array($childTagName, $options['alwaysArray']) || !$options['autoArray'] ? array($childProperties) : $childProperties;
325
                } elseif (
326
                        is_array($tagsArray[$childTagName]) && array_keys($tagsArray[$childTagName]) === range(0, count($tagsArray[$childTagName]) - 1)
327
                ) {
328
                    //key already exists and is integer indexed array
329
                    $tagsArray[$childTagName][] = $childProperties;
330
                } else {
331
                    //key exists so convert to integer indexed array with previous value in position 0
332
                    $tagsArray[$childTagName] = array($tagsArray[$childTagName], $childProperties);
333
                }
334
            }
335
        }
336
337
        //get text content of node
338
        $textContentArray = array();
339
        $plainText = trim((string) $xml);
340
        if ($plainText !== '')
341
            $textContentArray[$options['textContent']] = $plainText;
342
343
        //stick it all together
344
        $propertiesArray = !$options['autoText'] || $attributesArray || $tagsArray || ($plainText === '') ? array_merge($attributesArray, $tagsArray, $textContentArray) : $plainText;
0 ignored issues
show
Bug Best Practice introduced by
The expression $attributesArray of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
Bug Best Practice introduced by
The expression $tagsArray of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
345
346
        //return node as array
0 ignored issues
show
Unused Code Comprehensibility introduced by
43% 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...
347
        return array(
348
            $xml->getName() => $propertiesArray
349
        );
350
    }
351
352 View Code Duplication
    public static function arrayToXml($array, $key = '', $options = false) {
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...
353
        $field = "";
354
        $value = "";
355
        //$options = false;
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% 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...
356
        if (is_integer($key)) {
357
            $field = "<field ";
358
            foreach ($array as $index => $item) {
359
360
                if (is_array($item)) {
361
                    $value = self::value($item);
362
                    $options = true;
363
                } elseif ($options == false) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

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

Loading history...
364
                    $it = '=' . '"' . $item . '" ';
365
                    $field .= $index . $it;
366
                }
367
            }
368
369
            $field .= ">$value</field>";
370
        }
371
372
        foreach ($array as $key => $value) {
373
            if (is_array($value)) {
374
                $field .= self::arrayToXml($value, $key, $options);
375
            }
376
        }
377
378
        return $field;
379
    }
380
381 View Code Duplication
    public static function value($item) {
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...
382
        $result = "";
383
        foreach ($item as $k => $v) {
384
            $result .= '<option value=' . '"' . $k . '"' . '>' . $v . '</option>';
385
        }
386
        return $result;
387
    }
388
389 View Code Duplication
    public static function deletePopUp($id, $url, $title = "Delete", $class = "btn btn-sm btn-danger", $btn_name = "Delete", $button_check = true) {
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...
390
        $button = "";
391
        if ($button_check == 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...
392
            $button = '<a href="#delete" class="' . $class . '" data-toggle="modal" data-target="#delete' . $id . '">' . $btn_name . '</a>';
393
        }
394
        return $button . '<div class="modal fade" id="delete' . $id . '">
395
                    <div class="modal-dialog">
396
                        <div class="modal-content">
397
                            <div class="modal-header">
398
                                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
399
                                <h4 class="modal-title">' . $title . '</h4>
400
                            </div>
401
                            <div class="modal-body">
402
                                <div class="row">
403
                                <div class="col-md-12">
404
                                <p>Are you sure ?</p>
405
                                </div>
406
                                </div>
407
                            </div>
408
                            <div class="modal-footer">
409
                                <button type="button" id="close" class="btn btn-default pull-left" data-dismiss="modal">Close</button>
410
                                <a href="' . $url . '" class="btn btn-danger">Delete</a>
411
                            </div>
412
                        </div>
413
                    </div>
414
                </div>';
415
    }
416
417 View Code Duplication
    public static function checkCabUser($cabid) {
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...
418
        $authid = Auth::user()->id;
419
        $result = false;
420
        $cabs = new \App\Itil\Models\Cab();
421
        $cab = $cabs->find($cabid);
422
        if ($cab) {
423
            $members = $cab->approvers;
424
            if (is_array($members)) {
425
                if (in_array($authid, $members)) {
426
                    $result = true;
427
                }
428
            } elseif (is_integer($members)) {
429
                if ($authid == $members) {
430
                    $result = true;
431
                }
432
            } elseif ($cab->head) {
433
                if ($authid == $cab->head) {
434
                    $result = true;
435
                }
436
            }
437
        }
438
        return $result;
439
    }
440
441 View Code Duplication
    public static function cabMessage($cabid, $activity, $url) {
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...
442
        $cabs = new \App\Itil\Models\Cab();
443
        $cab = $cabs->find($cabid);
444
        if ($cab) {
445
            $members = $cab->approvers;
446
            $head = $cab->head;
447
            if (is_array($members)) {
448
                if (count($members) > 0) {
449
                    foreach ($members as $userid) {
450
                        self::sendCabMessage($userid, $head, $activity, $url);
451
                    }
452
                }
453
            }
454
        }
455
    }
456
457 View Code Duplication
    public static function sendCabMessage($userid, $head, $activity, $url) {
0 ignored issues
show
Unused Code introduced by
The parameter $activity is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
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...
458
        $users = new \App\User();
459
        $user = $users->find($userid);
0 ignored issues
show
Documentation Bug introduced by
The method find does not exist on object<App\User>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
460
        $leader = $users->find($head);
0 ignored issues
show
Documentation Bug introduced by
The method find does not exist on object<App\User>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
461
        $heads = "";
462
        //dd($url);
463
        if ($user) {
464
            $email = $user->email;
465
            $name = $user->first_name . " " . $user->last_name;
466
            if ($leader) {
467
                $heads = $leader->first_name . " " . $leader->last_name;
468
            }
469
            //dd([$email,$name,$heads,$url]);
0 ignored issues
show
Unused Code Comprehensibility introduced by
93% 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...
470
            $php_mailer = new \App\Http\Controllers\Common\PhpMailController();
471
            $php_mailer->sendmail(
472
                    $from = $php_mailer->mailfrom('1', '0'), $to = ['name' => $name, 'email' => $email], $message = [
473
                'subject' => 'Requesting For CAB Approval',
474
                'scenario' => 'sd-cab-vote',
475
                    ], $template_variables = [
476
                'user' => $name,
477
                'system_link' => $url,
478
                '$system_from' => $heads,
479
                    ]
480
            );
481
        }
482
    }
483
484 View Code Duplication
    public static function storeGeneralInfo($modelid, $table, $requests) {
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...
485
        $owner = "$table:$modelid";
486
        $request = $requests->except('_token', 'attachment', 'identifier');
487
        // 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...
488
        $general = new GeneralInfo();
489
490
        if (count($request) > 0) {
491
            foreach ($request as $key => $value) {
492
                $generals = $general->where('owner', $owner)->where('key', $key)->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...
493
                if ($generals) {
494
                    $generals->delete();
495
                }
496
                if ($value !== "") {
497
                    $general->create([
498
                        'owner' => $owner,
499
                        'key' => $key,
500
                        'value' => $value,
501
                    ]);
502
                }
503
            }
504
        }
505
506
        $attachments = $requests->file('attachment');
507
        $identifier = $requests->input('identifier');
508
        $attach_table = "$table:$identifier";
509
        self::attachment($modelid, $attach_table, $attachments);
510
        return "success";
511
    }
512
513 View Code Duplication
    public static function getAttachmentSize($size) {
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...
514
        $units = array('B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB');
515
        $power = $size > 0 ? floor(log($size, 1024)) : 0;
516
        $value = number_format($size / pow(1024, $power), 2, '.', ',') . ' ' . $units[$power];
517
        return $value;
518
    }
519
520
}
521