Completed
Push — master ( 0c0f2c...d38dfd )
by Andreas
18:36
created

net_nemein_wiki_handler_feed   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Test Coverage

Coverage 46.67%

Importance

Changes 0
Metric Value
eloc 33
dl 0
loc 48
ccs 14
cts 30
cp 0.4667
rs 10
c 0
b 0
f 0
wmc 5

1 Method

Rating   Name   Duplication   Size   Complexity  
A _handler_rss() 0 43 5
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
    /**
19
     * @return Response
20
     */
21 1
    public function _handler_rss()
22
    {
23 1
        $nap = new midcom_helper_nav();
24 1
        $node = $nap->get_node($this->_topic->id);
25
26 1
        $rss_creator = new UniversalFeedCreator();
27 1
        $rss_creator->title = $node[MIDCOM_NAV_NAME];
28 1
        $rss_creator->link = $node[MIDCOM_NAV_FULLURL];
29 1
        $rss_creator->syndicationURL = "{$node[MIDCOM_NAV_FULLURL]}rss.xml";
30
31 1
        $qb = net_nemein_wiki_wikipage::new_query_builder();
32 1
        $qb->add_constraint('topic.component', '=', midcom_core_context::get()->get_key(MIDCOM_CONTEXT_COMPONENT));
33 1
        $qb->add_constraint('topic', 'INTREE', $this->_topic->id);
34 1
        $qb->add_order('metadata.revised', 'DESC');
35 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

35
        $qb->set_limit(/** @scrutinizer ignore-type */ $this->_config->get('rss_count'));
Loading history...
36
37 1
        foreach ($qb->execute() as $wikipage) {
38
            if ($wikipage->topic == $this->_topic->id) {
0 ignored issues
show
Bug Best Practice introduced by
The property topic does not exist on midcom_core_dbaobject. Since you implemented __get, consider adding a @property annotation.
Loading history...
39
                $pagenode = $node;
40
            } else {
41
                $pagenode = $nap->get_node($wikipage->topic);
42
            }
43
            $item = new FeedItem();
44
            $item->title = $wikipage->title;
45
            $item->link = $pagenode[MIDCOM_NAV_FULLURL];
46
            if ($wikipage->name != 'index') {
47
                $item->link .= "{$wikipage->name}/";
48
            }
49
            $item->date = $wikipage->metadata->revised;
50
            try {
51
                $author = new midcom_db_person($wikipage->metadata->revisor);
52
                $item->author = $author->name;
53
            } catch (midcom_error $e) {
54
                $e->log();
55
            }
56
57
            $parser = new net_nemein_wiki_parser($wikipage);
58
            $item->description = $parser->get_html();
59
            $rss_creator->addItem($item);
60
        }
61
62 1
        return new Response($rss_creator->createFeed('RSS2.0'), Response::HTTP_OK, [
63
            'Content-Type' => 'text/xml; charset=UTF-8'
64 1
        ]);
65
    }
66
}
67