1 | <?php |
||
5 | class IMAPMessage extends IMAPMessageContent implements IMAPMessagePartInterface { |
||
6 | |||
7 | /** @var IMAPMailbox */ |
||
8 | protected $mailbox; |
||
9 | |||
10 | /** @var int */ |
||
11 | protected $msgNumber = 1; // starts at 1, not 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 headers() { |
||
81 | |||
82 | /** @return string */ |
||
83 | public function header( $name ) { |
||
87 | |||
88 | /** @return IMAPMessagePart */ |
||
89 | public function createMessagePart( $structure, $section ) { |
||
92 | |||
93 | /** @return IMAPMessagePart[] */ |
||
94 | public function parts() { |
||
127 | |||
128 | /** @return object */ |
||
129 | public function structure() { |
||
136 | |||
137 | /** @return string */ |
||
138 | public function subtype() { |
||
146 | |||
147 | /** @return int[] */ |
||
148 | public function section() { |
||
151 | |||
152 | /** @return string */ |
||
153 | public function content() { |
||
160 | |||
161 | /** @return string */ |
||
162 | public function decodedContent() { |
||
169 | |||
170 | /** @return bool */ |
||
171 | public function delete() { |
||
174 | |||
175 | /** @return string[] */ |
||
176 | public function simpleStructure() { |
||
200 | |||
201 | /** @return int */ |
||
202 | public function msgNumber() { |
||
205 | |||
206 | /** @return IMAPMailbox */ |
||
207 | public function mailbox() { |
||
210 | |||
211 | } |
||
212 |
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: