Passed
Push — master ( c7b0bf...abc1fb )
by Rougin
03:54
created

Crawler   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 90.91%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 12
c 1
b 0
f 0
dl 0
loc 34
ccs 10
cts 11
cp 0.9091
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A crawl() 0 19 2
1
<?php
2
3
namespace Pilipinews\Website\Bulletin;
4
5
use Pilipinews\Common\Client;
6
use Pilipinews\Common\Crawler as DomCrawler;
7
use Pilipinews\Common\Interfaces\CrawlerInterface;
8
9
/**
10
 * Manila Bulletin Crawler
11
 *
12
 * @package Pilipinews
13
 * @author  Rougin Gutib <[email protected]>
14
 */
15
class Crawler implements CrawlerInterface
16
{
17
    /**
18
     * @var string[]
19
     */
20
    protected $categories = array(
21
        'https://mb.com.ph/category/news/national/',
22
        'https://mb.com.ph/category/news/metro/',
23
    );
24
25
    /**
26
     * Returns an array of articles to scrape.
27
     *
28
     * @return string[]
29
     */
30 3
    public function crawl()
31
    {
32 3
        $articles = array();
33
34 3
        foreach ((array) $this->categories as $link)
35
        {
36 3
            $crawler = new DomCrawler(Client::request($link));
37
38 3
            $news = $crawler->filter('.uk-grid .uk-article');
39
40 3
            $items = $news->each(function (DomCrawler $node)
41
            {
42
                return $node->attr('data-permalink');
43 3
            });
44
45 1
            $articles = array_merge($articles, $items);
46 1
        }
47
48 1
        return array_reverse((array) $articles);
49
    }
50
}
51