1 | <?php |
||
13 | abstract class FilteredHttpResponseParser implements ResponseParser { |
||
14 | |||
15 | /** |
||
16 | * @var HttpRequest |
||
17 | */ |
||
18 | protected $httpRequest; |
||
19 | |||
20 | /** |
||
21 | * @var FilteredRecord |
||
22 | */ |
||
23 | protected $filteredRecord; |
||
24 | |||
25 | /** |
||
26 | * @var array |
||
27 | */ |
||
28 | private $messages = array(); |
||
29 | |||
30 | /** |
||
31 | * @since 0.1 |
||
32 | * |
||
33 | * @param HttpRequest $httpRequest |
||
34 | * @param FilteredRecord $filteredRecord |
||
35 | */ |
||
36 | 23 | public function __construct( HttpRequest $httpRequest, FilteredRecord $filteredRecord ) { |
|
40 | |||
41 | /** |
||
42 | * @since 0.1 |
||
43 | * |
||
44 | * @param string[] $message |
||
45 | */ |
||
46 | 1 | public function addMessage( $message ) { |
|
49 | |||
50 | /** |
||
51 | * @since 0.1 |
||
52 | * |
||
53 | * {@inheritDoc} |
||
54 | */ |
||
55 | 6 | public function getMessages() { |
|
58 | |||
59 | /** |
||
60 | * @since 0.1 |
||
61 | * |
||
62 | * {@inheritDoc} |
||
63 | */ |
||
64 | 21 | public function getFilteredRecord() { |
|
67 | |||
68 | /** |
||
69 | * @since 0.1 |
||
70 | * |
||
71 | * {@inheritDoc} |
||
72 | */ |
||
73 | 1 | public function usesCache() { |
|
76 | |||
77 | /** |
||
78 | * @since 0.1 |
||
79 | * |
||
80 | * {@inheritDoc} |
||
81 | */ |
||
82 | 1 | public function isFromCache() { |
|
85 | |||
86 | /** |
||
87 | * @since 0.1 |
||
88 | * |
||
89 | * {@inheritDoc} |
||
90 | */ |
||
91 | public function doFilterResponseFor( $id ) { |
||
94 | |||
95 | /** |
||
96 | * @since 0.1 |
||
97 | * |
||
98 | * {@inheritDoc} |
||
99 | */ |
||
100 | public function getRawResponse( $id ) { |
||
103 | |||
104 | /** |
||
105 | * @since 0.3 |
||
106 | * |
||
107 | * {@inheritDoc} |
||
108 | */ |
||
109 | abstract public function doFilterResponseById( $id ); |
||
110 | |||
111 | /** |
||
112 | * @since 0.3 |
||
113 | * |
||
114 | * {@inheritDoc} |
||
115 | */ |
||
116 | abstract public function getRawResponseById( $id ); |
||
117 | |||
118 | } |
||
119 |
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: