UtilityController::getAssetByTicketid()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 9

Duplication

Lines 12
Ratio 100 %

Importance

Changes 0
Metric Value
cc 3
eloc 9
nc 3
nop 1
dl 12
loc 12
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace App\Plugins\ServiceDesk\Controllers\Library;
4
5
use App\Http\Controllers\Controller;
6
use App\Plugins\ServiceDesk\Model\Assets\SdAssets;
7
use App\Plugins\ServiceDesk\Model\Common\Attachments;
8
use Exception;
9
use App\Plugins\ServiceDesk\Model\Common\AssetRelation;
10
use Auth;
11
use App\Plugins\ServiceDesk\Model\Common\GeneralInfo;
12
13
class UtilityController extends Controller {
14
15 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...
16
        $assets = new SdAssets();
17
        $asset = $assets->where('name', 'LIKE', '%' . $query . '%')->select('name as label', 'id as value');
0 ignored issues
show
Documentation Bug introduced by
The method where does not exist on object<App\Plugins\Servi...\Model\Assets\SdAssets>? 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...
18
19
        if ($format == 'json') {
20
            $asset = $asset->get()->toJson();
21
        }
22
        return $asset;
23
    }
24
25
    public static function assetByTypeId($typeid) {
26
        $assets = new SdAssets();
27
        $asset = $assets->where('asset_type_id', $typeid);
0 ignored issues
show
Documentation Bug introduced by
The method where does not exist on object<App\Plugins\Servi...\Model\Assets\SdAssets>? 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...
28
        return $asset;
29
    }
30
31 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...
32
        try {
33
            if (count($select) > 0) {
34
                $model = $model->select($select);
35
            }
36
            return $model;
37
        } catch (Exception $ex) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
38
            
39
        }
40
    }
41
42 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...
43
        
44
        $relation = new \App\Plugins\ServiceDesk\Model\Common\TicketRelation();
45
        $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\Plugins\Servi...\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...
46
        if ($relations->count() > 0) {
47
            foreach ($relations as $del) {
48
                $del->delete();
49
            }
50
        }
51
        if (is_array($id)) {
52
            foreach ($id as $i) {
53
                $relation->create([
54
                    'ticket_id' => $ticketid,
55
                    'owner' => "$table:$i",
56
                ]);
57
            }
58
        } else {
59
            $owner = "$table:$id";
60
            $relation->create([
61
                'ticket_id' => $ticketid,
62
                'owner' => $owner,
63
            ]);
64
        }
65
    }
66
67 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...
68
        if (is_array($assetid)) {
69
            $assetid = implode(',', $assetid);
70
        }
71
        $owner = "$table:$id";
72
        $relation = new \App\Plugins\ServiceDesk\Model\Common\AssetRelation();
73
        $relations = $relation->where('owner', $owner)->get();
0 ignored issues
show
Documentation Bug introduced by
The method where does not exist on object<App\Plugins\Servi...l\Common\AssetRelation>? 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...
74
        if ($relations->count() > 0) {
75
            foreach ($relations as $del) {
76
                $del->delete();
77
            }
78
        }
79
        $relation->create([
80
            'asset_ids' => $assetid,
81
            'owner' => $owner,
82
        ]);
83
    }
84
85 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...
86
        $relation = new \App\Plugins\ServiceDesk\Model\Common\AssetRelation();
87
        $model = $relation->where('owner', "tickets:$ticketid")->first();
0 ignored issues
show
Documentation Bug introduced by
The method where does not exist on object<App\Plugins\Servi...l\Common\AssetRelation>? 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...
88
        $asset = false;
89
        if ($model) {
90
            if ($model->asset_id) {
91
                $assets = new SdAssets();
92
                $asset = $assets->where('id', $model->asset_id)->first();
0 ignored issues
show
Documentation Bug introduced by
The method where does not exist on object<App\Plugins\Servi...\Model\Assets\SdAssets>? 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...
93
            }
94
        }
95
        return $asset;
