UserController::getExportUser()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 0
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace App\Http\Controllers\Agent\helpdesk;
4
5
// controllers
6
use App\Http\Controllers\Common\PhpMailController;
7
use App\Http\Controllers\Controller;
8
// requests
9
/*  Include Sys_user Model  */
10
use App\Http\Requests\helpdesk\ChangepasswordRequest;
11
/* For validation include Sys_userRequest in create  */
12
use App\Http\Requests\helpdesk\OtpVerifyRequest;
13
/* For validation include Sys_userUpdate in update  */
14
use App\Http\Requests\helpdesk\ProfilePassword;
15
/*  include guest_note model */
16
use App\Http\Requests\helpdesk\ProfileRequest;
17
use App\Http\Requests\helpdesk\Sys_userRequest;
18
// change password request
19
use App\Http\Requests\helpdesk\Sys_userUpdate;
20
// models
21
use App\Model\helpdesk\Agent\Assign_team_agent;
22
use App\Model\helpdesk\Agent_panel\Organization;
23
use App\Model\helpdesk\Agent_panel\User_org;
24
use App\Model\helpdesk\Notification\Notification;
25
use App\Model\helpdesk\Notification\UserNotification;
26
use App\Model\helpdesk\Settings\CommonSettings;
27
use App\Model\helpdesk\Settings\Email;
28
use App\Model\helpdesk\Ticket\Ticket_Thread;
29
use App\Model\helpdesk\Ticket\Tickets;
30
use App\Model\helpdesk\Utility\CountryCode;
31
use App\Model\helpdesk\Utility\Otp;
32
use App\User;
33
// classes
34
use Auth;
35
use Datatables;
36
use DateTime;
37
use DB;
38
use Exception;
39
use GeoIP;
40
use Hash;
41
use Illuminate\Http\Request;
42
use Input;
43
use Lang;
44
use Redirect;
45
46
/**
47
 * UserController
48
 * This controller is used to CRUD an User details, and proile management of an agent.
49
 *
50
 * @author      Ladybird <[email protected]>
51
 */
52
class UserController extends Controller
53
{
54
    /**
55
     * Create a new controller instance.
56
     * constructor to check
57
     * 1. authentication
58
     * 2. user roles
59
     * 3. roles must be agent.
60
     *
61
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
62
     */
63
    public function __construct(PhpMailController $PhpMailController)
64
    {
65
        $this->PhpMailController = $PhpMailController;
0 ignored issues
show
Bug introduced by
The property PhpMailController does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
66
        // checking authentication
67
        $this->middleware('auth');
68
        // checking if role is agent
69
        $this->middleware('role.agent');
70
    }
71
72
    /**
73
     * Display all list of the users.
74
     *
75
     * @param type User $user
76
     *
77
     * @return type view
78
     */
79 View Code Duplication
    public function index()
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...
80
    {
81
        try {
82
            /* get all values in Sys_user */
83
84
            $table = \ Datatable::table()
85
            ->addColumn(Lang::get('lang.name'),
86
                Lang::get('lang.email'),
87
                Lang::get('lang.phone'),
88
                Lang::get('lang.status'),
89
                Lang::get('lang.last_login'),
90
                Lang::get('lang.role'),
91
                Lang::get('lang.action'))  // these are the column headings to be shown
92
                ->noScript();
93
94
            return view('themes.default1.agent.helpdesk.user.index', compact('table'));
95
        } catch (Exception $e) {
96
            return redirect()->back()->with('fails', $e->getMessage());
97
        }
98
    }
99
100
    public function deletedUser()
101
    {
102
        try {
103
            // dd('here');
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...
104
            /* get all values in Sys_user */
105
            return view('themes.default1.agent.helpdesk.user.deleteduser');
106
        } catch (Exception $e) {
107
            return redirect()->back()->with('fails', $e->getMessage());
108
        }
109
    }
110
111
    /**
112
     * This function is used to display the list of users using chumper datatables.
113
     *
114
     * @return datatable
115
     */
116
    public function user_list(Request $request)
117
    {
118
        $type = $request->input('profiletype');
119
        $search = $request->input('searchTerm');
120
121
        if ($type === 'agents') {
122
            $users = User::where('role', '=', 'agent')->where('is_delete', '=', 0);
123
        } elseif ($type === 'users') {
124
            $users = User::where('role', '=', 'user')->where('is_delete', '=', 0);
125
        } elseif ($type === 'active-users') {
126
            $users = User::where('role', '!=', 'admin')->where('active', '=', 1);
127
        } elseif ($type === 'inactive') {
128
            $users = User::where('role', '!=', 'admin')->where('active', '=', 0);
129
        } elseif ($type === 'deleted') {
130
            $users = User::where('role', '!=', 'admin')->where('is_delete', '=', 1);
131
        } elseif ($type === 'banned') {
132
            $users = User::where('role', '!=', 'admin')->where('ban', '=', 1);
133
        } else {
134
            $users = User::where('role', '!=', 'admin')->where('is_delete', '=', 0);
135
        }
136
137
        $users = $users->select('user_name', 'email', 'mobile', 'active', 'updated_at', 'role', 'id', 'last_name', 'country_code', 'phone_number');
138
139
        if ($search !== '') {
140
            $users = $users->where(function ($query) use ($search) {
141
                $query->where('user_name', 'LIKE', '%'.$search.'%');
142
                $query->orWhere('email', 'LIKE', '%'.$search.'%');
143
                $query->orWhere('first_name', 'LIKE', '%'.$search.'%');
144
                $query->orWhere('last_name', 'LIKE', '%'.$search.'%');
145
                $query->orWhere('mobile', 'LIKE', '%'.$search.'%');
146
                $query->orWhere('updated_at', 'LIKE', '%'.$search.'%');
147
                $query->orWhere('country_code', 'LIKE', '%'.$search.'%');
148
            });
149
        }
150
        // displaying list of users with chumper datatables
151
        // return \Datatable::collection(User::where('role', "!=", "admin")->get())
0 ignored issues
show
Unused Code Comprehensibility introduced by
63% 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...
152
       return \Datatables::of($users)
153
                        /* column username */
154
                        ->removeColumn('id', 'last_name', 'country_code', 'phone_number')
155
                        ->addColumn('user_name', function ($model) {
156
                            if ($model->first_name) {
157
                                $string = strip_tags($model->first_name.' '.$model->last_name);
158
                            } else {
159
                                $string = strip_tags($model->user_name);
160
                            }
161
                            if (strlen($string) > 30) {
162
                                // truncate string
163
                                $stringCut = mb_substr($string, 0, 30, 'UTF-8').'...';
164
                            } else {
165
                                $stringCut = $string;
166
                            }
167
168
                            return "<a href='".route('user.show', $model->id)."' title='".$string."''>".$stringCut.'</a>';
169
                        })
170
                        /* column email */
171
                        ->addColumn('email', function ($model) {
172
                            $email = "<a href='".route('user.show', $model->id)."'>".$model->email.'</a>';
173
174
                            return $email;
175
                        })
176
                        /* column phone */
177 View Code Duplication
                        ->addColumn('mobile', function ($model) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
178
                            $phone = '';
179
                            if ($model->phone_number) {
180
                                $phone = $model->ext.' '.$model->phone_number;
181
                            }
182
                            $mobile = '';
183
                            if ($model->mobile) {
184
                                $mobile = $model->mobile;
185
                            }
186
                            $phone = $phone.'&nbsp;&nbsp;&nbsp;'.$mobile;
187
188
                            return $phone;
189
                        })
190
                        /* column account status */
191 View Code Duplication
                        ->addColumn('active', function ($model) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
192
                            $status = $model->active;
193
                            if ($status == 1) {
194
                                $stat = '<button class="btn btn-success btn-xs">Active</button>';
195
                            } else {
196
                                $stat = '<button class="btn btn-danger btn-xs">Inactive</button>';
197
                            }
198
199
                            return $stat;
200
                        })
