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

Apps/Model/Front/Profile/EntityAddNotification.php (1 issue)

1
<?php
2
3
namespace Apps\Model\Front\Profile;
4
5
use Apps\ActiveRecord\UserNotification;
6
use Ffcms\Core\Arch\Model;
7
8
/**
9
 * Class EntityAddNotification. Add user notification in database table
10
 * @package Apps\Model\Front\Profile
11
 */
12
class EntityAddNotification extends Model
13
{
14
    const MSG_DEFAULT = 'New notification event: &laquo;%snippet%&raquo;';
15
    const MSG_ADD_WALLPOST = 'New post on the wall: &laquo;%snippet%&raquo;';
16
    const MSG_ADD_WALLANSWER = 'New answer &laquo;%snippet%&raquo; for wall post &laquo;%post%&raquo;';
17
    const MSG_ADD_COMMENTANSWER = 'New answer &laquo;%snippet%&raquo; to your comment &laquo;%post%&raquo;';
18
    const MSG_ADD_FEEDBACKANSWER = 'New answer &laquo;%snippet%&raquo; to your feedback request &laquo;%post%&raquo;';
19
    
20
    private $_targetId;
21
22
    /**
23
     * EntityAddNotification constructor. Pass target user_id inside the model
24
     * @param bool $targetId
25
     */
26
    public function __construct($targetId)
27
    {
28
        $this->_targetId = $targetId;
29
        parent::__construct();
30
    }
31
32
    /**
33
     * Add notification for user
34
     * @param string $uri
35
     * @param string $msg
36
     * @param array|null $vars
37
     */
38
    public function add($uri, $msg = self::MSG_DEFAULT, array $vars = null)
39
    {
40
        // save data into database
41
        $record = new UserNotification();
42
        $record->user_id = $this->_targetId;
0 ignored issues
show
Documentation Bug introduced by
The property $user_id was declared of type integer, but $this->_targetId is of type boolean. 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...
43
        $record->uri = $uri;
44
        $record->msg = $msg;
45
        if ($vars !== null) {
46
            $record->vars = $vars;
47
        }
48
49
        $record->save();
50
    }
51
}
52