GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

Feed   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 49
Duplicated Lines 12.24 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 6
loc 49
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A addChannel() 0 6 1
A render() 6 17 2
A __toString() 0 4 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
2
3
namespace Bhaktaraz\RSSGenerator;
4
5
use DOMDocument;
6
use Bhaktaraz\RSSGenerator\FeedInterface;
7
use Bhaktaraz\RSSGenerator\ChannelInterface;
8
9
class Feed implements FeedInterface
10
{
11
12
    /** @var ChannelInterface[] */
13
    protected $channels = [];
14
15
    /**
16
     * Add channel
17
     * @param ChannelInterface $channel
18
     * @return $this
19
     */
20
    public function addChannel(ChannelInterface $channel)
21
    {
22
        $this->channels[] = $channel;
23
24
        return $this;
25
    }
26
27
    /**
28
     * Render XML
29
     * @return string
30
     */
31
    public function render()
32
    {
33
        $xml = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8" ?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/"  xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/">',
34
            LIBXML_NOERROR | LIBXML_ERR_NONE | LIBXML_ERR_FATAL);
35
36 View Code Duplication
        foreach ($this->channels as $channel) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
37
            $toDom = dom_import_simplexml($xml);
38
            $fromDom = dom_import_simplexml($channel->asXML());
39
            $toDom->appendChild($toDom->ownerDocument->importNode($fromDom, true));
40
        }
41
42
        $dom = new DOMDocument('1.0', 'UTF-8');
43
        $dom->appendChild($dom->importNode(dom_import_simplexml($xml), true));
44
        $dom->formatOutput = true;
45
46
        return $dom->saveXML();
47
    }
48
49
    /**
50
     * Render XML
51
     * @return string
52
     */
53
    public function __toString()
54
    {
55
        return $this->render();
56
    }
57
}
58