201
                        /* column last login date */
202
                        ->addColumn('updated_at', function ($model) {
203
                            $t = $model->updated_at;
204
205
                            return TicketController::usertimezone($t);
206
                        })
207
                        /* column Role */
208
                        ->addColumn('role', function ($model) {
209
                            $role = $model->role;
210
211
                            return $role;
212
                        })
213
                        /* column actions */
214
                        ->addColumn('Actions', function ($model) {
215
                            if ($model->is_delete == 0) {
216
                                return '<a href="'.route('user.edit', $model->id).'" class="btn btn-warning btn-xs">'.\Lang::get('lang.edit').'</a>&nbsp; <a href="'.route('user.show', $model->id).'" class="btn btn-primary btn-xs">'.\Lang::get('lang.view').'</a>';
217
                            } else {
218 View Code Duplication
                                if (Auth::user()->role == 'admin') {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
219
                                    // @if(Auth::user()->role == 'admin')
0 ignored issues
show
Unused Code Comprehensibility introduced by
38% 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...
220
221
                           return '<a href="'.route('user.show', $model->id).'" class="btn btn-primary btn-xs">'.\Lang::get('lang.view').'</a>';
222
                                }
223
224 View Code Duplication
                                if (Auth::user()->role == 'agent') {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
225
                                    // @if(Auth::user()->role == 'admin')
0 ignored issues
show
Unused Code Comprehensibility introduced by
38% 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...
226
                             if ($model->role == 'user') {
227
                                 return '<a href="'.route('user.show', $model->id).'" class="btn btn-primary btn-xs">'.\Lang::get('lang.view').'</a>';
228
                             }
229
                                }
230
                            }
231
                        })
232
                        ->make();
233
    }
234
235
    public function restoreUser($id)
236
    {
237
        // dd($id);
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
238
         // $delete_all = Input::get('delete_all');
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...
239
        $users = User::where('id', '=', $id)->first();
240
        $users->is_delete = 0;
241
        $users->active = 1;
242
        $users->ban = 0;
243
        $users->save();
244
245
        return redirect('user')->with('success', Lang::get('lang.user_restore_successfully'));
246
    }
247
248
    /**
249
     * Show the form for creating a new users.
250
     *
251
     * @return type view
252
     */
253
    public function create(CountryCode $code)
254
    {
255
        try {
256
            $settings = CommonSettings::select('status')->where('option_name', '=', 'send_otp')->first();
257
            $email_mandatory = CommonSettings::select('status')->where('option_name', '=', 'email_mandatory')->first();
258
            $location = GeoIP::getLocation();
259
            $phonecode = $code->where('iso', '=', $location->iso_code)->first();
0 ignored issues
show
Documentation Bug introduced by
The method where does not exist on object<App\Model\helpdesk\Utility\CountryCode>? 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...
260
            $org = Organization::lists('name', 'id')->toArray();
261
262
            return view('themes.default1.agent.helpdesk.user.create', compact('org', 'settings', 'email_mandatory'))->with('phonecode', $phonecode->phonecode);
0 ignored issues
show
Bug introduced by
The method with does only exist in Illuminate\View\View, but not in Illuminate\Contracts\View\Factory.

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

Let’s take a look at an example:

class A
{
    public function foo() { }
}

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

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

Available Fixes

  1. Add an additional type-check:

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

    function someFunction(B $x) { /** ... */ }
    
Loading history...
263
        } catch (Exception $e) {
264
            return redirect()->back()->with('fails', $e->errorInfo[2]);
0 ignored issues
show
Bug introduced by
The property errorInfo does not seem to exist in Exception.

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

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

Loading history...
265
        }
266
    }
267
268
    /**
269
     * Store a newly created users in storage.
270
     *
271
     * @param type User            $user
272
     * @param type Sys_userRequest $request
273
     *
274
     * @return type redirect
275
     */
276
    public function store(User $user, Sys_userRequest $request)
