1 | <?php |
||
22 | class Chirp |
||
23 | { |
||
24 | |||
25 | /** |
||
26 | * The Database object |
||
27 | * |
||
28 | * @var \MongoDB\Database |
||
29 | */ |
||
30 | private $db = null; |
||
31 | |||
32 | /** |
||
33 | * The instance of TwitterOAuth |
||
34 | * |
||
35 | * @var \Abraham\TwitterOAuth\TwitterOAuth |
||
36 | */ |
||
37 | private $twitter; |
||
38 | |||
39 | /** |
||
40 | * Constructor |
||
41 | * |
||
42 | * Passing $twitterAuthConf and/or $mongoConf it tries to setup them |
||
43 | * |
||
44 | * $twitterAuthConf must contain |
||
45 | * - consumer_key |
||
46 | * - consumer_secret |
||
47 | * - oauth_access_token |
||
48 | * - oauth_access_token_secret |
||
49 | * |
||
50 | * $mongoConf must contain |
||
51 | * - db: the name of mongo database to use |
||
52 | * |
||
53 | * and can contain |
||
54 | * - uri |
||
55 | * - uriOptions |
||
56 | * - driverOptions |
||
57 | * |
||
58 | * used for MongoDB connection |
||
59 | * |
||
60 | * @see \MongoDB\Client for $mongoConf |
||
61 | * @param array $twitterAuthConf |
||
62 | * @param array $mongoDbConf |
||
63 | */ |
||
64 | public function __construct(array $twitterAuthConf = array(), array $mongoDbConf = array()) |
||
73 | |||
74 | /** |
||
75 | * Setup TwitterOAuth |
||
76 | * |
||
77 | * $twitterAuthConf must contain |
||
78 | * - consumer_key |
||
79 | * - consumer_secret |
||
80 | * - oauth_access_token |
||
81 | * - oauth_access_token_secret |
||
82 | * |
||
83 | * @param array $twitterAuthConf |
||
84 | * @return $this |
||
85 | */ |
||
86 | public function setupTwitter(array $twitterAuthConf) |
||
103 | |||
104 | /** |
||
105 | * Setup MongoDB connection |
||
106 | * |
||
107 | * $mongoDbConf must contain |
||
108 | * - db: the name of mongo database to use |
||
109 | * |
||
110 | * and can contain |
||
111 | * - uri |
||
112 | * - uriOptions |
||
113 | * - driverOptions |
||
114 | * |
||
115 | * @see \MongoDB\Client for $mongoConf |
||
116 | * @param array $twitterAuthConf |
||
|
|||
117 | * @param array $mongoDbConf |
||
118 | * @return $this |
||
119 | */ |
||
120 | public function setupMongoDb(array $mongoDbConf) |
||
132 | |||
133 | /** |
||
134 | * Return TwitterOAuth instance |
||
135 | * |
||
136 | * @return \Abraham\TwitterOAuth\TwitterOAuth |
||
137 | */ |
||
138 | public function getTwitter() |
||
147 | |||
148 | /** |
||
149 | * Return the instance of MongoDB database |
||
150 | * |
||
151 | * @return \MongoDB\Database |
||
152 | */ |
||
153 | public function getDb() |
||
162 | |||
163 | /** |
||
164 | * Starting from twitter endpoint return the related collection |
||
165 | * It replaces "/" with "-" after removing trailing "/", for example: |
||
166 | * |
||
167 | * endpoint "statuses/user_timeline" corresponds to "statuses-user_timeline" collection |
||
168 | * |
||
169 | * @param string $endpoint [description] |
||
170 | * @return \MongoDB\Collection |
||
171 | */ |
||
172 | public function getCollection($endpoint) |
||
178 | |||
179 | /** |
||
180 | * Perform a Twitter request |
||
181 | * |
||
182 | * @param string $endpoint the endpoint for example 'statuses/user_timeline' |
||
183 | * @param array $query an array that specify query string to use with the endpoint |
||
184 | * @param string $requestMethod the http request method |
||
185 | * @return array |
||
186 | */ |
||
187 | public function request($endpoint, $query = [], $requestMethod = 'get') |
||
199 | |||
200 | /** |
||
201 | * Read results from a collection (default self::collection) |
||
202 | * using $filter to filter results |
||
203 | * |
||
204 | * If $options['limit'] = 1 return a \MongoDB\BSONDocument object |
||
205 | * else return an array or a cursor depending from $options['returnType'] |
||
206 | * |
||
207 | * @param string $endpoint |
||
208 | * @param array $filter |
||
209 | * @param array $options |
||
210 | * @return object|array |
||
211 | */ |
||
212 | public function read($endpoint, array $filter = [], array $options = []) |
||
223 | |||
224 | /** |
||
225 | * Perform twitter request and save results in db. |
||
226 | * |
||
227 | * Possible $options are: |
||
228 | * - query: an array used for compose query string |
||
229 | * - grep: an array used for look up. Results matching the grep criteria will be saved. |
||
230 | * Example |
||
231 | * ``` |
||
232 | * [ |
||
233 | * 'key_to_look_up' => ['match1', 'match2'], |
||
234 | * 'other_key_to_look_up' => ['match3'] |
||
235 | * ] |
||
236 | * ``` |
||
237 | * - require: an array of string of keys required. |
||
238 | * Only results with those fields will be saved. |
||
239 | * Use point separtated string to go deep in results, for example |
||
240 | * `'key1.key2.key3'` checks against`[ 'key1' => ['key2' => ['key3' => 'some_value']]] ` |
||
241 | * |
||
242 | * @param string $endpoint the twitter endpoint for example 'statuses/user_timeline' |
||
243 | * @param array $options |
||
244 | * @return array |
||
245 | */ |
||
246 | public function write($endpoint, array $options = []) |
||
269 | |||
270 | /** |
||
271 | * Check and return $options to be used in self::write() |
||
272 | * |
||
273 | * @param string $endpoint the twitter endpoint for example 'statuses/user_timeline' |
||
274 | * @param array $options |
||
275 | * @return array |
||
276 | */ |
||
277 | private function prepareWriteOptions($options) |
||
292 | |||
293 | /** |
||
294 | * Given an array of tweets and a collection |
||
295 | * return the tweets that missing from the collection |
||
296 | * |
||
297 | * @see self::write() for $options |
||
298 | * @param array $tweets |
||
299 | * @param \MongoDB\Collection $collection |
||
300 | * @param array $options |
||
301 | * @return array |
||
302 | */ |
||
303 | private function filterToSave(array $tweets, \MongoDB\Collection $collection, array $options) |
||
318 | } |
||
319 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.