HAtomAdapter::extractTitle()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 7

Duplication

Lines 14
Ratio 100 %

Importance

Changes 0
Metric Value
dl 14
loc 14
rs 9.4285
c 0
b 0
f 0
nc 1
cc 1
eloc 7
nop 1
1
<?php
2
3
namespace Zrashwani\NewsScrapper\Adapters;
4
5
use \Symfony\Component\DomCrawler\Crawler;
6
7
/**
8
 * Adapter to extract news base on microdata format base on hAtom microformats specifications
9
 * @link http://microformats.org/wiki/hatom draft microformat specification
10
 * @author Zeid Rashwani <zrashwani.com>
11
 */
12
class HAtomAdapter extends AbstractAdapter
13
{
14 View Code Duplication
    public function extractTitle(Crawler $crawler)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
15
    {
16
        $ret = null;
17
18
        $crawler->filter('.hentry .entry-title')
19
            ->each(
20
                function(Crawler $node) use (&$ret) {
21
                        $ret = $node->text();
22
                }
23
            );
24
25
26
        return $ret;
27
    }
28
29
    public function extractImage(Crawler $crawler)
30
    {
31
        $ret = $this->getSrcByImgSelector($crawler, '.entry-thumbnail img');
32
        return $ret;
33
    }
34
35 View Code Duplication
    public function extractDescription(Crawler $crawler)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
36
    {
37
        $ret = null;
38
39
        $crawler->filter('.hentry .entry-summary')
40
            ->each(
41
                function(Crawler $node) use (&$ret) {
42
                        $ret = $node->text();
43
                }
44
            );
45
46
        return $ret;
47
    }
48
49 View Code Duplication
    public function extractKeywords(Crawler $crawler)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
50
    {
51
        $ret = array();
52
53
        $crawler->filter('.hentry a[rel="tag"]')
54
            ->each(
55
                function(Crawler $node) use (&$ret) {
56
                        $ret[] = $node->text();
57
                }
58
            );
59
60
        return $ret;
61
    }
62
63 View Code Duplication
    public function extractBody(Crawler $crawler)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
64
    {
65
        $ret = null;
66
        $crawler->filter(".hentry .entry-content")
67
            ->each(
68
                function(Crawler $node) use (&$ret) {
69
                        $ret = $this->normalizeHtml($node->html());
70
                }
71
            );
72
73
        return $ret;
74
    }
75
76 View Code Duplication
    public function extractPublishDate(Crawler $crawler)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
77
    {
78
        $date_str = null;
79
80
        $crawler->filter('time.published, .hentry .entry-date')
81
            ->each(
82
                function(Crawler $node) use (&$date_str) {
83
                        $date_str = $node->attr('datetime');
84
                }
85
            );
86
87
        if (!is_null($date_str)) {
88
            $ret = new \DateTime($date_str);
89
            return $ret->format(\DateTime::ISO8601);
90
        }
91
    }
92
93 View Code Duplication
    public function extractAuthor(Crawler $crawler)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
94
    {
95
        $ret = null;
96
        $crawler->filter('.hentry .author.vcard')
97
            ->each(
98
                function(Crawler $node) use (&$ret) {
99
                        $ret = $node->text();
100
                }
101
            );
102
103
        return $ret;
104
    }
105
}
106