277
    {
278
        /* insert the input request to sys_user table */
279
        /* Check whether function success or not */
280 View Code Duplication
        if ($request->input('email') != '') {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
281
            $user->email = $request->input('email');
0 ignored issues
show
Documentation introduced by
The property email does not exist on object<App\User>. 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...
282
        } else {
283
            $user->email = null;
0 ignored issues
show
Documentation introduced by
The property email does not exist on object<App\User>. 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...
284
        }
285
        $user->first_name = $request->input('first_name');
0 ignored issues
show
Documentation introduced by
The property first_name does not exist on object<App\User>. 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...
286
        $user->last_name = $request->input('last_name');
0 ignored issues
show
Documentation introduced by
The property last_name does not exist on object<App\User>. 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...
287
        $user->user_name = $request->input('user_name');
0 ignored issues
show
Documentation introduced by
The property user_name does not exist on object<App\User>. 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...
288 View Code Duplication
        if ($request->input('mobile') != '') {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
289
            $user->mobile = $request->input('mobile');
0 ignored issues
show
Documentation introduced by
The property mobile does not exist on object<App\User>. 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...
290
        } else {
291
            $user->mobile = null;
0 ignored issues
show
Documentation introduced by
The property mobile does not exist on object<App\User>. 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...
292
        }
293
        $user->ext = $request->input('ext');
0 ignored issues
show
Documentation introduced by
The property ext does not exist on object<App\User>. 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...
294
        $user->phone_number = $request->input('phone_number');
0 ignored issues
show
Documentation introduced by
The property phone_number does not exist on object<App\User>. 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...
295
        $user->country_code = $request->input('country_code');
0 ignored issues
show
Documentation introduced by
The property country_code does not exist on object<App\User>. 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...
296
        $user->active = $request->input('active');
0 ignored issues
show
Documentation introduced by
The property active does not exist on object<App\User>. 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...
297
        $user->internal_note = $request->input('internal_note');
0 ignored issues
show
Documentation introduced by
The property internal_note does not exist on object<App\User>. 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...
298
        $password = $this->generateRandomString();
299
        $user->password = Hash::make($password);
0 ignored issues
show
Documentation introduced by
The property password does not exist on object<App\User>. 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...
300
        $user->role = 'user';
0 ignored issues
show
Documentation introduced by
The property role does not exist on object<App\User>. 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...
301
        try {
302
            if ($request->get('country_code') == '' && ($request->get('phone_number') != '' || $request->get('mobile') != '')) {
303
                return redirect()->back()->with(['fails' => Lang::get('lang.country-code-required-error'), 'country_code_error' => 1])->withInput();
304
            } else {
305
                $code = CountryCode::select('phonecode')->where('phonecode', '=', $request->get('country_code'))->get();
306
                if (!count($code)) {
307
                    return redirect()->back()->with(['fails' => Lang::get('lang.incorrect-country-code-error'), 'country_code_error' => 1])->withInput();
308
                }
309
            }
310
            // save user credentails
311
            if ($user->save() == 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...
312
                if ($request->input('org_id') != '') {
313
                    $orgid = $request->input('org_id');
314
                    $this->storeUserOrgRelation($user->id, $orgid);
0 ignored issues
show
Documentation introduced by
The property id does not exist on object<App\User>. Since you implemented __get, maybe consider adding a @property annotation.

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

<?php

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

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

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

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

}

If the property has read access only, you can use the @property-read annotation instead.

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

See also the PhpDoc documentation for @property.

Loading history...
315
                }
316
                // fetch user credentails to send mail
317
                $name = $user->first_name;
0 ignored issues
show
Documentation introduced by
The property first_name does not exist on object<App\User>. 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...
318
                $email = $user->email;
0 ignored issues
show
Documentation introduced by
The property email does not exist on object<App\User>. 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...
319 View Code Duplication
                if ($request->input('send_email')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
320
                    try {
321
                        // send mail on registration
322
                        $this->PhpMailController->sendmail($from = $this->PhpMailController->mailfrom('1', '0'), $to = ['name' => $name, 'email' => $email], $message = ['subject' => null, 'scenario' => 'registration-notification'], $template_variables = ['user' => $name, 'email_address' => $email, 'user_password' => $password]);
323
                    } catch (Exception $e) {
324
                        // returns if try fails
325
                        return redirect('user')->with('warning', Lang::get('lang.user_send_mail_error_on_user_creation'));
326
                    }
327
                }
328
                // returns for the success case
329
                // returns for the success case
330
                $email_mandatory = CommonSettings::select('status')->where('option_name', '=', 'email_mandatory')->first();
331
                if (($request->input('active') == '0' || $request->input('active') == 0) || ($email_mandatory->status == '0') || $email_mandatory->status == 0) {
332
                    \Event::fire(new \App\Events\LoginEvent($request));
333
                }
334
335
                return redirect('user')->with('success', Lang::get('lang.User-Created-Successfully'));
336
            }
337
//            $user->save();
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...
338
            /* redirect to Index page with Success Message */
339
            return redirect('user')->with('success', Lang::get('lang.User-Created-Successfully'));
340
        } catch (Exception $e) {
341
            /* redirect to Index page with Fails Message */
342
            return redirect('user')->with('fails', $e->getMessage());
343
        }
344
    }
345
346
    /**
347
     * Random Password Genetor for users.
348
     *
349
     * @param type int  $id
350
     * @param type User $user
351
     *
352
     * @return type view
353
     */
354
    public function randomPassword()
355
    {
356
        try {
357
            $alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890~!@#$%^&*(){}[]';
358
            $pass = []; //remember to declare $pass as an array
359
            $alphaLength = strlen($alphabet) - 1; //put the length -1 in cache
360
            for ($i = 0; $i < 10; $i++) {
361
                $n = rand(0, $alphaLength);
362
                $pass[] = $alphabet[$n];
363
            }
364
365
            return implode($pass);
366
        } catch (Exception $e) {
367
            /* redirect to Index page with Fails Message */
368
            return redirect('user')->with('fails', $e->getMessage());
369
        }
370
    }
371
372
    /**
373
     * Random Password Genetor for users.
374
     *
375
     * @param type int  $id
376
     * @param type User $user
377
     *
378
     * @return type view
379
     */
380
    public function randomPostPassword($id, ChangepasswordRequest $request)
381
    {
382
        try {
383
            $changepassword = $request->change_password;
0 ignored issues
show
Bug introduced by
The property change_password does not seem to exist in App\Http\Requests\helpdesk\ChangepasswordRequest.

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

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

Loading history...
Unused Code introduced by
$changepassword 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...
384
            $user = User::whereId($id)->first();
385
            $password = $request->change_password;
386
            $user->password = Hash::make($password);
387
            $user->save();
388
            $name = $user->first_name;
389
            $email = $user->email;
390
391
            $this->PhpMailController->sendmail($from = $this->PhpMailController
392
                    ->mailfrom('1', '0'), $to = ['name' => $name, 'email' => $email], $message = ['subject' => null, 'scenario' => 'reset_new_password'], $template_variables = ['user' => $name, 'user_password' => $password]);
393
394
            return redirect('user')->with('success', Lang::get('lang.password_change_successfully'));
395
        } catch (Exception $e) {
396
            return redirect('user')->with('fails', $e->getMessage());
397
        }
398
    }
399
400
    /**
401
     * @param type    $id
402
     * @param Request $request
403
     *
404
     * @return type
405
     */
406 View Code Duplication
    public function changeRoleAdmin($id, Request $request)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
