1 | <?php |
||
16 | class bbcodes extends base |
||
17 | { |
||
18 | /** @var config */ |
||
19 | protected $config; |
||
20 | |||
21 | /** @var bbcodes_legacy */ |
||
22 | protected $trim_bbcodes_legacy; |
||
23 | |||
24 | /** @var utils|null */ |
||
25 | protected $text_formatter_utils; |
||
26 | |||
27 | /** @var array Data array of BBCodes to remove */ |
||
28 | protected $data; |
||
29 | |||
30 | /** |
||
31 | * Constructor |
||
32 | * |
||
33 | * @param config $config Config object |
||
34 | * @param bbcodes_legacy $trim_bbcodes_legacy Legacy BBCodes trim tool |
||
35 | * @param utils|null $text_formatter_utils Text Formatter Utils |
||
36 | */ |
||
37 | 38 | public function __construct(config $config, bbcodes_legacy $trim_bbcodes_legacy, utils $text_formatter_utils = null) |
|
43 | |||
44 | /** |
||
45 | * @inheritdoc |
||
46 | */ |
||
47 | 38 | public function is_available() |
|
51 | |||
52 | /** |
||
53 | * @inheritdoc |
||
54 | */ |
||
55 | 12 | public function run() |
|
67 | |||
68 | /** |
||
69 | * @inheritdoc |
||
70 | */ |
||
71 | 12 | public function set_data() |
|
81 | |||
82 | /** |
||
83 | * Remove specified BBCodes and their contents |
||
84 | * |
||
85 | * @return string Stripped message text |
||
86 | */ |
||
87 | 12 | protected function process() |
|
96 | |||
97 | /** |
||
98 | * Is the message s9e formatted |
||
99 | * |
||
100 | * @return bool True if message is s9e formatted, false otherwise |
||
101 | */ |
||
102 | 12 | protected function s9e_format() |
|
106 | } |
||
107 |
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: