Completed
Push — master ( 5decb7...aee104 )
by Thibaud
14:37 queued 11:26
created

FeedEntry::getItems()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 3.576

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 8
ccs 3
cts 5
cp 0.6
rs 9.4285
cc 3
eloc 4
nc 4
nop 0
crap 3.576
1
<?php
2
3
/*
4
 * This file is part of Phraseanet SDK.
5
 *
6
 * (c) Alchemy <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace PhraseanetSDK\Entity;
13
14
use Doctrine\Common\Collections\ArrayCollection;
15
16
class FeedEntry
17
{
18
19
    /**
20
     * @param \stdClass[] $values
21
     * @return FeedEntry[]
22
     */
23 2
    public static function fromList(array $values)
24
    {
25 2
        $entries = array();
26
27 2
        foreach ($values as $value) {
28 2
            $entries[$value->id] = self::fromValue($value);
29 2
        }
30
31 2
        return $entries;
32
    }
33
34
    /**
35
     * @param \stdClass $value
36
     * @return FeedEntry
37
     */
38 3
    public static function fromValue(\stdClass $value)
39
    {
40 3
        return new self($value);
41
    }
42
43
    /**
44
     * @var \stdClass
45
     */
46
    protected $source;
47
48
    /**
49
     * @var \DateTime
50
     */
51
    protected $createdOn;
52
53
    /**
54
     * @var \DateTime
55
     */
56
    protected $updatedOn;
57
58
    /**
59
     * FeedEntryItem[]|ArrayCollection
60
     */
61
    protected $items;
62
63
    /**
64
     * @param \stdClass $source
65
     */
66 3
    public function __construct(\stdClass $source)
67
    {
68 3
        $this->source = $source;
69 3
    }
70
71
    /**
72
     * @return \stdClass
73
     */
74
    public function getRawData()
75
    {
76
        return $this->source;
77
    }
78
79
    /**
80
     * The Entry id
81
     *
82
     * @return integer
83
     */
84 3
    public function getId()
85
    {
86 3
        return $this->source->id;
87
    }
88
89
    /**
90
     * Get the author's mail of the feed entry
91
     *
92
     * @return string
93
     */
94 3
    public function getAuthorEmail()
95
    {
96 3
        return $this->source->author_email;
97
    }
98
99
    /**
100
     * Get the author's name of the feed entry
101
     *
102
     * @return string
103
     */
104 3
    public function getAuthorName()
105
    {
106 3
        return $this->source->author_name;
107
    }
108
109
    /**
110
     * Get the title of the feed entry
111
     *
112
     * @return string
113
     */
114 3
    public function getTitle()
115
    {
116 3
        return $this->source->title;
117
    }
118
119
    /**
120
     * Get The description of the feed entry
121
     *
122
     * @return string
123
     */
124 3
    public function getSubtitle()
125
    {
126 3
        return $this->source->subtitle;
127
    }
128
129
    /**
130
     * Creation date
131
     *
132
     * @return \DateTime
133
     */
134 3
    public function getCreatedOn()
135
    {
136 3
        return $this->createdOn ?: $this->createdOn = new \DateTime($this->source->created_on);
137
    }
138
139
    /**
140
     * Last update date
141
     *
142
     * @return \DateTime
143
     */
144 3
    public function getUpdatedOn()
145
    {
146 3
        return $this->updatedOn ?: $this->updatedOn = new \DateTime($this->source->updated_on);
147
    }
148
149
    /**
150
     * Get the items associated to the feed entry as a collection of
151
     * PhraseanetSDK\Entity\FeedEntryItem object
152
     *
153
     * @return ArrayCollection|FeedEntryItem[]
154
     */
155 3
    public function getItems()
156
    {
157 3
        if (! isset($this->source->items)) {
158
            $this->items = new ArrayCollection();
159
        }
160
161 3
        return $this->items ?: $this->items = new ArrayCollection(FeedEntryItem::fromList($this->source->items));
162
    }
163
164
    /**
165
     * Returns the entry's feed id
166
     *
167
     * @return integer
168
     */
169 3
    public function getFeedId()
170
    {
171 3
        return $this->source->feed_id;
172
    }
173
174
    /**
175
     * @return string
176
     */
177
    public function getFeedTitle()
178
    {
179
        return $this->source->feed_title;
180
    }
181
182
    /**
183
     * @return string
184
     */
185
    public function getFeedUrl()
186
    {
187
        return $this->source->feed_url;
188
    }
189
190
    /**
191
     * @return string
192
     */
193
    public function getUrl()
194
    {
195
        return $this->source->url;
196
    }
197
}
198