96
    }
97
98 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...
99
        $realtions  = new \App\Plugins\ServiceDesk\Model\Common\TicketRelation();
100
        $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\Plugins\Servi...\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...
101
        if($realtion){
102
            return $realtion;
103
        }
104
    }
105
106 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...
107
        $thread = \App\Model\helpdesk\Ticket\Ticket_Thread::where('id', $threadid)->first();
108
        $tickets = new \App\Plugins\ServiceDesk\Model\Common\Ticket();
109
        $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\Plugins\Servi...sk\Model\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...
110
        return $ticket;
111
    }
112
113 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...
114
        $assets = new SdAssets();
115
        $asset = $assets->find($assetid);
0 ignored issues
show
Documentation Bug introduced by
The method find does not exist on object<App\Plugins\Servi...\Model\Assets\SdAssets>? 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
        $userid = $asset->used_by;
117
        $users = new \App\User();
118
        $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...
119
        return $user;
120
    }
121
122 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...
123
        $assets = new SdAssets();
124
        $asset = $assets->find($assetid);
0 ignored issues
show
Documentation Bug introduced by
The method find does not exist on object<App\Plugins\Servi...\Model\Assets\SdAssets>? 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
        $userid = $asset->managed_by;
126
        $users = new \App\User();
127
        $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...
128
        return $user;
129
    }
130
131
    public static function getRelationOfTicket($id) {
132
        $relations = new \App\Plugins\ServiceDesk\Model\Common\TicketRelation();
133
        $relation = $relations->where('ticket_id', $id)->get();
0 ignored issues
show
Documentation Bug introduced by
The method where does not exist on object<App\Plugins\Servi...\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...
134
        return $relation;
135
    }
136
137 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...
138
        $relations = new \App\Plugins\ServiceDesk\Model\Common\AssetRelation();
139
        $owner = "$table:$id";
140
        $relation = $relations->where('owner', $owner)->first();
0 ignored issues
show
Documentation Bug introduced by
The method where does not exist on object<App\Plugins\Servi...l\Common\AssetRelation>? 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...
141
        return $relation;
142
    }
143
144 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...
145
        $threads = new \App\Model\helpdesk\Ticket\Ticket_Thread();
146
        $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...
147
        $ticketid = $thread->ticket_id;
148
        $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...
149
        return $thread_first->title;
150
    }
151
152 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...
153
        $threads = new \App\Model\helpdesk\Ticket\Ticket_Thread();
154
        $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...
155
        $ticketid = $thread->ticket_id;
156
        $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...
157
        return $thread_first->body;
158
    }
159
160
    public static function getBodyByThreadMaxId($threadid) {
161
        $threads = new \App\Model\helpdesk\Ticket\Ticket_Thread();
162
        $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...
163
        return $thread->body;
164
    }
165
166 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...
167
        //dd($id);
168
        $owner = "$table:$id";
169
        $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...
170
        $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...
171
        $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...
172
173
        if (count($attachments) > 0) {
174
            foreach ($attachments as $attachment) {
175
                if ($attachment) {
176
                    $name = $attachment->getClientOriginalName();
177
                    $destinationPath = 'uploads/service-desk/attachments';
178
                    $value = rand(0000, 9999) . '.' . $name;
179
                    $type = $attachment->getClientOriginalExtension();
180
                    $size = $attachment->getSize();
181
                    if ($saved == 2) {
182
                        $attachment->move($destinationPath, $value);
183
                    } else {
184
                        $value = file_get_contents($attachment->getRealPath());
185
                    }
186
                    self::storeAttachment($saved, $owner, $value, $type, $size);
187
                }
188
            }
189
        }
190
    }
191
192 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...
193
        $attachments = new Attachments();
194
        $attachments->create([
195
            'saved' => $saved,
196
            'owner' => $owner,
197
            'value' => $value,
198
            'type' => $type,
199
            'size' => $size,
200
        ]);
201
    }
202
203 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...
204
        $owner = "$table:$id";
