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

MockProvider   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 48
ccs 20
cts 20
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getFeedContent() 0 19 3
A addItem() 0 14 1
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