RSSNode::toSyntax()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 2
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 4
rs 10
1
<?php
2
3
namespace dokuwiki\plugin\prosemirror\parser;
4
5
class RSSNode extends Node
6
{
7
    protected $parent;
8
    protected $data;
9
10
    public function __construct($data, Node $parent)
11
    {
12
        $this->parent = &$parent;
13
        $this->data = $data;
14
    }
15
16
    public function toSyntax()
17
    {
18
        $attrs = $this->data['attrs'];
19
        return self::attrToSyntax($attrs);
20
    }
21
22
    protected static function attrToSyntax($attrs)
23
    {
24
        $prefix = '{{rss>';
25
        $url = '';
26
        if (!empty($attrs['url'])) {
27
            $url = $attrs['url'];
28
        }
29
        $paramString = '';
30
31
        if (!empty($attrs['max']) && $attrs['max'] !== 8) {
32
            $paramString .= ' ' . $attrs['max'];
33
        }
34
35
        if (!empty($attrs['reverse'])) {
36
            $paramString .= ' reverse';
37
        }
38
39
        if (!empty($attrs['author'])) {
40
            $paramString .= ' author';
41
        }
42
43
        if (!empty($attrs['date'])) {
44
            $paramString .= ' date';
45
        }
46
47
        if (!empty($attrs['details'])) {
48
            $paramString .= ' description';
49
        }
50
51
        if (!empty($attrs['refresh']) && $attrs['refresh'] !== '4h') {
52
            $paramString .= ' ' . $attrs['refresh'];
53
        }
54
        $postfix = '}}';
55
        return $prefix . $url . $paramString . $postfix;
56
    }
57
58
    public static function renderAttrsToHTML($attrs)
59
    {
60
        $syntax = self::attrToSyntax($attrs);
61
        $ins = p_get_instructions($syntax);
62
        return p_render('xhtml', $ins, $info);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $info seems to be never defined.
Loading history...
63
    }
64
}
65