Test Failed
Push — master ( e3c39f...fe570d )
by Mihail
07:20
created

FormAnswerAdd   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 23
dl 0
loc 42
rs 10
c 0
b 0
f 0
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A make() 0 37 4
1
<?php
2
3
namespace Apps\Model\Admin\Feedback;
4
5
use Apps\ActiveRecord\FeedbackAnswer;
6
use Apps\Model\Front\Feedback\FormAnswerAdd as FrontAnswer;
7
use Apps\Model\Front\Profile\EntityAddNotification;
8
use Ffcms\Core\App;
9
use Ffcms\Core\Helper\Text;
10
11
/**
12
 * Class FormAnswerAdd. Extend front model add answer
13
 * @package Apps\Model\Admin\Feedback
14
 */
15
class FormAnswerAdd extends FrontAnswer
16
{
17
    /**
18
     * @inheritdoc
19
     */
20
    public function make()
21
    {
22
        // update readed marker
23
        $this->_post->readed = 1;
0 ignored issues
show
Documentation Bug introduced by Mihail
The property $readed was declared of type boolean, but 1 is of type integer. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
24
        $this->_post->save();
25
26
        // add new answer row in database
27
        $record = new FeedbackAnswer();
28
        $record->feedback_id = $this->_post->id;
29
        $record->name = $this->name;
30
        $record->email = $this->email;
31
        $record->message = $this->message;
32
        $record->user_id = $this->_userId;
33
        $record->is_admin = 1;
0 ignored issues
show
Documentation Bug introduced by Mihail
The property $is_admin was declared of type boolean, but 1 is of type integer. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
34
35
        $record->ip = $this->_ip;
36
        $record->save();
37
38
        // add user notification
39
        if ((int)$this->_post->user_id > 0 && $this->_userId !== (int)$this->_post->user_id) {
40
            $notify = new EntityAddNotification((int)$this->_post->user_id);
0 ignored issues
show
Bug introduced by zenn
(int)$this->_post->user_id of type integer is incompatible with the type boolean expected by parameter $targetId of Apps\Model\Front\Profile...fication::__construct(). ( Ignorable by Annotation )

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

40
            $notify = new EntityAddNotification(/** @scrutinizer ignore-type */ (int)$this->_post->user_id);
Loading history...
41
            $uri = '/feedback/read/' . $this->_post->id . '/' . $this->_post->hash . '#feedback-answer-' . $record->id;
42
43
            $notify->add($uri, EntityAddNotification::MSG_ADD_FEEDBACKANSWER, [
44
                'snippet' => Text::snippet($this->message, 50),
45
                'post' => Text::snippet($this->_post->message, 50)
46
            ]);
47
        }
48
        if (App::$Mailer) {
49
            // send email notification
50
            App::$Mailer->tpl('feedback/mail/newanswer', [
51
                'record' => $record
52
            ])->send($record->email, App::$Translate->get('Feedback', 'New answer in request #%id%', ['id' => $record->id]));
53
        }
54
55
        // unset message data
56
        $this->message = null;
57
    }
58
}
59