GuestController::changeRedirect()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace App\Http\Controllers\Client\helpdesk;
4
5
// controllers
6
use App\Http\Controllers\Common\PhpMailController;
7
use App\Http\Controllers\Controller;
8
// requests
9
use App\Http\Requests\helpdesk\OtpVerifyRequest;
10
use App\Http\Requests\helpdesk\ProfilePassword;
11
use App\Http\Requests\helpdesk\ProfileRequest;
12
use App\Http\Requests\helpdesk\TicketRequest;
13
// models
14
use App\Model\helpdesk\Manage\Help_topic;
15
use App\Model\helpdesk\Settings\CommonSettings;
16
use App\Model\helpdesk\Settings\Company;
17
use App\Model\helpdesk\Settings\System;
18
use App\Model\helpdesk\Ticket\Ticket_Thread;
19
use App\Model\helpdesk\Ticket\Tickets;
20
use App\Model\helpdesk\Utility\CountryCode;
21
use App\Model\helpdesk\Utility\Otp;
22
use App\User;
23
use Auth;
24
// classes
25
use DateTime;
26
use DB;
27
use Exception;
28
use GeoIP;
29
use Hash;
30
use Illuminate\Http\Request;
31
use Input;
32
use Lang;
33
use Socialite;
34
35
/**
36
 * GuestController.
37
 *
38
 * @author      Ladybird <[email protected]>
39
 */
