FormController::post_ticket_reply()   B
last analyzed

Complexity

Conditions 3
Paths 9

Size

Total Lines 39
Code Lines 30

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 30
nc 9
nop 2
dl 0
loc 39
rs 8.8571
c 0
b 0
f 0
1
<?php
2
3
namespace App\Http\Controllers\Client\helpdesk;
4
5
// controllers
6
use App\Http\Controllers\Agent\helpdesk\TicketWorkflowController;
7
use App\Http\Controllers\Controller;
8
// requests
9
use App\Http\Requests\helpdesk\ClientRequest;
10
use App\Model\helpdesk\Agent\Department;
11
// models
12
use App\Model\helpdesk\Form\Fields;
13
use App\Model\helpdesk\Manage\Help_topic;
14
use App\Model\helpdesk\Settings\CommonSettings;
15
use App\Model\helpdesk\Settings\System;
16
use App\Model\helpdesk\Settings\Ticket;
17
use App\Model\helpdesk\Ticket\Ticket_attachments;
18
use App\Model\helpdesk\Ticket\Ticket_Priority;
19
use App\Model\helpdesk\Ticket\Ticket_source;
20
use App\Model\helpdesk\Ticket\Ticket_Thread;
21
use App\Model\helpdesk\Ticket\Tickets;
22
use App\Model\helpdesk\Utility\CountryCode;
23
use App\User;
24
use Exception;
25
// classes
26
use Form;
27
use GeoIP;
28
use Illuminate\Http\Request;
29
use Input;
30
use Lang;
31
use Redirect;
32
33
/**
34
 * FormController.
35
 *
36
 * @author      Ladybird <[email protected]>
37
 */