407
    {
408
        try {
409
            $user = User::whereId($id)->first();
410
            $user->role = 'admin';
411
            $user->assign_group = $request->group;
412
            $user->primary_dpt = $request->primary_department;
413
            $user->save();
414
415
            return redirect('user')->with('success', Lang::get('lang.role_change_successfully'));
416
        } catch (Exception $e) {
417
            /* redirect to Index page with Fails Message */
418
            return redirect('user')->with('fails', $e->getMessage());
419
        }
420
    }
421
422
    /**
423
     * @param type    $id
424
     * @param Request $request
425
     *
426
     * @return type
427
     */
428 View Code Duplication
    public function changeRoleAgent($id, Request $request)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
429
    {
430
        try {
431
            $user = User::whereId($id)->first();
432
            $user->role = 'agent';
433
            $user->assign_group = $request->group;
434
            $user->primary_dpt = $request->primary_department;
435
            $user->save();
436
437
            return redirect('user')->with('success', Lang::get('lang.role_change_successfully'));
438
        } catch (Exception $e) {
439
            /* redirect to Index page with Fails Message */
440
            return redirect('user')->with('fails', $e->getMessage());
441
        }
442
    }
443
444
    /**
445
     * @param type $id
446
     *
447
     * @return type
448
     */
449
    public function changeRoleUser($id)
450
    {
451
        try {
452
            $ticket = Tickets::where('assigned_to', '=', $id)->where('status', '=', '1')->get();
453
            if ($ticket) {
454
                $ticket = Tickets::where('assigned_to', '=', $id)->update(['assigned_to' => null]);
0 ignored issues
show
Unused Code introduced by
$ticket 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...
455
            }
456
            $user = User::whereId($id)->first();
457
            $user->role = 'user';
458
            $user->assign_group = null;
459
            $user->primary_dpt = null;
460
            $user->remember_token = null;
461
            $user->save();
462
463
            return redirect('user')->with('success', Lang::get('lang.role_change_successfully'));
464
        } catch (Exception $e) {
465
            /* redirect to Index page with Fails Message */
466
            return redirect('user')->with('fails', $e->getMessage());
467
        }
468
        // return 'Agent Role Successfully Change to User';
469
    }
470
471
    /**
472
     * @param type $id
473
     *
474
     * @return type
475
     */
476
    public function deleteAgent($id)
