Passed
Push — dev ( 9d591d...c59ba0 )
by Darko
22:01
created

ContactUsController::showContactForm()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 12
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use App\Jobs\SendContactUsEmail;
6
use Illuminate\Http\Request;
7
8
class ContactUsController extends BasePageController
9
{
10
    /**
11
     * @param \Illuminate\Http\Request $request
12
     *
13
     * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
14
     * @throws \Exception
15
     */
16
    public function contact(Request $request)
17
    {
18
        $this->setPrefs();
19
        $this->validate($request, [
20
            'useremail' => 'required',
21
            'username' => 'required',
22
        ]);
23
24
        if (config('captcha.enabled') === true && (! empty(config('captcha.secret')) && ! empty(config('captcha.sitekey')))) {
25
            $this->validate($request, [
26
                'g-recaptcha-response' => 'required|captcha',
27
            ]);
28
        }
29
30
        $msg = '';
31
32
        if ($request->has('useremail')) {
33
            $email = $request->input('useremail');
34
            $mailTo = config('mail.from.address');
35
            $mailBody = 'Values submitted from contact form: ';
36
37
            foreach ($request->all() as $key => $value) {
38
                if ($key !== 'submit' && $key !== '_token' && $key !== 'g-recaptcha-response') {
39
                    $mailBody .= "$key : $value".PHP_EOL;
40
                }
41
            }
42
43
            if (! preg_match("/\n/i", $request->input('useremail'))) {
44
                SendContactUsEmail::dispatch($email, $mailTo, $mailBody)->onQueue('contactemail');
45
            }
46
            $msg = "<h2 style='text-align:center;'>Thank you for getting in touch with ".config('app.name').'.</h2>';
47
        }
48
49
        return $this->showContactForm($msg);
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->showContactForm($msg) targeting App\Http\Controllers\Con...ller::showContactForm() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
50
    }
51
52
    /**
53
     * @param string $msg
54
     *
55
     * @throws \Exception
56
     */
57
    public function showContactForm($msg = '')
58
    {
59
        $this->setPrefs();
60
        $title = 'Contact '.config('app.name');
61
        $meta_title = 'Contact '.config('app.name');
62
        $meta_keywords = 'contact us,contact,get in touch,email';
63
        $meta_description = 'Contact us at '.config('app.name').' and submit your feedback';
64
        $content = $this->smarty->fetch('contact.tpl');
0 ignored issues
show
Bug introduced by
The method fetch() does not exist on Illuminate\Foundation\Application. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

64
        /** @scrutinizer ignore-call */ 
65
        $content = $this->smarty->fetch('contact.tpl');

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
65
66
        $this->smarty->assign(compact('title', 'content', 'meta_title', 'meta_keywords', 'meta_description', 'msg'));
0 ignored issues
show
Bug introduced by
The method assign() does not exist on Illuminate\Foundation\Application. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

66
        $this->smarty->/** @scrutinizer ignore-call */ 
67
                       assign(compact('title', 'content', 'meta_title', 'meta_keywords', 'meta_description', 'msg'));

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
67
68
        $this->pagerender();
69
    }
70
}
71