Conditions | 3 |
Paths | 1 |
Total Lines | 29 |
Code Lines | 13 |
Lines | 0 |
Ratio | 0 % |
Tests | 16 |
CRAP Score | 3 |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
27 | 3 | public function crawl() |
|
28 | { |
||
29 | 3 | $link = 'https://newsinfo.inquirer.net/category/latest-stories'; |
|
30 | |||
31 | 3 | $response = Client::request($link); |
|
32 | |||
33 | 3 | $allowed = (array) $this->allowed; |
|
34 | |||
35 | 3 | $callback = function (DomCrawler $node) use ($allowed) |
|
36 | { |
||
37 | 3 | $category = $node->filter('#ch-cat')->first(); |
|
38 | |||
39 | 3 | if (! $category->count()) |
|
40 | 1 | { |
|
41 | 3 | return null; |
|
42 | } |
||
43 | |||
44 | 3 | $allowed = in_array($category->text(), $allowed); |
|
45 | |||
46 | 3 | $link = $node->filter('a')->first(); |
|
47 | |||
48 | 3 | return $allowed ? $link->attr('href') : null; |
|
49 | 3 | }; |
|
50 | |||
51 | 1 | $crawler = new DomCrawler((string) $response); |
|
52 | |||
53 | 1 | $news = $crawler->filter('#inq-channel-left > #ch-ls-box'); |
|
54 | |||
55 | 1 | return array_values(array_filter($news->each($callback))); |
|
56 | } |
||
58 |