477
    {
478
        // try {
479
        $delete_all = Input::get('delete_all');
0 ignored issues
show
Unused Code introduced by
$delete_all 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...
480
481
        $delete_all = Input::get('delete_all');
482
        $users = User::where('id', '=', $id)->first();
483
        if ($users->role == 'user') {
484
            $users = User::where('id', '=', $id)->first();
485
            $users->is_delete = 1;
486
            $users->active = 0;
487
            $users->ban = 1;
488
            $users->save();
489
490
            return redirect('user')->with('success', Lang::get('lang.user_delete_successfully'));
491
        }
492
        // }
493
494
        if ($users->role == 'agent') {
495
            if ($delete_all == null) {
496
                $UserEmail = Input::get('assign_to');
497
                $assign_to = explode('_', $UserEmail);
498
                $ticket = Tickets::where('assigned_to', '=', $id)->get();
499
                if ($assign_to[0] == 'user') {
500
                    if ($users->id == $assign_to[1]) {
501
                        return redirect('user')->with('warning', Lang::get('lang.select_another_agent'));
502
                    }
503
                    // $user_detail = User::where('id', '=', $assign_to[1])->first();
0 ignored issues
show
Unused Code Comprehensibility introduced by
64% 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...
504
                    // $assignee = $user_detail->first_name.' '.$user_detail->last_name;
0 ignored issues
show
Unused Code Comprehensibility introduced by
47% 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...
505
                    // $ticket_logic1 = Tickets::where('assigned_to', '=', $id)
0 ignored issues
show
Unused Code Comprehensibility introduced by
53% 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...
506
                    //             ->update(['assigned_to' => $assign_to[1]]);
0 ignored issues
show
Unused Code Comprehensibility introduced by
75% 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...
507
                    // if ($ticket_logic2 = Tickets::where('user_id', '=', $id)->get()) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% 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...
508
                    //     $ticket_logic2 = Tickets::where('user_id', '=', $id)->update(['user_id' => $assign_to[1]]);
0 ignored issues
show
Unused Code Comprehensibility introduced by
66% 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...
509
                    // }
510
                    // if ($ticket_logic3 = Ticket_Thread::where('user_id', '=', $id)->get()) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% 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...
511
                    //     $ticket_logic3 = Ticket_Thread::where('user_id', '=', $id)->update(['user_id' => $assign_to[1]]);
0 ignored issues
show
Unused Code Comprehensibility introduced by
66% 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...
512
                    // }
513
                    // if ($ticket_logic4 = User_org::where('user_id', '=', $id)->get()) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% 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...
514
                    //     $ticket_logic4 = User_org::where('user_id', '=', $id)->update(['user_id' => $assign_to[1]]);
0 ignored issues
show
Unused Code Comprehensibility introduced by
66% 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...
515
                    // }
516
517
                        // $thread2 = Ticket_Thread::where('ticket_id', '=', $ticket->id)->first();
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% 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...
518
                        // $thread2->body = 'This Ticket have been Reassigned to' .' '.  $assignee;
0 ignored issues
show
Unused Code Comprehensibility introduced by
40% 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...
519
                        // $thread2->save();
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...
520
                        // UserNotification::where('notification_id', '=', $ticket->id)->delete();
0 ignored issues
show
Unused Code Comprehensibility introduced by
65% 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...
521
                        // $users = User::where('id', '=', $id)->get();
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% 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...
522
                        // $organization = User_org::where('user_id', '=', $id)->delete();
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% 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...
523
                        // Assign_team_agent::where('agent_id', '=', $id)->update(['agent_id' => $assign_to[1]]);
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...
524
           $tickets = Tickets::where('assigned_to', '=', $id)->get();
525
526
                    foreach ($tickets as $ticket) {
527
                        // code...
528
529
            $ticket->assigned_to = $assign_to[1];
530
                        $user_detail = User::where('id', '=', $assign_to[1])->first();
531
                        $assignee = $user_detail->first_name.' '.$user_detail->last_name;
532
                        $ticket_number = $ticket->ticket_number;
0 ignored issues
show
Unused Code introduced by
$ticket_number 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...
533
                        $ticket->save();
534
535
                        $thread = new Ticket_Thread();
536
                        $thread->ticket_id = $ticket->id;
0 ignored issues
show
Documentation introduced by
The property ticket_id does not exist on object<App\Model\helpdesk\Ticket\Ticket_Thread>. 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...
537
                        $thread->user_id = Auth::user()->id;
0 ignored issues
show
Documentation introduced by
The property user_id does not exist on object<App\Model\helpdesk\Ticket\Ticket_Thread>. 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...
538
                        $thread->is_internal = 1;
0 ignored issues
show
Documentation introduced by
The property is_internal does not exist on object<App\Model\helpdesk\Ticket\Ticket_Thread>. 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...
539
                        $thread->body = 'This Ticket has been assigned to '.$assignee;
0 ignored issues
show
Documentation introduced by
The property body does not exist on object<App\Model\helpdesk\Ticket\Ticket_Thread>. 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...
540
                        $thread->save();
541
                    }
542
                    $user = User::find($id);
0 ignored issues
show
Unused Code introduced by
$user 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...
543
                    $users->is_delete = 1;
544
                    $users->active = 0;
545
                    $users->ban = 1;
546
                    $users->save();
547
548
                    return redirect('user')->with('success', Lang::get('lang.agent_delete_successfully_and_ticket_assign_to_another_agent'));
549
                }
550
551
                // if (User_org::where('user_id', '=', $id)) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
64% 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...
552
                //     DB::table('user_assign_organization')->where('user_id', '=', $id)->delete();
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% 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...
553
                // }
554
                $user = User::find($id);
0 ignored issues
show
Unused Code introduced by
$user 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...
555
                $users->is_delete = 1;
556
                $users->active = 0;
557
                $users->ban = 1;
558
                $users->save();
559
560
                return redirect('user')->with('success', Lang::get('lang.agent_delete_successfully'));
561
            } elseif ($delete_all == 1) {
562
                if ($delete_all) {
563
                    // dd('here');
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...
564
              $tickets = Tickets::where('assigned_to', '=', $id)->get();
565
              // dd($tickets);
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...
566
             foreach ($tickets as $ticket) {
567
                 $ticket->assigned_to = null;
568
                 $ticket_number = $ticket->ticket_number;
0 ignored issues
show
Unused Code introduced by
$ticket_number 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...
569
                 $ticket->save();
570
571
                 $thread = new Ticket_Thread();
572
                 $thread->ticket_id = $ticket->id;
0 ignored issues
show
Documentation introduced by
The property ticket_id does not exist on object<App\Model\helpdesk\Ticket\Ticket_Thread>. 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...
573
                 $thread->user_id = Auth::user()->id;
0 ignored issues
show
Documentation introduced by
The property user_id does not exist on object<App\Model\helpdesk\Ticket\Ticket_Thread>. 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...
574
                 $thread->is_internal = 1;
0 ignored issues
show
Documentation introduced by
The property is_internal does not exist on object<App\Model\helpdesk\Ticket\Ticket_Thread>. 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...
575
                 $thread->body = 'This Ticket has been unassigned ';
0 ignored issues
show
Documentation introduced by
The property body does not exist on object<App\Model\helpdesk\Ticket\Ticket_Thread>. 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...
576
                 $thread->save();
577
             }
578
                    // $users = User::where('id', '=', $id)->get();
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% 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...
579
                    $user = User::find($id);
0 ignored issues
show
Unused Code introduced by
$user 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...
580
                    $users->is_delete = 1;
581
                    $users->active = 0;
582
                    $users->save();
583
584
                    return redirect('user')->with('success', Lang::get('lang.agent_delete_successfully'));
585
                } else {
586
                    // Assign_team_agent::where('agent_id', '=', $id)->delete();
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...
587
                    // User_org::where('user_id', '=', $id)->delete();
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...
588
                    $user = User::find($id);
0 ignored issues
show
Unused Code introduced by
$user 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...
589
                    $users->is_delete = 1;
590
                    $users->active = 0;
591
                    $users->save();
592
593
                    return redirect('user')->with('success', Lang::get('lang.agent_delete_successfully'));
594
                }
595
            } else {
0 ignored issues
show
Unused Code introduced by
This else statement is empty and can be removed.

This check looks for the else branches of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These else branches can be removed.

if (rand(1, 6) > 3) {
print "Check failed";
} else {
    //print "Check succeeded";
}

could be turned into

if (rand(1, 6) > 3) {
    print "Check failed";
}

This is much more concise to read.

Loading history...
596
            }
597
        }
598
        // } catch (Exception $e) {
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...
599
            /* redirect to Index page with Fails Message */
600
            // return redirect('user')->with('fails', $e->getMessage());
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% 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...
601
        // }
602
    }
603
604
    /**
605
     * Display the specified users.
606
     *
607
     * @param type int  $id
608
     * @param type User $user
609
     *
610
     * @return type view
611
     */
612
    public function show($id)
613
    {
614
        try {
615
            $users = User::where('id', '=', $id)->first();
616
            if (count($users) > 0) {
617
                return view('themes.default1.agent.helpdesk.user.show', compact('users'));
618
            } else {
619
                return redirect()->back()->with('fails', Lang::get('lang.user-not-found'));
620
            }
621
        } catch (Exception $e) {
622
            return redirect()->back()->with('fails', $e->getMessage());
623
        }
624
    }
625
626
    /**
627
     * Show the form for editing the specified resource.
628
     *
629
     * @param type int  $id
630
     * @param type User $user
631
     *
632
     * @return type Response
633
     */
634
    public function edit($id, CountryCode $code)
