1 | <?php |
||
14 | class Crawler |
||
15 | { |
||
16 | /** |
||
17 | * Base URL of AA API |
||
18 | */ |
||
19 | const API_BASE_URL = 'https://api.aa.com.tr'; |
||
20 | |||
21 | /** |
||
22 | * @var string |
||
23 | */ |
||
24 | protected $user_name = ''; |
||
25 | |||
26 | /** |
||
27 | * @var string |
||
28 | */ |
||
29 | protected $password = ''; |
||
30 | |||
31 | /** |
||
32 | * @var int |
||
33 | */ |
||
34 | protected $summary_length = 150; |
||
35 | |||
36 | /** |
||
37 | * @var array |
||
38 | */ |
||
39 | protected $attributes = [ |
||
40 | 'filter_language' => '1', |
||
41 | 'filter_type' => '1', |
||
42 | 'limit' => '5', |
||
43 | ]; |
||
44 | |||
45 | /** |
||
46 | * @var array |
||
47 | */ |
||
48 | protected $auth = ['', '']; |
||
49 | |||
50 | /** |
||
51 | * Create a new Crawler Instance |
||
52 | */ |
||
53 | public function __construct($config) |
||
57 | |||
58 | /** |
||
59 | * @param array $attributes |
||
60 | * @return array |
||
61 | */ |
||
62 | public function crawl($attributes = []) |
||
82 | |||
83 | |||
84 | /** |
||
85 | * Creates a news object from NewsML SimpleXmlElement instance. |
||
86 | * @param \SimpleXMLElement $xml |
||
87 | * @return \stdClass |
||
88 | */ |
||
89 | protected function newsmlToNews($xml) |
||
112 | |||
113 | /** |
||
114 | * Creates document link for next requests. |
||
115 | * @param string $id |
||
116 | * @param string $format |
||
117 | * @return string |
||
118 | */ |
||
119 | protected function getDocumentLink($id, $format) |
||
123 | |||
124 | /** |
||
125 | * Fetches NewsML document, creates a SimpleXMLElement instance and returns it. |
||
126 | * @param $id |
||
127 | * @return null|\SimpleXMLElement |
||
128 | */ |
||
129 | protected function document($id) |
||
137 | |||
138 | /** |
||
139 | * Searchs documents with given filter attributes. |
||
140 | * @return mixed |
||
141 | */ |
||
142 | protected function search() |
||
161 | |||
162 | /** |
||
163 | * Creates short summary of the news, strip credits. |
||
164 | * @param string $text |
||
165 | * @return string |
||
166 | */ |
||
167 | protected function createSummary($text) |
||
180 | |||
181 | /** |
||
182 | * Sets config parameters. |
||
183 | * @param $config |
||
184 | */ |
||
185 | protected function setParameters($config) |
||
199 | |||
200 | /** |
||
201 | * Sets filter attributes. |
||
202 | * @param $attributes array |
||
203 | */ |
||
204 | protected function setAttributes($attributes) |
||
210 | |||
211 | |||
212 | /** |
||
213 | * Fethches given url and returns response as string. |
||
214 | * @param string $url |
||
215 | * @param string $method |
||
216 | * @param array $options |
||
217 | * |
||
218 | * @return string |
||
219 | */ |
||
220 | protected function fetchUrl($url, $method = 'GET', $options = []) |
||
229 | |||
230 | /** |
||
231 | * Cuts the given string from the end of the appropriate word. |
||
232 | * @param string $str |
||
233 | * @param int $len |
||
234 | * @return string |
||
235 | */ |
||
236 | protected function shortenString($str, $len) |
||
246 | |||
247 | /** |
||
248 | * Converts a string to "Title Case" |
||
249 | * @param $str |
||
250 | * @return string |
||
251 | */ |
||
252 | protected function titleCase($str) |
||
257 | } |
||
258 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.