1 | <?php |
||
5 | class IMAPMessage extends IMAPMessageContent implements IMAPMessagePartInterface { |
||
6 | |||
7 | /** @var IMAPMailbox */ |
||
8 | protected $mailbox; |
||
9 | |||
10 | /** @var int */ |
||
11 | protected $msgNumber = 1; // Body starts at 1. Header is 0. |
||
12 | |||
13 | /** @var bool */ |
||
14 | protected $unseen = true; |
||
15 | |||
16 | /** @var string[] */ |
||
17 | protected $headers = []; |
||
18 | |||
19 | /** @var string */ |
||
20 | protected $subject = ''; |
||
21 | |||
22 | /** @var string */ |
||
23 | protected $subtype = ''; |
||
24 | |||
25 | public function __construct( IMAPMailbox $mailbox, $msgNumber, $unseen = null ) { |
||
34 | |||
35 | /** @return bool|bool[] */ |
||
36 | protected function flags( $flags, $clear ) { |
||
47 | |||
48 | /** @return bool|bool[] */ |
||
49 | public function flag( $flags ) { |
||
52 | |||
53 | /** @return bool|bool[] */ |
||
54 | public function unflag( $flags ) { |
||
57 | |||
58 | /** @return int */ |
||
59 | public function utc() { |
||
62 | |||
63 | /** @return string */ |
||
64 | public function subject() { |
||
72 | |||
73 | /** @return string */ |
||
74 | public function headerString() { |
||
77 | |||
78 | /** @return IMAPMessagePart */ |
||
79 | public function createMessagePart( $structure, $section ) { |
||
82 | |||
83 | /** @return IMAPMessagePart[] */ |
||
84 | public function parts() { |
||
117 | |||
118 | /** @return object */ |
||
119 | public function structure() { |
||
126 | |||
127 | /** @return string */ |
||
128 | public function subtype() { |
||
136 | |||
137 | /** @return int[] */ |
||
138 | public function section() { |
||
141 | |||
142 | /** @return string */ |
||
143 | public function content() { |
||
150 | |||
151 | /** @return string */ |
||
152 | public function decodedContent() { |
||
159 | |||
160 | /** @return bool */ |
||
161 | public function delete() { |
||
164 | |||
165 | /** @return string[] */ |
||
166 | public function simpleStructure() { |
||
190 | |||
191 | /** @return int */ |
||
192 | public function msgNumber() { |
||
195 | |||
196 | /** @return IMAPMailbox */ |
||
197 | public function mailbox() { |
||
200 | |||
201 | } |
||
202 |
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the interface: