Completed
Push — master ( 3cdce8...5b29fc )
by Bruno
11s
created

StandardEntity::getTimestamp()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 0
cts 4
cp 0
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 0
crap 6
1
<?php
2
3
namespace Swader\Diffbot\Traits;
4
5
/**
6
 * Trait StandardEntity
7
 * @package Swader\Diffbot\Traits
8
 * @property $data array
9
 */
10
trait StandardEntity {
11
12
    /**
13
     * Alias for getLang()
14
     * @see getLang()
15
     * @return string
16
     */
17 1
    public function getHumanLanguage()
18
    {
19 1
        return $this->getLang();
20
    }
21
22
    /**
23
     * Returns the human language of the page as determined by Diffbot when looking at content.
24
     * The code returned is a two-character ISO 639-1 code: http://en.wikipedia.org/wiki/List_of_ISO_639-1_codes
25
     * @return string
26
     */
27 1
    public function getLang()
28
    {
29 1
        return $this->data['humanLanguage'];
30
    }
31
32
    /**
33
     * Returns the URL which was crawled
34
     * @return string
35
     */
36 2
    public function getPageUrl()
37
    {
38 2
        return $this->data['pageUrl'];
39
    }
40
41
    /**
42
     * Returns page Url which was resolved by redirects, if any.
43
     * For example, crawling a bitly link will make this method return the ultimate destination's URL
44
     * @return string
45
     */
46 1
    public function getResolvedPageUrl()
47
    {
48 1
        return (isset($this->data['resolvedPageUrl'])) ? $this->data['resolvedPageUrl'] : $this->getPageUrl();
49
    }
50
51
    /**
52
     * Returns title of article as deduced by Diffbot
53
     * @return string
54
     */
55 1
    public function getTitle()
56
    {
57 1
        return $this->data['title'];
58
    }
59
60
    /**
61
     * Returns an array of all links found on the crawled page.
62
     *
63
     * Only available in the standard APIs, not Custom APIs
64
     * @return array|null
65
     */
66 1
    public function getLinks()
67
    {
68 1
        return (isset($this->data['links'])) ? $this->data['links'] : null;
69
    }
70
71
    /**
72
     * Returns a top-level object (meta) containing the full contents of page meta tags,
73
     * including sub-arrays for OpenGraph tags, Twitter Card metadata, schema.org microdata,
74
     * and -- if available -- oEmbed metadata.
75
     *
76
     * Only available in the standard APIs, not Custom APIs
77
     * @return array|null
78
     */
79 1
    public function getMeta()
80
    {
81 1
        return (isset($this->data['meta'])) ? $this->data['meta'] : null;
82
    }
83
84
    /**
85
     * Returns any key/value pairs present in the URL querystring.
86
     * Items without a discrete value will be returned as true.
87
     *
88
     * Only available in the standard APIs, not Custom APIs
89
     * @return array|null
90
     */
91 1
    public function getQueryString()
92
    {
93 1
        return (isset($this->data['queryString'])) ? $this->data['queryString'] : null;
94
    }
95
96
    /**
97
     * Returns a top-level array (breadcrumb) of URLs and link text from page breadcrumbs.
98
     *
99
     * Only available in the standard APIs, not Custom APIs
100
     * @return array|null
101
     */
102 1
    public function getBreadcrumb()
103
    {
104 1
        return (isset($this->data['breadcrumb'])) ? $this->data['breadcrumb'] : null;
105
    }
106
107
    /**
108
     * An internal identifier for Diffbot, used for indexing in their databases
109
     * @return string
110
     */
111 1
    public function getDiffbotUri()
112
    {
113 1
        return $this->data['diffbotUri'];
114
    }
115
116
    /**
117
     * Returns the timestamp from the point in time the page was indexed by the engine
118
     * Example date: "Wed, 18 Dec 2013 00:00:00 GMT"
119
     * This will be a Carbon (https://github.com/briannesbitt/Carbon) instance if Carbon is installed.
120
     * @return \Carbon\Carbon | string
121
     */
122
    public function getTimestamp()
123
    {
124
        return (class_exists('\Carbon\Carbon')) ?
125
            new \Carbon\Carbon($this->data['timestamp'], 'GMT') :
126
            $this->data['timestamp'];
127
    }
128
129 24
    protected function getOrDefault($key, $default = null, $data = null)
130
    {
131 24
        $data = ($data !== null) ?: $this->data;
132 24
        return (isset($data[$key]) ? $data[$key] : $default);
133
    }
134
135
}
136