Discussion::getType()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Swader\Diffbot\Entity;
4
5
use Swader\Diffbot\Abstracts\Entity;
6
use Swader\Diffbot\Traits\StandardEntity;
7
8
class Discussion extends Entity
9
{
10
    use StandardEntity;
11
12
    protected $posts = [];
13
14 67
    public function __construct(array $data)
15
    {
16 67
        parent::__construct($data);
17 67
        foreach ($this->data['posts'] as $post) {
18 67
            $this->posts[] = new Post($post);
19 67
        }
20 67
        $this->data['posts'] = $this->posts;
21 67
    }
22
23
    /**
24
     * Should always return "discussion"
25
     * @return string
26
     */
27 1
    public function getType()
28
    {
29 1
        return $this->data['type'];
30
    }
31
32
    /**
33
     * Number of individual posts in the thread
34
     * @return int
35
     */
36 1
    public function getNumPosts()
37
    {
38 1
        return (int)$this->data['numPosts'];
39
    }
40
41
    /**
42
     * Array containing all tags that Diffbot's AI concluded match the content.
43
     *
44
     * Note that these are *not* the meta tags as defined by the creator of the
45
     * content, but machine learned ones. The format of the array is:
46
     *
47
     * [
48
     *  [
49
     *      "id": 133907,
50
     *      "count": 3,
51
     *      "prevalence": 0.3103448275862069,
52
     *      "label": "Apache HTTP Server",
53
     *      "type": "Http://www.ontologydesignpatterns.org/ont/dul/DUL.owl#InformationEntity",
54
     *      "uri": "http://dbpedia.org/resource/Apache_HTTP_Server"
55
     *  ],
56
     *  [
57
     *      "id": 208652,
58
     *      "count": 5,
59
     *      "prevalence": 0.5172413793103449,
60
     *      "label": "PHP",
61
     *      "type": "Http://www.ontologydesignpatterns.org/ont/dul/DUL.owl#InformationEntity",
62
     *      "uri": "http://dbpedia.org/resource/PHP"
63
     *  ]
64
     * ]
65
     *
66
     * @return array
67
     */
68 1
    public function getTags()
69
    {
70 1
        return $this->data['tags'];
71
    }
72
73
    /**
74
     * Number of unique participants in the discussion thread or comments
75
     *
76
     * @return int
77
     */
78 1
    public function getParticipants()
79
    {
80 1
        return (int)$this->data['participants'];
81
    }
82
83
    /**
84
     * Number of pages in the thread concatenated to form the posts response.
85
     * Use maxPages to define how many pages to concatenate.
86
     * @see http://support.diffbot.com/automatic-apis/handling-multiple-page-articles/
87
     * @return int
88
     */
89 1
    public function getNumPages()
90
    {
91 1
        return (isset($this->data['numPages'])) ? $this->data['numPages'] : 1;
92
    }
93
94
    /**
95
     * Array of all page URLs concatenated in a multipage discussion.
96
     * Empty array if article was not concatenated before being returned.
97
     * @see http://support.diffbot.com/automatic-apis/handling-multiple-page-articles/
98
     * @return array
99
     */
100 1
    public function getNextPages()
101
    {
102 1
        return (isset($this->data['nextPages'])) ? $this->data['nextPages'] : [];
103
    }
104
105
    /**
106
     * If discussion spans multiple pages, nextPage will return the subsequent
107
     * page URL.
108
     * @return string|null
109
     */
110 1
    public function getNextPage()
111
    {
112 1
        return (isset($this->data['nextPage'])) ? $this->data['nextPage'] : null;
113
    }
114
115
    /**
116
     * Discussion service provider (e.g., Disqus, Facebook), if known.
117
     * @return string|null
118
     */
119 1
    public function getProvider()
120
    {
121 1
        return (isset($this->data['provider'])) ? $this->data['provider'] : null;
122
    }
123
124
    /**
125
     * URL of the discussion's RSS feed, if available.
126
     * @return string|null
127
     */
128 1
    public function getRssUrl()
129
    {
130 1
        return (isset($this->data['rssUrl'])) ? $this->data['rssUrl'] : null;
131
    }
132
133
    /**
134
     * @todo find out what this is
135
     * @return float|null
136
     */
137 1
    public function getConfidence()
138
    {
139 1
        return (isset($this->data['confidence'])) ? (float)$this->data['confidence'] : null;
140
    }
141
142
    /**
143
     * Returns an array of posts or comments in discussion.
144
     * Each post is a Post entity.
145
     *
146
     * @see Post
147
     * @return array
148
     */
149 15
    public function getPosts()
150
    {
151 15
        return $this->posts;
152
    }
153
154
}