205
        $attachments = new Attachments();
206
        $attachment = $attachments->where('owner', $owner)->first();
0 ignored issues
show
Documentation Bug introduced by
The method where does not exist on object<App\Plugins\Servi...del\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...
207
208
        if ($attachment) {
209
            self::removeAttachment($attachment);
210
        }
211
    }
212
213 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...
214
        $saved = $attachment->saved;
215
        if ($saved == 2) {
216
            $file = $attachment->value;
217
            $path = public_path('uploads' . DIRECTORY_SEPARATOR . 'service-desk' . DIRECTORY_SEPARATOR . 'attachments' . DIRECTORY_SEPARATOR . $file);
218
            unlink($path);
219
        }
220
        $attachment->delete();
221
    }
222
223 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...
224
        $saved = $attachment->saved;
225
        if ($saved == 2) {
226
            $file = $attachment->value;
227
            $attach = public_path('uploads' . DIRECTORY_SEPARATOR . 'service-desk' . DIRECTORY_SEPARATOR . 'attachments' . DIRECTORY_SEPARATOR . $file);
228
        } else {
229
            $attach = $attachment->value;
230
        }
231
        return $attach;
232
    }
233
234 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...
235
        $relations = new AssetRelation();
236
        $owner = "$table:$id";
237
        $relationses = $relations->where('owner', $owner)->get();
0 ignored issues
show
Documentation Bug introduced by
The method where does not exist on object<App\Plugins\Servi...l\Common\AssetRelation>? 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...
238
        if ($relationses->count() > 0) {
239
            foreach ($relationses as $relationse) {
240
                $relationse->delete();
241
            }
242
        }
243
        if (count($asset_ids) > 0) {
244
            if (is_array($asset_ids)) {
245
                $asset_ids = implode(',', $asset_ids);
246
            }
247
248
            $relations->asset_ids = $asset_ids;
0 ignored issues
show
Documentation introduced by
The property asset_ids does not exist on object<App\Plugins\Servi...l\Common\AssetRelation>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
249
            $relations->owner = $owner;
0 ignored issues
show
Documentation introduced by
The property owner does not exist on object<App\Plugins\Servi...l\Common\AssetRelation>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
250
            $relations->save();
251
        }
252
    }
253
254 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...
255
        $relations = new AssetRelation();
256
        $relation = $relations->where('asset_ids', '!=', '')->get();
0 ignored issues
show
Documentation Bug introduced by
The method where does not exist on object<App\Plugins\Servi...l\Common\AssetRelation>? 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...
257
        $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...
258
        //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...
259
        foreach ($relation as $del) {
260
            $array = $del->asset_ids;
261
            $array = array_diff($array, [$id]);
262
            if (count($array) > 0) {
263
                $asset_ids = implode(',', $array);
264
                $del->asset_ids = $asset_ids;
265
                $del->save();
266
            } else {
267
                $del->delete();
268
            }
269
        }
270
    }
271
272 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...
273
        $defaults = array(
274
            'namespaceSeparator' => ':', //you may want this to be something other than a colon
275
            'attributePrefix' => '', //to distinguish between attributes and nodes with the same name
276
            'alwaysArray' => array(), //array of xml tag names which should always become arrays
277
            'autoArray' => true, //only create arrays for tags which appear more than once
278
            'textContent' => 'option-name', //key used for the text content of elements
279
            'autoText' => true, //skip textContent key if node has no attributes or child nodes
280
            'keySearch' => false, //optional search and replace on tag and attribute names
281
            'keyReplace' => false       //replace values for above search values (as passed to str_replace())
282
        );
283
        $options = array_merge($defaults, $options);
284
        $namespaces = $xml->getDocNamespaces();
285
        $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...
286
        //get attributes from all namespaces
287
        $attributesArray = array();
