1 | <?php |
||
56 | class FeedReader |
||
57 | { |
||
58 | /** |
||
59 | * @var Parser[] |
||
60 | */ |
||
61 | protected $parsers = array(); |
||
62 | |||
63 | /** |
||
64 | * @var HttpDriverInterface |
||
65 | */ |
||
66 | protected $driver = null; |
||
67 | |||
68 | /** |
||
69 | * @var Factory |
||
70 | */ |
||
71 | protected $factory = null; |
||
72 | |||
73 | /** |
||
74 | * @var XmlParser |
||
75 | */ |
||
76 | protected $xmlParser = null; |
||
77 | |||
78 | /** |
||
79 | * @param HttpDriverInterface $driver |
||
80 | * @param Factory $factory |
||
81 | */ |
||
82 | 2 | public function __construct(HttpDriverInterface $driver, Factory $factory, XmlParser $xmlParser) |
|
88 | |||
89 | /** |
||
90 | * Add a Parser. |
||
91 | * |
||
92 | * @param Parser $parser |
||
93 | * |
||
94 | * @return FeedReader |
||
95 | */ |
||
96 | 2 | public function addParser(Parser $parser) |
|
103 | |||
104 | /** |
||
105 | * @return HttpDriverInterface |
||
106 | */ |
||
107 | 2 | public function getDriver() |
|
111 | |||
112 | /** |
||
113 | * Read a feed using its url and create a FeedInInterface instance |
||
114 | * Second parameter can be either a \DateTime instance or a numeric limit. |
||
115 | * |
||
116 | * @param string $url |
||
117 | * @param \DateTime $arg |
||
118 | * |
||
119 | * @return FeedInInterface|FeedContent |
||
120 | */ |
||
121 | 4 | public function getFeedContent($url, $arg = null) |
|
122 | { |
||
123 | 4 | if (is_numeric($arg)) { |
|
124 | return $this->getFilteredContent($url, array( |
||
125 | new Filter\Limit($arg), |
||
126 | )); |
||
127 | } |
||
128 | 4 | if ($arg instanceof \DateTime) { |
|
129 | 4 | return $this->getFeedContentSince($url, $arg); |
|
130 | } |
||
131 | |||
132 | return $this->getFilteredContent($url, array()); |
||
133 | } |
||
134 | |||
135 | /** |
||
136 | * @param string $url |
||
137 | * @param array $filters |
||
138 | * @param \DateTime $modifiedSince |
||
139 | * |
||
140 | * @return FeedInInterface |
||
141 | */ |
||
142 | 1 | public function getFilteredContent($url, array $filters, \DateTime $modifiedSince = null) |
|
148 | |||
149 | /** |
||
150 | * @param string $url |
||
151 | * @param \DateTime $modifiedSince |
||
152 | * |
||
153 | * @return FeedInInterface |
||
154 | */ |
||
155 | 1 | public function getFeedContentSince($url, \DateTime $modifiedSince) |
|
163 | |||
164 | /** |
||
165 | * Read a feed using its url and hydrate the given FeedInInterface instance. |
||
166 | * |
||
167 | * @param string $url |
||
168 | * @param FeedInInterface $feed |
||
169 | * @param \DateTime $modifiedSince |
||
170 | * |
||
171 | * @return FeedInInterface |
||
172 | */ |
||
173 | 1 | public function readFeed($url, FeedInInterface $feed, \DateTime $modifiedSince) |
|
183 | |||
184 | /** |
||
185 | * Read the XML stream hosted at $url. |
||
186 | * |
||
187 | * @param $url |
||
188 | * @param \Datetime $modifiedSince |
||
189 | * |
||
190 | * @return HttpDriverResponse |
||
191 | */ |
||
192 | 2 | public function getResponse($url, \Datetime $modifiedSince = null) |
|
200 | |||
201 | /** |
||
202 | * Parse the body of a feed and write it into the FeedInInterface instance. |
||
203 | * |
||
204 | * @param HttpDriverResponse $response |
||
205 | * @param FeedInInterface $feed |
||
206 | * @param array $filters |
||
207 | * |
||
208 | * @return FeedInInterface |
||
209 | */ |
||
210 | 10 | public function parseBody(HttpDriverResponse $response, FeedInInterface $feed, array $filters = array()) |
|
233 | |||
234 | /** |
||
235 | * Choose the accurate Parser for the XML stream. |
||
236 | * |
||
237 | * @param SimpleXMLElement $xmlBody |
||
238 | * |
||
239 | * @throws ParserException |
||
240 | * |
||
241 | * @return Parser |
||
242 | */ |
||
243 | 3 | public function getAccurateParser(SimpleXMLElement $xmlBody) |
|
253 | } |
||
254 |
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.
Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.