635
    {
636
        try {
637
638
            // dd('here');
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...
639
            $settings = CommonSettings::select('status')->where('option_name', '=', 'send_otp')->first();
0 ignored issues
show
Unused Code introduced by
$settings 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...
640
            $email_mandatory = CommonSettings::select('status')->where('option_name', '=', 'email_mandatory')->first();
0 ignored issues
show
Unused Code introduced by
$email_mandatory 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...
641
642
            $user = new User();
643
            /* select the field where id = $id(request Id) */
644
            $users = $user->whereId($id)->first();
0 ignored issues
show
Documentation Bug introduced by
The method whereId 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...
645
            $location = GeoIP::getLocation();
646
            $phonecode = $code->where('iso', '=', $location->iso_code)->first();
0 ignored issues
show
Documentation Bug introduced by
The method where does not exist on object<App\Model\helpdesk\Utility\CountryCode>? 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...
647
            $orgs = Organization::all();
648
            // dd($org);
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...
649
            $organization_id = User_org::where('user_id', '=', $id)->lists('org_id')->first();
650
651
            // $org_name=Organization::where('id','=',$org_id)->lists('name')->first();
0 ignored issues
show
Unused Code Comprehensibility introduced by
74% 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...
652
            // dd($org_name);
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...
653
654
            return view('themes.default1.agent.helpdesk.user.edit', compact('users', 'orgs', '$settings', '$email_mandatory', 'organization_id'))->with('phonecode', $phonecode->phonecode);
0 ignored issues
show
Bug introduced by
The method with does only exist in Illuminate\View\View, but not in Illuminate\Contracts\View\Factory.

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

Let’s take a look at an example:

class A
{
    public function foo() { }
}

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

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

Available Fixes

  1. Add an additional type-check:

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

    function someFunction(B $x) { /** ... */ }
    
Loading history...
655
        } catch (Exception $e) {
656
            return redirect()->back()->with('fails', $e->getMessage());
657
        }
658
    }
659
660
    /**
661
     * Update the specified user in storage.
662
     *
663
     * @param type int            $id
664
     * @param type User           $user
665
     * @param type Sys_userUpdate $request
666
     *
667
     * @return type Response
668
     */
669
    public function update($id, Sys_userUpdate $request)
670
    {
671
        $user = new User();
672
        /* select the field where id = $id(request Id) */
673
        $users = $user->whereId($id)->first();
0 ignored issues
show
Documentation Bug introduced by
The method whereId 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...
674
        /* Update the value by selected field  */
675
        /* Check whether function success or not */
676
        try {
677 View Code Duplication
            if ($request->get('country_code') == '' && ($request->get('phone_number') != '' || $request->get('mobile') != '')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
678
                return redirect()->back()->with(['fails' => Lang::get('lang.country-code-required-error'), 'country_code_error' => 1])->withInput();
679
            } else {
680
                $code = CountryCode::select('phonecode')->where('phonecode', '=', $request->get('country_code'))->get();
681
                if (!count($code)) {
682
                    return redirect()->back()->with(['fails' => Lang::get('lang.incorrect-country-code-error'), 'country_code_error' => 1])->withInput();
683
                } else {
684
                    $users->country_code = $request->country_code;
0 ignored issues
show
Bug introduced by
The property country_code does not seem to exist in App\Http\Requests\helpdesk\Sys_userUpdate.

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

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

Loading history...
685
                }
686
            }
687
            $users->mobile = ($request->input('mobile') == '') ? null : $request->input('mobile');
688
            $users->fill($request->except('mobile'));
689
            $users->save();
690
            if ($request->input('org_id') != '') {
691
                $orgid = $request->input('org_id');
692
693
                $this->storeUserOrgRelation($id, $orgid);
694
            }
695
            /* redirect to Index page with Success Message */
696
            return redirect('user')->with('success', Lang::get('lang.User-profile-Updated-Successfully'));
697
        } catch (Exception $e) {
698
            /* redirect to Index page with Fails Message */
699
            return redirect()->back()->with('fails', $e->getMessage());
700
        }
701
    }
702
703
    /**
704
     * get agent profile page.
705
     *
706
     * @return type view
707
     */
708 View Code Duplication
    public function getProfile()
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...
709
    {
710
        $user = Auth::user();
711
        try {
712
            return view('themes.default1.agent.helpdesk.user.profile', compact('user'));
713
        } catch (Exception $e) {
714
            return redirect()->back()->with('fails', $e->getMessage());
715
        }
716
    }
717
718
    /**
719
     * get profile edit page.
720
     *
721
     * @return type view
722
     */
723
    public function getProfileedit(CountryCode $code)
724
    {
725
        $user = Auth::user();
726
        $location = GeoIP::getLocation();
727
        $phonecode = $code->where('iso', '=', $location->iso_code)->first();
0 ignored issues
show
Documentation Bug introduced by
The method where does not exist on object<App\Model\helpdesk\Utility\CountryCode>? 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...
728
        $settings = CommonSettings::select('status')->where('option_name', '=', 'send_otp')->first();
729
        $status = $settings->status;
730
        try {
731
            return view('themes.default1.agent.helpdesk.user.profile-edit', compact('user'))
0 ignored issues
show
Bug introduced by
The method with does only exist in Illuminate\View\View, but not in Illuminate\Contracts\View\Factory.

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

Let’s take a look at an example:

class A
{
    public function foo() { }
}

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

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

Available Fixes

  1. Add an additional type-check:

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

    function someFunction(B $x) { /** ... */ }
    
Loading history...
732
                            ->with(['phonecode' => $phonecode->phonecode,
733
                                'verify'        => $status, ]);
734
        } catch (Exception $e) {
735
            return redirect()->back()->with('fails', $e->getMessage());
736
        }
737
    }
738
739
    /**
740
     * post profile edit.
741
     *
742
     * @param type int            $id
743
     * @param type ProfileRequest $request
744
     *
745
     * @return type Redirect
746
     */
747
    public function postProfileedit(ProfileRequest $request)
748
    {
749
        try {
750
            // geet authenticated user details
751
            $user = Auth::user();
752 View Code Duplication
            if ($request->get('country_code') == '' && ($request->get('phone_number') != '' || $request->get('mobile') != '')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
753
                return redirect()->back()->with(['fails' => Lang::get('lang.country-code-required-error'), 'country_code_error' => 1])->withInput();
754
            } else {
755
                $code = CountryCode::select('phonecode')->where('phonecode', '=', $request->get('country_code'))->get();
756
                if (!count($code)) {
757
                    return redirect()->back()->with(['fails' => Lang::get('lang.incorrect-country-code-error'), 'country_code_error' => 1])->withInput();
758
                }
759
                $user->country_code = $request->country_code;
0 ignored issues
show
Bug introduced by
The property country_code does not seem to exist in App\Http\Requests\helpdesk\ProfileRequest.

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

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

Loading history...
760
            }
761
            $user->fill($request->except('profile_pic', 'mobile'));
762
            $user->gender = $request->input('gender');
763
            $user->save();
764
            if (Input::file('profile_pic')) {
765
                // fetching picture name
766
                $name = Input::file('profile_pic')->getClientOriginalName();
767
            // fetching upload destination path
768
                $destinationPath = 'uploads/profilepic';
769
            // adding a random value to profile picture filename
770
                $fileName = rand(0000, 9999).'.'.$name;
771
            // moving the picture to a destination folder
772
                Input::file('profile_pic')->move($destinationPath, $fileName);
773
            // saving filename to database
774
                $user->profile_pic = $fileName;
775
            }
776
            if ($request->get('mobile')) {
777
                $user->mobile = $request->get('mobile');
778
            } else {
779
                $user->mobile = null;
780
            }
781
            if ($user->save()) {
782
                return Redirect::route('profile')->with('success', Lang::get('lang.Profile-Updated-sucessfully'));
783
            } else {
784
                return Redirect::route('profile')->with('fails', Lang::get('lang.Profile-Updated-sucessfully'));
785
            }
786
        } catch (Exception $e) {
787
            return Redirect::route('profile')->with('fails', $e->getMessage());
788
        }
789
    }
790
791
    /**
792
     * Post profile password.
793
     *
794
     * @param type int             $id
795
     * @param type ProfilePassword $request
796
     *
797
     * @return type Redirect
798
     */
799
    public function postProfilePassword($id, ProfilePassword $request)
0 ignored issues
show
Unused Code introduced by
The parameter $id 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...
800
    {
801
        // get authenticated user
802
        $user = Auth::user();
803
        // checking if the old password matches the new password
804
        if (Hash::check($request->input('old_password'), $user->getAuthPassword())) {
805
            $user->password = Hash::make($request->input('new_password'));
806
            try {
807
                $user->save();
808
809
                return redirect('profile-edit')->with('success1', Lang::get('lang.password_updated_sucessfully'));
810
            } catch (Exception $e) {
811
                return redirect('profile-edit')->with('fails', $e->getMessage());
812
            }
813
        } else {
814
            return redirect('profile-edit')->with('fails1', Lang::get('lang.password_was_not_updated_incorrect_old_password'));
815
        }
816
    }
817
818
    /**
819
     * Assigning an user to an organization.
820
     *
821
     * @param type $id
822
     *
823
     * @return type boolean
824
     */
825
    public function UserAssignOrg($id)
826
    {
827
        $org_name = Input::get('org');
828
829
        if ($org_name) {
830
            $org = Organization::where('name', '=', $org_name)->lists('id')->first();
831
            if ($org) {
832
                $user_org = new User_org();
833
                $user_org->org_id = $org;
0 ignored issues
show
Documentation introduced by
The property org_id does not exist on object<App\Model\helpdesk\Agent_panel\User_org>. 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...
834
                $user_org->user_id = $id;
0 ignored issues
show
Documentation introduced by
The property user_id does not exist on object<App\Model\helpdesk\Agent_panel\User_org>. 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...
835
                $user_org->save();
836
837
                return 1;
838
            } else {
839
                return 0;
840
            }
841
        } else {
842
            return 2;
843
        }
844
    }
