MockProvider   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 57
Duplicated Lines 52.63 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 4
dl 30
loc 57
ccs 22
cts 22
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getFeed() 0 6 1
A buildFeed() 16 16 2
A addItem() 14 14 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php declare(strict_types=1);
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
use FeedIo\FeedInterface;
18
use Symfony\Component\HttpFoundation\Request;
19
20
class MockProvider implements FeedProviderInterface
21
{
22
23
    /**
24
     * @param Request $request
25
     * @return FeedInterface
26
     * @throws FeedNotFoundException
27
     */
28 7
    public function getFeed(Request $request): FeedInterface
29
    {
30 7
        $id = $request->get('id');
31
32 7
        return $this->buildFeed($id);
33
    }
34
35
    /**
36
     * @param string $id
37
     * @return FeedInterface
38
     * @throws FeedNotFoundException
39
     */
40 5 View Code Duplication
    protected function buildFeed(string $id): FeedInterface
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
41
    {
42 5
        if ($id === 'not-found') {
43 1
            throw new FeedNotFoundException();
44
        }
45
46 4
        $feed = new Feed();
47
48 4
        $feed->setPublicId($id);
49 4
        $feed->setTitle('thank you for using RssAtomBundle');
50 4
        $feed->setDescription('this is the mock FeedContent');
51 4
        $feed->setLink('https://raw.github.com/alexdebril/rss-atom-bundle/');
52 4
        $feed->setLastModified(new \DateTime());
53
54 4
        return $this->addItem($feed);
55
    }
56
57
    /**
58
     * @param Feed $feed
59
     * @return FeedInterface
60
     * @throws \Exception
61
     */
62 4 View Code Duplication
    protected function addItem(Feed $feed) : FeedInterface
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
63
    {
64 4
        $item = new Item();
65
66 4
        $item->setPublicId('1');
67 4
        $item->setLink('https://raw.github.com/alexdebril/rss-atom-bundle/somelink');
68 4
        $item->setTitle('This is an item');
69 4
        $item->setDescription('this stream was generated using the MockProvider class');
70 4
        $item->setLastModified(new \DateTime());
71
72 4
        $feed->add($item);
73
74 4
        return $feed;        
75
    }
76
}
77