38
class FormController extends Controller {
39
40
    /**
41
     * Create a new controller instance.
42
     * Constructor to check.
43
     *
44
     * @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...
45
     */
46
    public function __construct(TicketWorkflowController $TicketWorkflowController) {
47
        $this->middleware('board');
48
        // creating a TicketController instance
49
        $this->TicketWorkflowController = $TicketWorkflowController;
0 ignored issues
show
Bug introduced by
The property TicketWorkflowController 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...
50
    }
51
52
    /**
53
     * getform.
54
     *
55
     * @param type Help_topic $topic
56
     *
57
     * @return type
58
     */
59
    public function getForm(Help_topic $topic, CountryCode $code) {
60
        if (\Config::get('database.install') == '%0%') {
61
            return \Redirect::route('licence');
0 ignored issues
show
Bug Best Practice introduced by
The return type of return \Redirect::route('licence'); (Illuminate\Http\RedirectResponse) is incompatible with the return type documented by App\Http\Controllers\Cli...FormController::getForm 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...
62
        }
63
        $settings = CommonSettings::select('status')->where('option_name', '=', 'send_otp')->first();
64
        $email_mandatory = CommonSettings::select('status')->where('option_name', '=', 'email_mandatory')->first();
65
        if (!\Auth::check() && ($settings->status == 1 || $settings->status == '1')) {
66
            return redirect('auth/login')->with(['login_require' => 'Please login to your account for submitting a ticket', 'referer' => 'form']);
0 ignored issues
show
Bug Best Practice introduced by
The return type of return redirect('auth/lo... 'referer' => 'form')); (Illuminate\Http\RedirectResponse) is incompatible with the return type documented by App\Http\Controllers\Cli...FormController::getForm 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...
67
        }
68
        $location = GeoIP::getLocation();
69
        $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...
70
        if (System::first()->status == 1) {
71
            $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...
72
            $codes = $code->get();
0 ignored issues
show
Documentation Bug introduced by
The method get 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...
73
            if ($phonecode->phonecode) {
74
                $phonecode = $phonecode->phonecode;
75
            } else {
76
                $phonecode = '';
77
            }
78
79
            return view('themes.default1.client.helpdesk.form', compact('topics', 'codes', 'email_mandatory'))->with('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...
80
        } else {
81
            return \Redirect::route('home');
0 ignored issues
show
Bug Best Practice introduced by
The return type of return \Redirect::route('home'); (Illuminate\Http\RedirectResponse) is incompatible with the return type documented by App\Http\Controllers\Cli...FormController::getForm 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...
82
        }
83
    }
84
85
    /**
86
     * This Function to post the form for the ticket.
87
     *
88
     * @param type Form_name    $name
89
     * @param type Form_details $details
90
     *
91
     * @return type string
92
     */
93
    public function postForm($id, Help_topic $topic) {
94
        if ($id != 0) {
95
            $helptopic = $topic->where('id', '=', $id)->first();
0 ignored issues
show
Documentation Bug introduced by
The method where 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...
96
            $custom_form = $helptopic->custom_form;
97
            $values = Fields::where('forms_id', '=', $custom_form)->get();
98
            if (!$values) {
0 ignored issues
show
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies 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 if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

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

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
99
                
100
            }
101
            if ($values) {
102
                foreach ($values as $form_data) {
103
                    if ($form_data->type == 'select') {
104
                        $form_fields = explode(',', $form_data->value);
105
                        $var = '';
106
                        foreach ($form_fields as $form_field) {
107
                            $var .= '<option value="' . $form_field . '">' . $form_field . '</option>';
108
                        }
109
                        echo '<br/><label>' . ucfirst($form_data->label) . '</label><select class="form-control" name="' . $form_data->name . '">' . $var . '</select>';
110 View Code Duplication
                    } elseif ($form_data->type == 'radio') {
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...
111
                        $type2 = $form_data->value;
112
                        $vals = explode(',', $type2);
113
                        echo '<br/><label>' . ucfirst($form_data->label) . '</label><br/>';
114
                        foreach ($vals as $val) {
115
                            echo '<input type="' . $form_data->type . '" name="' . $form_data->name . '"> ' . $form_data->value . '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
116
                        }
117
                        echo '<br/>';
118
                    } elseif ($form_data->type == 'textarea') {
119
                        $type3 = $form_data->value;
0 ignored issues
show
Unused Code introduced by
$type3 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...
120
                        echo '<br/><label>' . $form_data->label . '</label></br><textarea id="unique-textarea" name="' . $form_data->name . '" class="form-control" style="height:15%;"></textarea>';
121 View Code Duplication
                    } elseif ($form_data->type == 'checkbox') {
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...
122
                        $type4 = $form_data->value;
123
                        $checks = explode(',', $type4);
124
                        echo '<br/><label>' . ucfirst($form_data->label) . '</label><br/>';
125
                        foreach ($checks as $check) {
126
                            echo '<input type="' . $form_data->type . '" name="' . $form_data->name . '">&nbsp&nbsp' . $check;
127
                        }
128
                    } else {
129
                        echo '<br/><label>' . ucfirst($form_data->label) . '</label><input type="' . $form_data->type . '" class="form-control"   name="' . $form_data->name . '" />';
130
                    }
131
                }
132
                echo '<br/><br/>';
133
            }
134
        } else {
135
            return;
136
        }
137
    }
138
139
    /**
140
     * Posted form.
141
     *
142
     * @param type Request $request
143
     * @param type User    $user
144
     */
145
    public function postedForm(User $user, ClientRequest $request, Ticket $ticket_settings, Ticket_source $ticket_source, Ticket_attachments $ta, CountryCode $code) {
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...
146
        try {
147
            $form_extras = $request->except('Name', 'Phone', 'Email', 'Subject', 'Details', 'helptopic', '_wysihtml5_mode', '_token', 'mobile', 'Code', 'priority', 'attachment');
148
            $name = $request->input('Name');
149
            $phone = $request->input('Phone');
150
            if ($request->input('Email')) {
151
                if ($request->input('Email')) {
152
                    $email = $request->input('Email');
153
                } else {
154
                    $email = null;
155
                }
156
            } else {
157
                $email = null;
158
            }
159
            $subject = $request->input('Subject');
160
            $details = $request->input('Details');
161
            $phonecode = $request->input('Code');
162
            if ($request->input('mobile')) {
163
                $mobile_number = $request->input('mobile');
164
            } else {
165
                $mobile_number = null;
166
            }
167
            $status = $ticket_settings->first()->status;
0 ignored issues
show
Documentation Bug introduced by
The method first does not exist on object<App\Model\helpdesk\Settings\Ticket>? Since you implemented __call, maybe consider adding a @method annotation.

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

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

class ParentClass {
    private $data = array();

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

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

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
168
            $helptopic = $request->input('helptopic');
169
            $helpTopicObj = Help_topic::where('id', '=', $helptopic);
170
            if ($helpTopicObj->exists() && ($helpTopicObj->value('status') == 1)) {
171
                $department = $helpTopicObj->value('department');
172
            } else {
173
                $defaultHelpTopicID = Ticket::where('id', '=', '1')->first()->help_topic;
174
                $department = Help_topic::where('id', '=', $defaultHelpTopicID)->value('department');
175
            }
176
            $sla = $ticket_settings->first()->sla;
0 ignored issues
show
Documentation Bug introduced by
The method first does not exist on object<App\Model\helpdesk\Settings\Ticket>? Since you implemented __call, maybe consider adding a @method annotation.

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

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

class ParentClass {
    private $data = array();

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

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

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
177
178
            // $priority = $ticket_settings->first()->priority;
0 ignored issues
show
Unused Code Comprehensibility introduced by
54% 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...
179
            $default_priority = Ticket_Priority::where('is_default', '=', 1)->first();
180
            $user_priority = CommonSettings::where('option_name', '=', 'user_priority')->first();
0 ignored issues
show
Unused Code introduced by
$user_priority 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...
181
            if (!($request->input('priority'))) {
182
                $priority = $default_priority->priority_id;
183
                if ($helpTopicObj->exists() && ($helpTopicObj->value('status') == 1)) {
184
                    $priority = $helpTopicObj->value('priority');
185
                }
186
            } else {
187
                $priority = $request->input('priority');
188
            }
189
            $source = $ticket_source->where('name', '=', 'web')->first()->id;
0 ignored issues
show
Documentation Bug introduced by
The method where does not exist on object<App\Model\helpdesk\Ticket\Ticket_source>? 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...
190
            $attachments = $request->file('attachment');
191
            $collaborator = null;
192
            $assignto = null;
193
            if ($helpTopicObj->exists() && ($helpTopicObj->value('status') == 1)) {
194
                $assignto = $helpTopicObj->value('auto_assign');
195
            }
196
            $auto_response = 0;
197
            $team_assign = null;
198
            if ($phone != null || $mobile_number != null) {
0 ignored issues
show
Bug introduced by
It seems like you are loosely comparing $mobile_number of type string|array|null against null; this is ambiguous if the string can be empty. Consider using a strict comparison !== instead.
Loading history...
199
                $location = GeoIP::getLocation();
200
                $geoipcode = $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...
201
                if ($phonecode == null) {
202
                    $data = [
203
                        'fails' => Lang::get('lang.country-code-required-error'),
204
                        'phonecode' => $geoipcode->phonecode,
205
                        'country_code_error' => 1,
206
                    ];
207
208
                    return Redirect::back()->with($data)->withInput($request->except('password'));
209
                } else {
210
                    $code = CountryCode::select('phonecode')->where('phonecode', '=', $phonecode)->get();
211
                    if (!count($code)) {
212
                        $data = [
213
                            'fails' => Lang::get('lang.incorrect-country-code-error'),
214
                            'phonecode' => $geoipcode->phonecode,
215
                            'country_code_error' => 1,
216
                        ];
217
218
                        return Redirect::back()->with($data)->withInput($request->except('password'));
219
                    }
220
                }
221
            }
222
            \Event::fire(new \App\Events\ClientTicketFormPost($form_extras, $email, $source));
0 ignored issues
show
Documentation introduced by
$form_extras is of type array, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Bug introduced by
It seems like $email can also be of type array or null; however, App\Events\ClientTicketFormPost::__construct() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
223
            $result = $this->TicketWorkflowController->workflow($email, $name, $subject, $details, $phone, $phonecode, $mobile_number, $helptopic, $sla, $priority, $source, $collaborator, $department, $assignto, $team_assign, $status, $form_extras, $auto_response);
224
            // dd($result);
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...
225
            if ($result[1] == 1) {
226
                $ticketId = Tickets::where('ticket_number', '=', $result[0])->first();
227
                $thread = Ticket_Thread::where('ticket_id', '=', $ticketId->id)->first();
228
                if ($attachments != null) {
229
                    foreach ($attachments as $attachment) {
0 ignored issues
show
Bug introduced by
The expression $attachments of type object<Illuminate\Http\UploadedFile>|array is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
230
                        if ($attachment != null) {
231
                            $name = $attachment->getClientOriginalName();
232
                            $type = $attachment->getClientOriginalExtension();
233
                            $size = $attachment->getSize();
234
                            $data = file_get_contents($attachment->getRealPath());
235
                            $attachPath = $attachment->getRealPath();
0 ignored issues
show
Unused Code introduced by
$attachPath 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...
236
                            $ta->create(['thread_id' => $thread->id, 'name' => $name, 'size' => $size, 'type' => $type, 'file' => $data, 'poster' => 'ATTACHMENT']);
237
                        }
238
                    }
239
                }
240
                // dd($result);
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...
241
                return Redirect::back()->with('success', Lang::get('lang.Ticket-has-been-created-successfully-your-ticket-number-is') . ' ' . $result[0] . '. ' . Lang::get('lang.Please-save-this-for-future-reference'));
242
            } else {
243
                return Redirect::back()->withInput($request->except('password'))->with('fails', Lang::get('lang.failed-to-create-user-tcket-as-mobile-has-been-taken'));
244
            }
245
        } catch (\Exception $ex) {
246
            return redirect()->back()->with('fails', $ex->getMessage());
247
        }
248
//        dd($result);
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...
249
    }
250
251
    /**
252
     * reply.
253
     *
254
     * @param type $value
0 ignored issues
show
Bug introduced by
There is no parameter named $value. 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...
255
     *
256
     * @return type view
257
     */
258
    public function post_ticket_reply($id, Request $request) {
259
        try {
260
            if ($comment != null) {
0 ignored issues
show
Bug introduced by
The variable $comment does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
261
                $tickets = Tickets::where('id', '=', $id)->first();
262
                $thread = Ticket_Thread::where('ticket_id', '=', $tickets->id)->first();
263
264
                $subject = $thread->title . '[#' . $tickets->ticket_number . ']';
265
                $body = $request->input('comment');
266
267
                $user_cred = User::where('id', '=', $tickets->user_id)->first();
268
269
                $fromaddress = $user_cred->email;
270
                $fromname = $user_cred->user_name;
271
                $phone = '';
272
                $phonecode = '';
273
                $mobile_number = '';
274
275
                $helptopic = $tickets->help_topic_id;
276
                $sla = $tickets->sla;
277
                $priority = $tickets->priority_id;
278
                $source = $tickets->source;
279
                $collaborator = '';
280
                $dept = $tickets->dept_id;
281
                $assign = $tickets->assigned_to;
282
                $form_data = null;
283
                $team_assign = null;
284
                $ticket_status = null;
285
                $auto_response = 0;
286
287
                $this->TicketWorkflowController->workflow($fromaddress, $fromname, $subject, $body, $phone, $phonecode, $mobile_number, $helptopic, $sla, $priority, $source, $collaborator, $dept, $assign, $team_assign, $ticket_status, $form_data, $auto_response);
288
289
                return \Redirect::back()->with('success1', Lang::get('lang.successfully_replied'));
290
            } else {
291
                return \Redirect::back()->with('fails1', Lang::get('lang.please_fill_some_data'));
292
            }
293
        } catch (Exception $e) {
294
            return \Redirect::back()->with('fails1', $e->getMessage());
295
        }
296
    }
297
298
    public function getCustomForm(Request $request) {
299
        $html = '';
300
        $helptopic_id = $request->input('helptopic');
301
        $helptopics = new Help_topic();
302
        $helptopic = $helptopics->find($helptopic_id);
0 ignored issues
show
Documentation Bug introduced by
The method find 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...
303
        if (!$helptopic) {
304
            throw new Exception('We can not find your request');
305
        }
306
        $custom_form = $helptopic->custom_form;
307
        if ($custom_form) {
308
            $fields = new Fields();
309
            $forms = new \App\Model\helpdesk\Form\Forms();
310
            $form_controller = new \App\Http\Controllers\Admin\helpdesk\FormController($fields, $forms);
311
            $html = $form_controller->renderForm($custom_form);
312
        }
313
314
        return $html;
315
    }
316
317
}
318