GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

LobPostcard   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 134
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 12
lcom 1
cbo 1
dl 0
loc 134
ccs 0
cts 33
cp 0
rs 10
c 0
b 0
f 0

10 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 4 1
A __construct() 0 4 1
A fromAddress() 0 6 2
A toAddress() 0 6 2
A front() 0 6 1
A message() 0 6 1
A size() 0 6 1
A size4x6() 0 6 1
A size6x11() 0 6 1
A toArray() 0 10 1
1
<?php
2
3
namespace NotificationChannels\Lob;
4
5
class LobPostcard
6
{
7
    /** @var string */
8
    public $type = 'postcards';
9
10
    /** @var string|null */
11
    protected $fromAddress = null;
12
13
    /** @var string|null */
14
    protected $toAddress = null;
15
16
    /** @var string */
17
    protected $front;
18
19
    /** @var string */
20
    protected $message;
21
22
    /** @var string */
23
    protected $size = '4x6';
24
25
    /**
26
     * @param string $message
27
     *
28
     * @return static
29
     */
30
    public static function create($message = '')
31
    {
32
        return new static($message);
33
    }
34
35
    /**
36
     * @param string $message
37
     */
38
    public function __construct($message = '')
39
    {
40
        $this->message = $message;
41
    }
42
43
    /**
44
     * @param string|LobAddress $value
45
     *
46
     * @return $this
47
     */
48
    public function fromAddress($value)
49
    {
50
        $this->fromAddress = is_string($value) ? $value : $value->toArray();
0 ignored issues
show
Documentation Bug introduced by
It seems like is_string($value) ? $value : $value->toArray() can also be of type array. However, the property $fromAddress is declared as type string|null. 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...
51
52
        return $this;
53
    }
54
55
    /**
56
     * @param string|LobAddress $value
57
     *
58
     * @return $this
59
     */
60
    public function toAddress($value)
61
    {
62
        $this->toAddress = is_string($value) ? $value : $value->toArray();
0 ignored issues
show
Documentation Bug introduced by
It seems like is_string($value) ? $value : $value->toArray() can also be of type array. However, the property $toAddress is declared as type string|null. 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...
63
64
        return $this;
65
    }
66
67
    /**
68
     * @param mixed $front
69
     *
70
     * @return $this
71
     */
72
    public function front($front)
73
    {
74
        $this->front = $front;
75
76
        return $this;
77
    }
78
79
    /**
80
     * @param string $message
81
     *
82
     * @return $this
83
     */
84
    public function message($message)
85
    {
86
        $this->message = $message;
87
88
        return $this;
89
    }
90
91
    /**
92
     * @param string $size
93
     *
94
     * @return $this
95
     */
96
    public function size($size)
97
    {
98
        $this->size = $size;
99
100
        return $this;
101
    }
102
103
    /**
104
     * @return $this
105
     */
106
    public function size4x6()
107
    {
108
        $this->size = '4x6';
109
110
        return $this;
111
    }
112
113
    /**
114
     * @return $this
115
     */
116
    public function size6x11()
117
    {
118
        $this->size = '6x11';
119
120
        return $this;
121
    }
122
123
    /**
124
     * Get an array representation of the message.
125
     *
126
     * @return array
127
     */
128
    public function toArray()
129
    {
130
        return array_filter([
131
            'to' => $this->toAddress,
132
            'from' => $this->fromAddress,
133
            'front' => $this->front,
134
            'message' => $this->message,
135
            'size' => $this->size,
136
        ]);
137
    }
138
}
139