Completed
Push — master ( 5dc77f...6a8ca7 )
by Wilmer
02:13
created

SiteController   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 91
Duplicated Lines 0 %

Test Coverage

Coverage 84.62%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 30
c 2
b 0
f 0
dl 0
loc 91
ccs 22
cts 26
cp 0.8462
rs 10
wmc 9

6 Methods

Rating   Name   Duplication   Size   Complexity  
A actions() 0 9 2
A actionContact() 0 13 3
A sendContact() 0 11 1
A behaviors() 0 7 1
A actionAbout() 0 3 1
A actionIndex() 0 3 1
1
<?php
2
3
namespace terabytesoft\app\basic\controllers;
4
5
use terabytesoft\app\basic\forms\ContactForm;
6
use yii\base\Model;
7
use yii\captcha\CaptchaAction;
8
use yii\filters\AccessControl;
9
use yii\filters\VerbFilter;
10
use yii\web\Controller;
11
use yii\web\ErrorAction;
12
use yii\web\Response;
13
14
/**
15
 * SiteController
16
 *
17
 * Controller web application basic
18
 */
19
class SiteController extends Controller
20
{
21
    /**
22
     * @var array
23
     */
24
    public $app;
25
26
    /**
27
     * behaviors
28
     */
29 4
    public function behaviors()
30
    {
31
        return [
32
            'verbs' => [
33 4
                'class' => VerbFilter::class,
34
                'actions' => [
35
                    'logout' => ['post'],
36
                ],
37
            ],
38
        ];
39
    }
40
41
42
    /**
43
     * actions
44
     */
45 4
    public function actions()
46
    {
47
        return [
48
            'error' => [
49 4
                'class' => ErrorAction::class,
50
            ],
51
            'captcha' => [
52
                'class' => CaptchaAction::class,
53 4
                'fixedVerifyCode' => YII_ENV ? 'testme' : null,
54
            ],
55
        ];
56
    }
57
58
    /**
59
     * actionIndex
60
     */
61
    public function actionIndex(): string
62
    {
63
        return $this->render('index');
64
    }
65
66
    /**
67
     * actionAbout
68
     **/
69
    public function actionAbout(): string
70
    {
71
        return $this->render('about');
72
    }
73
74
    /**
75
     * actionContact
76
     * @return response|string
77
     **/
78 4
    public function actionContact()
79
    {
80 4
        $model = new ContactForm();
81
82 4
        if ($model->load($this->module->request->post()) && $model->validate()) {
0 ignored issues
show
Bug introduced by
The method post() does not exist on null. ( Ignorable by Annotation )

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

82
        if ($model->load($this->module->request->/** @scrutinizer ignore-call */ post()) && $model->validate()) {

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...
83 1
            $this->sendContact($this->module->params['app.basic.email.admin'], $model);
84 1
            $this->module->session->setFlash('contactFormSubmitted');
0 ignored issues
show
Bug introduced by
The method setFlash() does not exist on null. ( Ignorable by Annotation )

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

84
            $this->module->session->/** @scrutinizer ignore-call */ 
85
                                    setFlash('contactFormSubmitted');

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...
85
86 1
            return $this->refresh();
87
        }
88
89 4
        return $this->render('contact', [
90 4
            'model' => $model,
91
        ]);
92
    }
93
94
    /**
95
     * sendContact
96
     * @param string $email the target email address
97
     * @param Model  $model
98
     **/
99 2
    public function sendContact(string $email, Model $model): void
100
    {
101 2
        $this->module->mailer->compose()
0 ignored issues
show
Bug introduced by
The method compose() does not exist on null. ( Ignorable by Annotation )

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

101
        $this->module->mailer->/** @scrutinizer ignore-call */ 
102
                               compose()

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...
102 2
            ->setTo($email)
103 2
            ->setFrom(
104 2
                [$this->module->params['app.basic.email.admin'] => $this->module->params['app.basic.email.sendername']]
105
            )
106 2
            ->setReplyTo([$model->email => $model->name])
107 2
            ->setSubject($model->subject)
108 2
            ->setTextBody($model->body)
109 2
            ->send();
110 2
    }
111
}
112