Completed
Push — master ( f6e48a...088fe8 )
by Andreas
18:26
created

net_nemein_wiki_handler_feed::_handler_rss()   A

Complexity

Conditions 5
Paths 9

Size

Total Lines 43
Code Lines 32

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 15
CRAP Score 8.4366

Importance

Changes 0
Metric Value
cc 5
eloc 32
nc 9
nop 0
dl 0
loc 43
ccs 15
cts 31
cp 0.4839
crap 8.4366
rs 9.0968
c 0
b 0
f 0
1
<?php
2
/**
3
 * @package net.nemein.wiki
4
 * @author The Midgard Project, http://www.midgard-project.org
5
 * @copyright The Midgard Project, http://www.midgard-project.org
6
 * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License
7
 */
8
9
use Symfony\Component\HttpFoundation\Response;
10
11
/**
12
 * Wikipage feed handler
13
 *
14
 * @package net.nemein.wiki
15
 */
16
class net_nemein_wiki_handler_feed extends midcom_baseclasses_components_handler
17
{
18 1
    public function _handler_rss()
19
    {
20 1
        $nap = new midcom_helper_nav();
21 1
        $node = $nap->get_node($this->_topic->id);
22
23 1
        $rss_creator = new UniversalFeedCreator();
24 1
        $rss_creator->title = $node[MIDCOM_NAV_NAME];
25 1
        $rss_creator->link = $node[MIDCOM_NAV_FULLURL];
26 1
        $rss_creator->syndicationURL = "{$node[MIDCOM_NAV_FULLURL]}rss.xml";
27
28 1
        $qb = net_nemein_wiki_wikipage::new_query_builder();
29 1
        $qb->add_constraint('topic.component', '=', midcom_core_context::get()->get_key(MIDCOM_CONTEXT_COMPONENT));
30 1
        $qb->add_constraint('topic', 'INTREE', $this->_topic->id);
31 1
        $qb->add_order('metadata.revised', 'DESC');
32 1
        $qb->set_limit($this->_config->get('rss_count'));
0 ignored issues
show
Bug introduced by
It seems like $this->_config->get('rss_count') can also be of type false; however, parameter $limit of midcom_core_query::set_limit() does only seem to accept integer, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

32
        $qb->set_limit(/** @scrutinizer ignore-type */ $this->_config->get('rss_count'));
Loading history...
33
34 1
        foreach ($qb->execute() as $wikipage) {
35
            if ($wikipage->topic == $this->_topic->id) {
36
                $pagenode = $node;
37
            } else {
38
                $pagenode = $nap->get_node($wikipage->topic);
39
            }
40
            $item = new FeedItem();
41
            $item->title = $wikipage->title;
42
            $item->link = $pagenode[MIDCOM_NAV_FULLURL];
43
            if ($wikipage->name != 'index') {
44
                $item->link .= "{$wikipage->name}/";
45
            }
46
            $item->date = $wikipage->metadata->revised;
47
            try {
48
                $author = new midcom_db_person($wikipage->metadata->revisor);
49
                $item->author = $author->name;
50
            } catch (midcom_error $e) {
51
                $e->log();
52
            }
53
54
            $parser = new net_nemein_wiki_parser($wikipage);
55
            $item->description = $parser->get_html();
56
            $rss_creator->addItem($item);
57
        }
58
59 1
        return new Response($rss_creator->createFeed('RSS2.0'), Response::HTTP_OK, [
60 1
            'Content-Type' => 'text/xml; charset=UTF-8'
61
        ]);
62
    }
63
}
64