Completed
Pull Request — master (#123)
by Alex
04:13 queued 02:21
created

MockProvider::getFeedContent()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 19
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 19
ccs 11
cts 11
cp 1
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 11
nc 4
nop 1
crap 3
1
<?php
2
3
/**
4
 * RssAtomBundle.
5
 *
6
 *
7
 * @license http://opensource.org/licenses/lgpl-3.0.html LGPL
8
 * @copyright (c) 2013, Alexandre Debril
9
 *
10
 * creation date : 31 mars 2013
11
 */
12
namespace Debril\RssAtomBundle\Provider;
13
14
use FeedIo\Feed;
15
use FeedIo\Feed\Item;
16
use Debril\RssAtomBundle\Exception\FeedException\FeedNotFoundException;
17
18
/**
19
 * Class MockProvider.
20
 */
21
class MockProvider implements FeedContentProviderInterface
22
{
23
    /**
24
     * @param array $options
25
     *
26
     * @return Feed
27
     *
28
     * @throws FeedNotFoundException
29
     */
30 4
    public function getFeedContent(array $options)
31
    {
32 4
        $feed = new Feed();
33
34 4
        $id = array_key_exists('id', $options) ? $options['id'] : null;
35
36 4
        if ($id === 'not-found') {
37 2
            throw new FeedNotFoundException();
38
        }
39
40 2
        $feed->setPublicId($id);
41
42 2
        $feed->setTitle('thank you for using RssAtomBundle');
43 2
        $feed->setDescription('this is the mock FeedContent');
44 2
        $feed->setLink('https://raw.github.com/alexdebril/rss-atom-bundle/');
45 2
        $feed->setLastModified(new \DateTime());
46
47 2
        return $this->addItem($feed);
48
    }
49
50
    /**
51
     * @param Feed $feed
52
     * @return Feed
53
     */
54 1
    protected function addItem(Feed $feed)
55
    {
56 1
        $item = new Item();
57
58 1
        $item->setPublicId('1');
59 1
        $item->setLink('https://raw.github.com/alexdebril/rss-atom-bundle/somelink');
60 1
        $item->setTitle('This is an item');
61 1
        $item->setDescription('this stream was generated using the MockProvider class');
62 1
        $item->setLastModified(new \DateTime());
63
64 1
        $feed->add($item);
65
66 1
        return $feed;        
67
    }
68
}
69