Passed
Push — master ( 7d97ae...1dbfa0 )
by Mihail
04:17
created

FormAnswerAdd::sendEmail()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 9

Duplication

Lines 18
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 18
loc 18
rs 9.4285
cc 1
eloc 9
nc 1
nop 1
1
<?php
2
3
namespace Apps\Model\Admin\Feedback;
4
5
use Apps\ActiveRecord\FeedbackAnswer;
6
use Apps\ActiveRecord\FeedbackPost;
7
use Apps\Model\Front\Feedback\FormAnswerAdd as FrontAnswer;
8
use Ffcms\Core\App;
9
10
/**
11
 * Class FormAnswerAdd. Extend front model add answer
12
 * @package Apps\Model\Admin\Feedback
13
 */
14
class FormAnswerAdd extends FrontAnswer
15
{
16
    public function make()
17
    {
18
        // update readed marker
19
        $this->_post->readed = 1;
20
        $this->_post->save();
21
22
        // add new answer row in database
23
        $record = new FeedbackAnswer();
24
        $record->feedback_id = $this->_post->id;
25
        $record->name = App::$Security->strip_tags($this->name);
26
        $record->email = App::$Security->strip_tags($this->email);
27
        $record->message = App::$Security->strip_tags($this->message);
28
        $record->user_id = $this->_userId;
29
        $record->is_admin = 1;
30
31
        $record->ip = $this->_ip;
32
        $record->save();
33
34
        // send email notification
35
        $this->sendEmail($record->getFeedbackPost());
0 ignored issues
show
Documentation introduced by
$record->getFeedbackPost() is of type object<Ffcms\Core\Arch\ActiveModel>|null, but the function expects a object<Apps\ActiveRecord\FeedbackPost>.

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...
36
37
        // unset message data
38
        $this->message = null;
39
    }
40
41
    /**
42
     * Send notification to post owner
43
     * @param FeedbackPost $record
44
     * @throws \Ffcms\Core\Exception\SyntaxException
45
     */
46 View Code Duplication
    public function sendEmail($record)
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...
47
    {
48
        // prepare email template
49
        $template = App::$View->render('feedback/mail/newanswer', [
50
            'record' => $record
51
        ]);
52
53
        // get website default email
54
        $sender = App::$Properties->get('adminEmail');
55
56
        // build swift mailer handler
57
        $mailMessage = \Swift_Message::newInstance(App::$Translate->get('Feedback', 'New answer in request #%id%', ['id' => $record->id]))
58
            ->setFrom([$sender])
59
            ->setTo([$record->email])
60
            ->setBody($template, 'text/html');
61
        // send message over swift instance
62
        App::$Mailer->send($mailMessage);
0 ignored issues
show
Documentation introduced by
$mailMessage is of type object<Swift_Mime_MimePart>, but the function expects a object<Swift_Mime_Message>.

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...
63
    }
64
}