Issues (39)

src/Models/ActivitiesTable/ActivityTrait.php (3 issues)

1
<?php
2
3
namespace Nip\MailModule\Models\ActivitiesTable;
4
5
use Nip\Records\Traits\AbstractTrait\RecordTrait as AbstractRecordTrait;
6
7
/**
8
 * Trait ActivityTrait
9
 * @package Nip\Mail\Models\ActivitiesTable
10
 *
11
 * @property string $values
12
 */
13
trait ActivityTrait
14
{
15
    use AbstractRecordTrait;
16
17
    /**
18
     * @param bool|array $data
19
     * @return
20
     */
21
    public function writeDBData($data = [])
22
    {
23
        $this->values = (isset($data['values'])) ? unserialize($data['values']) : [];
0 ignored issues
show
Documentation Bug introduced by
It seems like IssetNode ? unserialize(...ta['values']) : array() can also be of type array. However, the property $values is declared as type string. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
24
25
        return parent::writeDBData($data);
26
    }
27
28
    /**
29
     * @param $notification
30
     */
31
    public function initFromSendGrid($notification)
32
    {
33
        foreach (['smtp-id', 'category', 'email', 'event', 'timestamp'] as $type) {
34
            $varName = $type == 'smtp-id' ? 'smtp_id' : $type;
35
            $this->{$varName} = isset($notification[$type]) ? $notification[$type] : '';
36
            unset($notification[$type]);
37
        }
38
39
        $extraValues = [];
40
        foreach ($notification as $type => $value) {
41
            $extraValues[$type] = $value;
42
        }
43
        $this->values = $extraValues;
0 ignored issues
show
Documentation Bug introduced by
It seems like $extraValues of type array or array is incompatible with the declared type string of property $values.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
44
    }
45
46
    /**
47
     * @return string
48
     */
49
    public function getExtraInfo()
50
    {
51
        $return = [];
52
        foreach ($this->values as $type => $value) {
0 ignored issues
show
The expression $this->values of type string is not traversable.
Loading history...
53
            $return[] = '<strong>' . $type . '</strong> : ' . $value;
54
        }
55
        return implode("<br />", $return);
56
    }
57
58
    /**
59
     * @return bool
60
     */
61
    public function insert()
62
    {
63
        $values = $this->values;
64
        $this->values = serialize($this->values);
65
66
        $return = parent::insert();
67
        $this->values = $values;
68
        return $return;
69
    }
70
71
    /**
72
     * @return bool|\Nip\Database\Result
73
     */
74
    public function update()
75
    {
76
        $values = $this->values;
77
        $this->values = serialize($this->values);
78
        $return = parent::update();
79
        $this->values = $values;
80
        return $return;
81
    }
82
}
83