288
        foreach ($namespaces as $prefix => $namespace) {
289
            foreach ($xml->attributes($namespace) as $attributeName => $attribute) {
290
                //replace characters in attribute name
291
                if ($options['keySearch'])
292
                    $attributeName = str_replace($options['keySearch'], $options['keyReplace'], $attributeName);
293
                $attributeKey = $options['attributePrefix']
294
                        . ($prefix ? $prefix . $options['namespaceSeparator'] : '')
295
                        . $attributeName;
296
                $attributesArray[$attributeKey] = (string) $attribute;
297
            }
298
        }
299
300
        //get child nodes from all namespaces
301
        $tagsArray = array();
302
        foreach ($namespaces as $prefix => $namespace) {
303
            foreach ($xml->children($namespace) as $childXml) {
304
                //recurse into child nodes
305
                $childArray = self::xmlToArray($childXml, $options);
306
                list($childTagName, $childProperties) = each($childArray);
307
308
                //replace characters in tag name
309
                if ($options['keySearch'])
310
                    $childTagName = str_replace($options['keySearch'], $options['keyReplace'], $childTagName);
311
                //add namespace prefix, if any
312
                if ($prefix)
313
                    $childTagName = $prefix . $options['namespaceSeparator'] . $childTagName;
314
315
                if (!isset($tagsArray[$childTagName])) {
316
                    //only entry with this key
317
                    //test if tags of this type should always be arrays, no matter the element count
318
                    $tagsArray[$childTagName] = in_array($childTagName, $options['alwaysArray']) || !$options['autoArray'] ? array($childProperties) : $childProperties;
319
                } elseif (
320
                        is_array($tagsArray[$childTagName]) && array_keys($tagsArray[$childTagName]) === range(0, count($tagsArray[$childTagName]) - 1)
321
                ) {
322
                    //key already exists and is integer indexed array
323
                    $tagsArray[$childTagName][] = $childProperties;
324
                } else {
325
                    //key exists so convert to integer indexed array with previous value in position 0
326
                    $tagsArray[$childTagName] = array($tagsArray[$childTagName], $childProperties);
327
                }
328
            }
329
        }
330
331
        //get text content of node
332
        $textContentArray = array();
333
        $plainText = trim((string) $xml);
334
        if ($plainText !== '')
335
            $textContentArray[$options['textContent']] = $plainText;
336
337
        //stick it all together
338
        $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...
339
340
        //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...
341
        return array(
342
            $xml->getName() => $propertiesArray
343
        );
344
    }
345
346 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...
347
        $field = "";
348
        $value = "";
349
        //$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...
350
        if (is_integer($key)) {
351
            $field = "<field ";
352
            foreach ($array as $index => $item) {
353
354
                if (is_array($item)) {
355
                    $value = self::value($item);
356
                    $options = true;
357
                } 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...
358
                    $it = '=' . '"' . $item . '" ';
359
                    $field .= $index . $it;
360
                }
361
            }
362
363
            $field .= ">$value</field>";
364
        }
365
366
        foreach ($array as $key => $value) {
367
            if (is_array($value)) {
368
                $field .= self::arrayToXml($value, $key, $options);
369
            }
370
        }
371
372
        return $field;
373
    }
374
375 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...
376
        $result = "";
377
        foreach ($item as $k => $v) {
378
            $result .= '<option value=' . '"' . $k . '"' . '>' . $v . '</option>';
379
        }
380
        return $result;
381
    }
382
383 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...
384
        $button = "";
385
        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...
386
            $button = '<a href="#delete" class="' . $class . '" data-toggle="modal" data-target="#delete' . $id . '">' . $btn_name . '</a>';
387
        }
388
        return $button . '<div class="modal fade" id="delete' . $id . '">
389
                    <div class="modal-dialog">
390
                        <div class="modal-content">
391
                            <div class="modal-header">
392
                                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
393
                                <h4 class="modal-title">' . $title . '</h4>
394
                            </div>
395
                            <div class="modal-body">
396
                                <div class="row">
397
                                <div class="col-md-12">
398
                                <p>Are you sure ?</p>
399
                                </div>