845
846 View Code Duplication
    public function UsereditAssignOrg($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...
847
    {
848
        $org_name = Input::get('org');
849
850
        if ($org_name) {
851
            $org = Organization::where('name', '=', $org_name)->lists('id')->first();
852
            if ($org) {
853
                $user_org = User_org::where('user_id', '=', $id)->first();
854
                $user_org->org_id = $org;
855
                $user_org->user_id = $id;
856
                $user_org->save();
857
858
                return 1;
859
            } else {
860
                return 0;
861
            }
862
        } else {
863
            return 2;
864
        }
865
    }
866
867 View Code Duplication
    public function orgAssignUser($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...
868
    {
869
        $org = Input::get('org');
870
        $user_org = new User_org();
871
        $user_org->org_id = $id;
0 ignored issues
show
Documentation introduced by
The property org_id does not exist on object<App\Model\helpdesk\Agent_panel\User_org>. 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...
872
        $user_org->user_id = $org;
0 ignored issues
show
Documentation introduced by
The property user_id does not exist on object<App\Model\helpdesk\Agent_panel\User_org>. 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...
873
        $user_org->save();
874
875
        return 1;
876
    }
877
878
    public function removeUserOrg($id)
879
    {
880
        $user_org = User_org::where('org_id', '=', $id)->first();
881
        $user_org->delete();
882
883
        return redirect()->back()->with('success1', Lang::get('lang.the_user_has_been_removed_from_this_organization'));
884
    }
885
886
    /**
887
     * creating an organization in user profile page via modal popup.
888
     *
889
     * @param type $id
890
     *
891
     * @return type
892
     */
893 View Code Duplication
    public function User_Create_Org($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...
894
    {
895
        // checking if the entered value for website is available in database
896
        if (Input::get('website') != null) {
897
            // checking website
898
            $check = Organization::where('website', '=', Input::get('website'))->first();
899
        } else {
900
            $check = null;
901
        }
902
        // checking if the name is unique
903
        $check2 = Organization::where('name', '=', Input::get('name'))->first();
904
        // if any of the fields is not available then return false
905
        if (\Input::get('name') == null) {
906
            return 'Name is required';
907
        } elseif ($check2 != null) {
908
            return 'Name should be Unique';
909
        } elseif ($check != null) {
910
            return 'Website should be Unique';
911
        } else {
912
            // storing organization details and assigning the current user to that organization
913
            $org = new Organization();
914
            $org->name = Input::get('name');
0 ignored issues
show
Documentation introduced by
The property name does not exist on object<App\Model\helpdes...ent_panel\Organization>. 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...
915
            $org->phone = Input::get('phone');
0 ignored issues
show
Documentation introduced by
The property phone does not exist on object<App\Model\helpdes...ent_panel\Organization>. 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...
916
            $org->website = Input::get('website');
0 ignored issues
show
Documentation introduced by
The property website does not exist on object<App\Model\helpdes...ent_panel\Organization>. 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...
917
            $org->address = Input::get('address');
0 ignored issues
show
Documentation introduced by
The property address does not exist on object<App\Model\helpdes...ent_panel\Organization>. 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...
918
            $org->internal_notes = Input::get('internal');
0 ignored issues
show
Documentation introduced by
The property internal_notes does not exist on object<App\Model\helpdes...ent_panel\Organization>. 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...
919
            $org->save();
920
921
            $user_org = new User_org();
922
            $user_org->org_id = $org->id;
0 ignored issues
show
Documentation introduced by
The property org_id does not exist on object<App\Model\helpdesk\Agent_panel\User_org>. 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...
Documentation introduced by
The property id does not exist on object<App\Model\helpdes...ent_panel\Organization>. 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...
923
            $user_org->user_id = $id;
0 ignored issues
show
Documentation introduced by
The property user_id does not exist on object<App\Model\helpdesk\Agent_panel\User_org>. 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...
924
            $user_org->save();
925
            // for success return 0
0 ignored issues
show
Unused Code Comprehensibility introduced by
38% 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...
926
            return 0;
927
        }
928
    }
929
930
    /**
931
     * Generate a random string for password.
932
     *
933
     * @param type $length
934
     *
935
     * @return string
936
     */
937 View Code Duplication
    public function generateRandomString($length = 10)
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...
938
    {
939
        // list of supported characters
940
        $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
941
        // character length checked
942
        $charactersLength = strlen($characters);
943
        // creating an empty variable for random string
944
        $randomString = '';
945
        // fetching random string
946
        for ($i = 0; $i < $length; $i++) {
947
            $randomString .= $characters[rand(0, $charactersLength - 1)];
948
        }
949
        // return random string
950
        return $randomString;
951
    }
952
953
    public function storeUserOrgRelation($userid, $orgid)
954
    {
955
        $org_relations = new User_org();
956
        $org_relation = $org_relations->where('user_id', $userid)->first();
0 ignored issues
show
Documentation Bug introduced by
The method where does not exist on object<App\Model\helpdesk\Agent_panel\User_org>? 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...
957
        if ($org_relation) {
958
            $org_relation->delete();
959
        }
960
        $org_relations->create([
961
            'user_id' => $userid,
962
            'org_id'  => $orgid,
963
        ]);
964
    }
965
966
    public function getExportUser()
967
    {
968
        try {
969
            return view('themes.default1.agent.helpdesk.user.export');
970
        } catch (Exception $ex) {
971
            return redirect()->back()->with('fails', $ex->getMessage());
972
        }
973
    }
974
975 View Code Duplication
    public function exportUser(Request $request)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
976
    {
977
        try {
978
            $date = $request->input('date');
979
            $date = str_replace(' ', '', $date);
980
            $date_array = explode(':', $date);
981
            $first = $date_array[0].' 00:00:00';
982
            $second = $date_array[1].' 23:59:59';
983
            $first_date = $this->convertDate($first);
984
            $second_date = $this->convertDate($second);
985
            $users = $this->getUsers($first_date, $second_date);
986
            $excel_controller = new \App\Http\Controllers\Common\ExcelController();
987
            $filename = 'users'.$date;
988
            $excel_controller->export($filename, $users);
989
        } catch (Exception $ex) {
990
            return redirect()->back()->with('fails', $ex->getMessage());
991
        }
992
    }
993
994
    public function convertDate($date)
995
    {
996
        $converted_date = date('Y-m-d H:i:s', strtotime($date));
997
998
        return $converted_date;
999
    }
1000
1001
    public function getUsers($first, $last)
1002
    {
1003
        $user = new User();
1004
        $users = $user->leftJoin('user_assign_organization', 'users.id', '=', 'user_assign_organization.user_id')
0 ignored issues
show
Documentation Bug introduced by
The method leftJoin 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...
1005
                ->leftJoin('organization', 'user_assign_organization.org_id', '=', 'organization.id')
1006
                ->whereBetween('users.created_at', [$first, $last])
1007
                ->where('role', 'user')
1008
                ->where('active', 1)
1009
                ->select('users.user_name as Username', 'users.email as Email', 'users.first_name as Fisrtname', 'users.last_name as Lastname', 'organization.name as Organization')
1010
                ->get()
1011
                ->toArray();
1012
1013
        return $users;
1014
    }
1015
1016 View Code Duplication
    public function resendOTP(OtpVerifyRequest $request)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1017
    {
1018
        if (\Schema::hasTable('sms')) {
1019
            $sms = DB::table('sms')->get();
1020
            if (count($sms) > 0) {
1021
                \Event::fire(new \App\Events\LoginEvent($request));
1022
1023
                return 1;
1024
            }
1025
        } else {
1026
            return 'Plugin has not been setup successfully.';
1027
        }
1028
    }
1029
1030 View Code Duplication
    public function verifyOTP()
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...
1031
    {
1032
        // dd(Input::all());
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% 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...
1033
        // $user = User::select('id', 'mobile', 'user_name')->where('email', '=', $request->input('email'))->first();
0 ignored issues
show
Unused Code Comprehensibility introduced by
66% 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...
1034
        $otp = Otp::select('otp', 'updated_at')->where('user_id', '=', Input::get('u_id'))
1035
                ->first();
1036
        if ($otp != null) {
1037
            $otp_length = strlen(Input::get('otp'));
1038
            if (($otp_length == 6 && !preg_match('/[a-z]/i', Input::get('otp')))) {
1039
                $otp2 = Hash::make(Input::get('otp'));
0 ignored issues
show
Unused Code introduced by
$otp2 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...
1040
                $date1 = date_format($otp->updated_at, 'Y-m-d h:i:sa');
1041
                $date2 = date('Y-m-d h:i:sa');
1042
                $time1 = new DateTime($date2);
1043
                $time2 = new DateTime($date1);
1044
                $interval = $time1->diff($time2);
1045
                if ($interval->i > 10 || $interval->h > 0) {
1046
                    $message = Lang::get('lang.otp-expired');
1047
1048
                    return $message;
1049
                } else {
1050
                    if (Hash::check(Input::get('otp'), $otp->otp)) {
1051
                        Otp::where('user_id', '=', Input::get('u_id'))
1052
                                ->update(['otp' => '']);
1053
                        // User::where('id', '=', $user->id)
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% 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...
1054
                        //     ->update(['active' => 1]);
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% 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...
1055
                        // $this->openTicketAfterVerification($user->id);
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% 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...
1056
                        return 1;
1057
                    } else {
1058
                        $message = Lang::get('lang.otp-not-matched');
1059
1060
                        return $message;
1061
                    }
1062
                }
1063
            } else {
1064
                $message = Lang::get('lang.otp-invalid');
1065
1066
                return $message;
1067
            }
1068
        } else {
1069
            $message = Lang::get('lang.otp-not-matched');
1070
1071
            return $message;
1072
        }
1073
    }
1074
1075
    public function getAgentDetails()
1076
    {
1077
        $users = User::where('role', '<>', 'user')->where('active', '=', 1)->orderBy('first_name')->get();
1078
        foreach ($users as $user) {
1079
            echo "<option value='user_$user->id'>".$user->name().'</option>';
1080
        }
1081
    }
1082
}
1083