40
class GuestController extends Controller
41
{
42
    /**
43
     * Create a new controller instance.
44
     *
45
     * @return type 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...
46
     */
47
    public function __construct(PhpMailController $PhpMailController)
48
    {
49
        $this->middleware('board');
50
        $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...
51
        // checking authentication
52
        $this->middleware('auth');
53
    }
54
55
    /**
56
     * Get profile.
57
     *
58
     * @return type Response
59
     */
60
    public function getProfile(CountryCode $code)
61
    {
62
        $user = Auth::user();
63
        $location = GeoIP::getLocation();
64
        $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...
65
        $settings = CommonSettings::select('status')->where('option_name', '=', 'send_otp')->first();
66
        $status = $settings->status;
67
68
        return view('themes.default1.client.helpdesk.profile', 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...
69
                        ->with(['phonecode' => $phonecode->phonecode,
70
                            'verify'        => $status, ]);
71
    }
72
73
    /**
74
     * Save profile data.
75
     *
76
     * @param type                $id
0 ignored issues
show
Bug introduced by
There is no parameter named $id. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
77
     * @param type ProfileRequest $request
78
     *
79
     * @return type Response
80
     */
81
    public function postProfile(ProfileRequest $request)
82
    {
83
        try {
84
            // geet authenticated user details
85
            $user = Auth::user();
86 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...
87
                return redirect()->back()->with(['fails' => Lang::get('lang.country-code-required-error'), 'country_code_error' => 1])->withInput();
0 ignored issues
show
Bug Best Practice introduced by
The return type of return redirect()->back(...r' => 1))->withInput(); (Illuminate\Http\RedirectResponse) is incompatible with the return type documented by App\Http\Controllers\Cli...Controller::postProfile of type App\Http\Controllers\Client\helpdesk\type.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
88
            } else {
89
                $code = CountryCode::select('phonecode')->where('phonecode', '=', $request->get('country_code'))->get();
90
                if (!count($code)) {
91
                    return redirect()->back()->with(['fails' => Lang::get('lang.incorrect-country-code-error'), 'country_code_error' => 1])->withInput();
0 ignored issues
show
Bug Best Practice introduced by
The return type of return redirect()->back(...r' => 1))->withInput(); (Illuminate\Http\RedirectResponse) is incompatible with the return type documented by App\Http\Controllers\Cli...Controller::postProfile of type App\Http\Controllers\Client\helpdesk\type.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
92
                }
93
                $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...
94
            }
95
            $user->fill($request->except('profile_pic', 'mobile'));
96
            $user->gender = $request->input('gender');
97
            $user->save();
98
            if (Input::file('profile_pic')) {
99
                // fetching picture name
100
                $name = Input::file('profile_pic')->getClientOriginalName();
101
            // fetching upload destination path
102
                $destinationPath = 'uploads/profilepic';
103
            // adding a random value to profile picture filename
104
                $fileName = rand(0000, 9999).'.'.$name;
105
            // moving the picture to a destination folder
106
                Input::file('profile_pic')->move($destinationPath, $fileName);
107
            // saving filename to database
108
                $user->profile_pic = $fileName;
109
            }
110
            if ($request->get('mobile')) {
111
                $user->mobile = $request->get('mobile');
112
            } else {
113
                $user->mobile = null;
114
            }
115
            if ($user->save()) {
116
                return redirect()->back()->with('success', Lang::get('lang.Profile-Updated-sucessfully'));
0 ignored issues
show
Bug Best Practice introduced by
The return type of return redirect()->back(...Updated-sucessfully')); (Illuminate\Http\RedirectResponse) is incompatible with the return type documented by App\Http\Controllers\Cli...Controller::postProfile of type App\Http\Controllers\Client\helpdesk\type.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
117
            } else {
118
                return redirect()->back()->route('profile')->with('fails', Lang::get('lang.Profile-Updated-sucessfully'));
119
            }
120
        } catch (Exception $e) {
121
            return redirect()->back()->route('profile')->with('fails', $e->getMessage());
122
        }
123
    }
124
125
    /**
126
     *@category fucntion to check if mobile number is unqique or not
127
     *
128
     *@param string $mobile
129
     *
130
     *@return bool true(if mobile exists in users table)/false (if mobile does not exist in user table)
131
     */
132
    public function checkMobile($mobile)
133
    {
134
        if ($mobile) {
135
            $check = User::where('mobile', '=', $mobile)
136
                ->where('id', '<>', \Auth::user()->id)
137
                ->first();
138
            if (count($check) > 0) {
139
                return true;
140
            }
141
        }
142
143
        return false;
144
    }
145
146
    /**
147
     * Get Ticket page.
148
     *
149
     * @param type Help_topic $topic
150
     *
151
     * @return type Response
152
     */
153
    public function getTicket(Help_topic $topic)
154
    {
155
        $topics = $topic->get();
0 ignored issues
show
Documentation Bug introduced by
The method get does not exist on object<App\Model\helpdesk\Manage\Help_topic>? 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...
156
157
        return view('themes.default1.client.helpdesk.tickets.form', compact('topics'));
158
    }
159
160
    /**
161
     * getform.
162
     *
163
     * @param type Help_topic $topic
164
     *
165
     * @return type
166
     */
167
    public function getForm(Help_topic $topic)
168
    {
169
        if (\Config::get('database.install') == '%0%') {
170
            return \Redirect::route('licence');
171
        }
172
        if (System::first()->status == 1) {
173
            $topics = $topic->get();
0 ignored issues
show
Documentation Bug introduced by
The method get does not exist on object<App\Model\helpdesk\Manage\Help_topic>? 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...
174
175
            return view('themes.default1.client.helpdesk.form', compact('topics'));
176
        } else {
177
            return \Redirect::route('home');
178
        }
179
    }
180
181
    /**
182
     * Get my ticket.
183
     *
184
     * @param type Tickets       $tickets
185
     * @param type Ticket_Thread $thread
186
     * @param type User          $user
187
     *
188
     * @return type Response
189
     */
190
    public function getMyticket()
191
    {
192
        return view('themes.default1.client.helpdesk.mytickets');
193
    }
194
195
    /**
196
     * Get ticket-thread.
197
     *
198
     * @param type Ticket_Thread $thread
199
     * @param type Tickets       $tickets
200
     * @param type User          $user
201
     *
202
     * @return type Response
203
     */
204
    public function thread(Ticket_Thread $thread, Tickets $tickets, User $user)
0 ignored issues
show
Unused Code introduced by
The parameter $user 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...
205
    {
206
        $user_id = Auth::user()->id;
207
        //dd($user_id);
208
        /* get the ticket's id == ticket_id of thread  */
209
        $tickets = $tickets->where('user_id', '=', $user_id)->first();
0 ignored issues
show
Documentation Bug introduced by
The method where does not exist on object<App\Model\helpdesk\Ticket\Tickets>? 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...
210
        //dd($ticket);
211
        $thread = $thread->where('ticket_id', $tickets->id)->first();
0 ignored issues
show
Documentation Bug introduced by
The method where does not exist on object<App\Model\helpdesk\Ticket\Ticket_Thread>? Since you implemented __call, maybe consider adding a @method annotation.

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

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

class ParentClass {
    private $data = array();

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

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

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
212
        //dd($thread);
213
        // $tickets = $tickets->whereId($id)->first();
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...
214
        return view('themes.default1.client.guest-user.view_ticket', compact('thread', 'tickets'));
215
    }
216
217
    /**
218
     * ticket Edit.
219
     *
220
     * @return
221
     */
222
    public function ticketEdit()
223
    {
224
    }
225
226
    /**
227
     * Post porfile password.
228
     *
229
     * @param type                 $id
0 ignored issues
show
Bug introduced by
There is no parameter named $id. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
230
     * @param type ProfilePassword $request
231
     *
232
     * @return type Response
233
     */
234
    public function postProfilePassword(ProfilePassword $request)
235
    {
236
        $user = Auth::user();
237
        //echo $user->password;
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
        if (Hash::check($request->input('old_password'), $user->getAuthPassword())) {
239
            $user->password = Hash::make($request->input('new_password'));
240
            try {
241
                $user->save();
242
243
                return redirect()->back()->with('success2', Lang::get('lang.password_updated_sucessfully'));
244
            } catch (Exception $e) {
245
                return redirect()->back()->with('fails2', $e->getMessage());
246
            }
247
        } else {
248
            return redirect()->back()->with('fails2', Lang::get('lang.password_was_not_updated_incorrect_old_password'));
249
        }
250
    }
251
252
    /**
253
     * Ticekt reply.
254
     *
255
     * @param type Ticket_Thread $thread
256
     * @param type TicketRequest $request
257
     *
258
     * @return type Response
259
     */
260
    public function reply(Ticket_Thread $thread, TicketRequest $request)
261
    {
262
        $thread->ticket_id = $request->input('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...
263
        $thread->title = $request->input('To');
0 ignored issues
show
Documentation introduced by
The property title 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...
264
        $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...
265
        $thread->body = $request->input('reply_content');
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...
266
        $thread->poster = 'user';
0 ignored issues
show
Documentation introduced by
The property poster 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...
267
        $thread->save();
268
        $ticket_id = $request->input('ticket_ID');
269
        $tickets = Tickets::where('id', '=', $ticket_id)->first();
0 ignored issues
show
Unused Code introduced by
$tickets 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...
270
        $thread = Ticket_Thread::where('ticket_id', '=', $ticket_id)->first();
0 ignored issues
show
Unused Code introduced by
$thread 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...
271
272
        return Redirect('thread/'.$ticket_id);
273
    }
274
275
    /**
276
     * Get Checked ticket.
277
     *
278
     * @param type Tickets $ticket
279
     * @param type User    $user
280
     *
281
     * @return type response
282
     */
283
    public function getCheckTicket(Tickets $ticket, User $user)
0 ignored issues
show
Unused Code introduced by
The parameter $user 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...
284
    {
285
        return view('themes.default1.client.helpdesk.guest-user.newticket', compact('ticket'));
286
    }
287
288
    /**
289
     * Post Check ticket.
290
     *
291
     * @param type CheckTicket   $request
292
     * @param type User          $user
293
     * @param type Tickets       $ticket
294
     * @param type Ticket_Thread $thread
295
     *
296
     * @return type Response
297
     */
298
    public function PostCheckTicket(Request $request)
299
    {
300
        $validator = \Validator::make($request->all(), [
301
                    'email'         => 'required|email',
302
                    'ticket_number' => 'required',
303
        ]);
304
        if ($validator->fails()) {
305
            return redirect()->back()
306
                            ->withErrors($validator)
307
                            ->withInput()
308
                            ->with('check', '1');
309
        }
310
        $Email = $request->input('email');
311
        $Ticket_number = $request->input('ticket_number');
312
        $ticket = Tickets::where('ticket_number', '=', $Ticket_number)->first();
313
        if ($ticket == null) {
314
            return \Redirect::route('form')->with('fails', Lang::get('lang.there_is_no_such_ticket_number'));
315
        } else {
316
            $userId = $ticket->user_id;
317
            $user = User::where('id', '=', $userId)->first();
318 View Code Duplication
            if ($user->role == 'user') {
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...
319
                $username = $user->first_name;
320
            } else {
321
                $username = $user->first_name.' '.$user->last_name;
322
            }
323
            if ($user->email != $Email) {
324
                return \Redirect::route('form')->with('fails', Lang::get("lang.email_didn't_match_with_ticket_number"));
325
            } else {
326
                $code = $ticket->id;
327
                $code = \Crypt::encrypt($code);
328
329
                $company = $this->company();
0 ignored issues
show
Unused Code introduced by
$company 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...
330
331
                $this->PhpMailController->sendmail(
332
                        $from = $this->PhpMailController->mailfrom('1', '0'), $to = ['name' => $username, 'email' => $user->email], $message = ['subject' => 'Ticket link Request ['.$Ticket_number.']', 'scenario' => 'check-ticket'], $template_variables = ['user' => $username, 'ticket_link_with_number' => \URL::route('check_ticket', $code)]
333
                );
334
335
                return \Redirect::back()
336
                                ->with('success', Lang::get('lang.we_have_sent_you_a_link_by_email_please_click_on_that_link_to_view_ticket'));
337
            }
338
        }
339
    }
340
341
    /**
342
     * get ticket email.
343
     *
344
     * @param type $id
345
     *
346
     * @return type
347
     */
348
    public function get_ticket_email($id, CommonSettings $common_settings)
349
    {
350
        $common_setting = $common_settings->select('status')
0 ignored issues
show
Documentation Bug introduced by
The method select does not exist on object<App\Model\helpdes...ettings\CommonSettings>? 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...
351
                ->where('option_name', '=', 'user_set_ticket_status')
352
                ->first();
353
354
        return view('themes.default1.client.helpdesk.ckeckticket', compact('id', 'common_setting'));
355
    }
356
357
    /**
358
     * get ticket status.
359
     *
360
     * @param type Tickets $ticket
361
     *
362
     * @return type
363
     */
364
    public function getTicketStat(Tickets $ticket)
365
    {
366
        return view('themes.default1.client.helpdesk.ckeckticket', compact('ticket'));
367
    }
368
369
    /**
370
     * get company.
371
     *
372
     * @return type
373
     */
374 View Code Duplication
    public function company()
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...
375
    {
376
        $company = Company::Where('id', '=', '1')->first();
377
        if ($company->company_name == null) {
378
            $company = 'Support Center';
379
        } else {
380
            $company = $company->company_name;
381
        }
382
383
        return $company;
384
    }
385
386 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...
387
    {
388
        if (\Schema::hasTable('sms')) {
389
            $sms = DB::table('sms')->get();
390
            if (count($sms) > 0) {
391
                \Event::fire(new \App\Events\LoginEvent($request));
392
393
                return 1;
394
            }
395
        } else {
396
            return 'Plugin has not been setup successfully.';
397
        }
398
    }
399
400 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...
401
    {
402
        // 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...
403
        // $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...
404
        $otp = Otp::select('otp', 'updated_at')->where('user_id', '=', Input::get('u_id'))
405
                                ->first();
406
        if ($otp != null) {
407
            $otp_length = strlen(Input::get('otp'));
408
            if (($otp_length == 6 && !preg_match('/[a-z]/i', Input::get('otp')))) {
409
                $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...
410
                $date1 = date_format($otp->updated_at, 'Y-m-d h:i:sa');
411
                $date2 = date('Y-m-d h:i:sa');
412
                $time1 = new DateTime($date2);
413
                $time2 = new DateTime($date1);
414
                $interval = $time1->diff($time2);
415
                if ($interval->i > 10 || $interval->h > 0) {
416
                    $message = Lang::get('lang.otp-expired');
417
418
                    return $message;
419
                } else {
420
                    if (Hash::check(Input::get('otp'), $otp->otp)) {
421
                        Otp::where('user_id', '=', Input::get('u_id'))
422
                            ->update(['otp' => '']);
423
                        // 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...
424
                        //     ->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...
425
                        // $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...
426
                        return 1;
427
                    } else {
428
                        $message = Lang::get('lang.otp-not-matched');
429
430
                        return $message;
431
                    }
432
                }
433
            } else {
434
                $message = Lang::get('lang.otp-invalid');
435
436
                return $message;
437
            }
438
        } else {
439
            $message = Lang::get('lang.otp-not-matched');
440
441
            return $message;
442
        }
443
    }
444
445
    public function sync()
446
    {
447
        try {
448
            $provider = $this->getProvider();
449
            $this->changeRedirect();
450
            $users = Socialite::driver($provider)->user();
451
            $this->forgetSession();
452
            $user['provider'] = $provider;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$user was never initialized. Although not strictly required by PHP, it is generally a good practice to add $user = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
453
            $user['social_id'] = $users->id;
454
            $user['name'] = $users->name;
455
            $user['email'] = $users->email;
456
            $user['username'] = $users->nickname;
457
            $user['avatar'] = $users->avatar;
458
459
            return redirect('client-profile')->with('success', 'Additional informations fetched');
460
        } catch (Exception $ex) {
461
            dd($ex);
462
463
            return redirect('client-profile')->with('fails', $ex->getMessage());
464
        }
465
    }
466
467
    public function getProvider()
468
    {
469
        $provider = \Session::get('provider');
470
471
        return $provider;
472
    }
473
474
    public function changeRedirect()
475
    {
476
        $provider = \Session::get('provider');
477
        $url = \Session::get($provider.'redirect');
478
        \Config::set("services.$provider.redirect", $url);
479
    }
480
481
    public function forgetSession()
482
    {
483
        $provider = $this->getProvider();
484
        \Session::forget('provider');
485
        \Session::forget($provider.'redirect');
486
    }
487
488
    public function checkArray($key, $array)
489
    {
490
        $value = '';
491
        if (array_key_exists($key, $array)) {
492
            $value = $array[$key];
493
        }
494
495
        return $value;
496
    }
497
498
    public function updateUser($user = [])
499
    {
500
        $userid = \Auth::user()->id;
501
        $useremail = \Auth::user()->email;
502
        $email = $this->checkArray('email', $user); //$user['email'];
503
        if ($email !== '' && $email !== $useremail) {
504
            throw new Exception('Sorry! your current email and '.ucfirst($user['provider']).' email is different so system can not sync');
505
        }
506
        $this->update($userid, $user);
0 ignored issues
show
Bug introduced by
The call to update() misses a required argument $provider.

This check looks for function calls that miss required arguments.

Loading history...
507
    }
508
509
    public function update($userid, $user, $provider)
510
    {
511
        $email = $this->checkArray('email', $user);
512
        $this->deleteUser($userid, $user, $provider);
513
        $this->insertAdditional($userid, $provider, $user);
514
        $this->changeEmail($email);
515
    }
516
517
    public function deleteUser($userid, $user, $provider)
518
    {
519
        $info = new \App\UserAdditionalInfo();
520
        $infos = $info->where('owner', $userid)->where('service', $provider)->get();
0 ignored issues
show
Documentation Bug introduced by
The method where does not exist on object<App\UserAdditionalInfo>? 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...
521
        if ($infos->count() > 0 && count($user) > 0) {
522
            foreach ($infos as $key => $detail) {
523
                //if ($user[$key] !== $detail->$key) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
71% 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
                $detail->delete();
525
                //}
526
            }
527
        }
528
    }
529
530
    public function insertAdditional($id, $provider, $user = [])
531
    {
532
        $info = new \App\UserAdditionalInfo();
533
        if (count($user) > 0) {
534
            foreach ($user as $key => $value) {
535
                $info->create([
536
                    'owner'   => $id,
537
                    'service' => $provider,
538
                    'key'     => $key,
539
                    'value'   => $value,
540
                ]);
541
            }
542
        }
543
    }
544
545
    public function changeEmail($email)
546
    {
547
        $user = \Auth::user();
548
        if ($user && $email && !$user->email) {
549
            $user->email = $email;
550
            $user->save();
551
        }
552
    }
553
}
554