400
                                </div>
401
                            </div>
402
                            <div class="modal-footer">
403
                                <button type="button" id="close" class="btn btn-default pull-left" data-dismiss="modal">Close</button>
404
                                <a href="' . $url . '" class="btn btn-danger">Delete</a>
405
                            </div>
406
                        </div>
407
                    </div>
408
                </div>';
409
    }
410
411 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...
412
        $authid = Auth::user()->id;
413
        $result = false;
414
        $cabs = new \App\Plugins\ServiceDesk\Model\Cab\Cab();
415
        $cab = $cabs->find($cabid);
0 ignored issues
show
Documentation Bug introduced by
The method find does not exist on object<App\Plugins\ServiceDesk\Model\Cab\Cab>? 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...
416
        if ($cab) {
417
            $members = $cab->approvers;
418
            if (is_array($members)) {
419
                if (in_array($authid, $members)) {
420
                    $result = true;
421
                }
422
            } elseif (is_integer($members)) {
423
                if ($authid == $members) {
424
                    $result = true;
425
                }
426
            } elseif ($cab->head) {
427
                if ($authid == $cab->head) {
428
                    $result = true;
429
                }
430
            }
431
        }
432
        return $result;
433
    }
434
435 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...
436
        $cabs = new \App\Plugins\ServiceDesk\Model\Cab\Cab();
437
        $cab = $cabs->find($cabid);
0 ignored issues
show
Documentation Bug introduced by
The method find does not exist on object<App\Plugins\ServiceDesk\Model\Cab\Cab>? 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...
438
        if ($cab) {
439
            $members = $cab->approvers;
440
            $head = $cab->head;
441
            if (is_array($members)) {
442
                if (count($members) > 0) {
443
                    foreach ($members as $userid) {
444
                        self::sendCabMessage($userid, $head, $activity, $url);
445
                    }
446
                }
447
            }
448
        }
449
    }
450
451 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...
452
        $users = new \App\User();
453
        $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...
454
        $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...
455
        $heads = "";
456
        //dd($url);
457
        if ($user) {
458
            $email = $user->email;
459
            $name = $user->first_name . " " . $user->last_name;
460
            if ($leader) {
461
                $heads = $leader->first_name . " " . $leader->last_name;
462
            }
463
            //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...
464
            $php_mailer = new \App\Http\Controllers\Common\PhpMailController();
465
            $php_mailer->sendmail(
466
                    $from = $php_mailer->mailfrom('1', '0'), $to = ['name' => $name, 'email' => $email], $message = [
467
                'subject' => 'Requesting For CAB Approval',
468
                'scenario' => 'sd-cab-vote',
469
                    ], $template_variables = [
470
                'user' => $name,
471
                'system_link' => $url,
472
                '$system_from' => $heads,
473
                    ]
474
            );
475
        }
476
    }
477
478 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...
479
        $owner = "$table:$modelid";
480
        $request = $requests->except('_token', 'attachment', 'identifier');
481
        // 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...
482
        $general = new GeneralInfo();
483
484
        if (count($request) > 0) {
485
            foreach ($request as $key => $value) {
486
                $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\Plugins\Servi...del\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...
487
                if ($generals) {
488
                    $generals->delete();
489
                }
490
                if ($value !== "") {
491
                    $general->create([
492
                        'owner' => $owner,
493
                        'key' => $key,
494
                        'value' => $value,
495
                    ]);
496
                }
497
            }
498
        }
499
500
        $attachments = $requests->file('attachment');
501
        $identifier = $requests->input('identifier');
502
        $attach_table = "$table:$identifier";
503
        self::attachment($modelid, $attach_table, $attachments);
504
        return "success";
505
    }
506
507 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...
508
        $units = array('B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB');
509
        $power = $size > 0 ? floor(log($size, 1024)) : 0;
510
        $value = number_format($size / pow(1024, $power), 2, '.', ',') . ' ' . $units[$power];
511
        return $value;
512
    }
513
514
}
515