Completed
Push — master ( 8431a9...0bccd4 )
by Gabriel
04:28
created

Nip_Form_Element_Texteditor   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 159
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
eloc 120
c 1
b 0
f 0
dl 0
loc 159
ccs 0
cts 24
cp 0
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A addAllowedTags() 0 5 2
A addAllowedAttributes() 0 5 2
A filterHTML() 0 4 1
A getDataFromRequest() 0 5 1
A getInputFilter() 0 11 2
1
<?php
2
3
class Nip_Form_Element_Texteditor extends Nip_Form_Element_Textarea
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
4
{
5
    protected $_type = 'texteditor';
6
7
    protected $inputFilter;
8
9
    protected $allowedTags = [
10
        "a",
11
        "b",
12
        "blink",
13
        "blockquote",
14
        "br",
15
        "caption",
16
        "center",
17
        "col",
18
        "colgroup",
19
        "comment",
20
        "em",
21
        "font",
22
        "h1",
23
        "h2",
24
        "h3",
25
        "h4",
26
        "h5",
27
        "h6",
28
        "hr",
29
        "img",
30
        "li",
31
        "marquee",
32
        "ol",
33
        "p",
34
        "pre",
35
        "s",
36
        "small",
37
        "span",
38
        "strike",
39
        "strong",
40
        "sub",
41
        "sup",
42
        "table",
43
        "tbody",
44
        "td",
45
        "tfoot",
46
        "th",
47
        "thead",
48
        "tr",
49
        "tt",
50
        "u",
51
        "ul"
52
    ];
53
54
    protected $allowedAttributes = [
55
        "abbr",
56
        "align",
57
        "alt",
58
        "axis",
59
        "background",
60
        "behavior",
61
        "bgcolor",
62
        "border",
63
        "bordercolor",
64
        "bordercolordark",
65
        "bordercolorlight",
66
        "bottompadding",
67
        "cellpadding",
68
        "cellspacing",
69
        "char",
70
        "charoff",
71
        "cite",
72
        "clear",
73
        "color",
74
        "cols",
75
        "direction",
76
        "face",
77
        "font-weight",
78
        "headers",
79
        "height",
80
        "href",
81
        "hspace",
82
        "leftpadding",
83
        "loop",
84
        "noshade",
85
        "nowrap",
86
        "point-size",
87
        "rel",
88
        "rev",
89
        "rightpadding",
90
        "rowspan",
91
        "rules",
92
        "scope",
93
        "scrollamount",
94
        "scrolldelay",
95
        "size",
96
        "span",
97
        "src",
98
        "start",
99
        "style",
100
        "summary",
101
        "target",
102
        "title",
103
        "toppadding",
104
        "type",
105
        "valign",
106
        "value",
107
        "vspace",
108
        "width",
109
        "wrap"
110
    ];
111
112
113
    /**
114
     * @param $request
115
     * @return $this
116
     */
117
    public function getDataFromRequest($request)
118
    {
119
        $this->setValue($request);
120
        $this->filterHTML();
121
        return $this;
122
    }
123
124
    /**
125
     * @return $this
126
     */
127
    protected function filterHTML()
128
    {
129
        $this->setValue($this->getInputFilter()->purify($this->getValue()));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->getValue() targeting Nip\Form\Elements\AbstractElement::getValue() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
130
        return $this;
131
    }
132
133
    /**
134
     * @return HTMLPurifier
135
     */
136
    protected function getInputFilter()
137
    {
138
        if (!$this->inputFilter) {
139
            $config = HTMLPurifier_Config::createDefault();
0 ignored issues
show
Bug introduced by
The type HTMLPurifier_Config was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
140
            $config->set('HTML.AllowedElements', $this->allowedTags);
141
            $config->set('HTML.AllowedAttributes', $this->allowedAttributes);
142
            $purifier = new HTMLPurifier($config);
0 ignored issues
show
Bug introduced by
The type HTMLPurifier was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
143
            $this->inputFilter = $purifier;
144
        }
145
146
        return $this->inputFilter;
147
    }
148
149
    public function addAllowedTags()
150
    {
151
        $items = func_get_args();
152
        foreach ($items as $item) {
153
            $this->allowedTags[] = $item;
154
        }
155
    }
156
157
    public function addAllowedAttributes()
158
    {
159
        $items = func_get_args();
160
        foreach ($items as $item) {
161
            $this->allowedAttributes[] = $item;
162
        }
163
    }
164
}
165