Completed
Branch develop (c4337b)
by Romain
01:55
created

Postback   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 1
dl 0
loc 52
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getPayload() 0 4 1
A getReferral() 0 4 1
A create() 0 6 2
1
<?php
2
namespace Kerox\Messenger\Model\Callback;
3
4
class Postback
5
{
6
7
    /**
8
     * @var string
9
     */
10
    protected $payload;
11
12
    /**
13
     * @var null|\Kerox\Messenger\Model\Callback\Messaging\Referral
14
     */
15
    protected $referral;
16
17
    /**
18
     * Postback constructor.
19
     *
20
     * @param string $payload
21
     * @param \Kerox\Messenger\Model\Callback\Messaging\Referral $referral
22
     */
23
    public function __construct(string $payload, Referral $referral = null)
24
    {
25
        $this->payload = $payload;
26
        $this->referral = $referral;
0 ignored issues
show
Documentation Bug introduced by
It seems like $referral can also be of type object<Kerox\Messenger\Model\Callback\Referral>. However, the property $referral is declared as type null|object<Kerox\Messen...ack\Messaging\Referral>. 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...
27
    }
28
29
    /**
30
     * @return string
31
     */
32
    public function getPayload(): string
33
    {
34
        return $this->payload;
35
    }
36
37
    /**
38
     * @return null|\Kerox\Messenger\Model\Callback\Messaging\Referral
39
     */
40
    public function getReferral()
41
    {
42
        return $this->referral;
43
    }
44
45
    /**
46
     * @param array $payload
47
     * @return static
48
     */
49
    public static function create(array $payload)
50
    {
51
        $referral = isset($payload['referral']) ? Referral::create($payload['referral']) : null;
52
53
        return new static($payload['payload'], $referral);
54
    }
55
}
56