Completed
Pull Request — master (#591)
by Richard
17:41
created

XoopsCode   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 126
Duplicated Lines 0 %

Test Coverage

Coverage 56%

Importance

Changes 0
Metric Value
eloc 77
dl 0
loc 126
ccs 42
cts 75
cp 0.56
rs 10
c 0
b 0
f 0
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
B registerExtensionProcessing() 0 114 2
1
<?php
2
/*
3
 You may not change or alter any portion of this comment or credits
4
 of supporting developers from this source code or any supporting source code
5
 which is considered copyrighted (c) material of the original comment or credit authors.
6
7
 This program is distributed in the hope that it will be useful,
8
 but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
*/
11
12
namespace Xoops\Core\Text\Sanitizer\Extensions;
13
14
use Xoops\Core\Text\Sanitizer;
15
use Xoops\Core\Text\Sanitizer\ExtensionAbstract;
16
17
/**
18
 * TextSanitizer extension
19
 *
20
 * @category  Sanitizer
21
 * @package   Xoops\Core\Text
22
 * @author    iHackCode <https://github.com/ihackcode>
23
 * @copyright 2011-2015 XOOPS Project (http://xoops.org)
24
 * @license   GNU GPL 2 (http://www.gnu.org/licenses/gpl-2.0.html)
25
 * @link      http://xoops.org
26
 */
27
class XoopsCode extends ExtensionAbstract
28
{
29
    /**
30
     * @var array default configuration values
31
     */
32
    protected static $defaultConfiguration = ['enabled' => true];
33
34
    /**
35
     * Register extension with the supplied sanitizer instance
36
     *
37
     * @return void
38
     */
39 20
    public function registerExtensionProcessing()
40
    {
41 20
        $shortcodes = $this->shortcodes;
42
43 20
        $shortcodes->addShortcode(
44 20
            'siteurl',
45
            function ($attributes, $content, $tagName) use ($shortcodes) {
0 ignored issues
show
Unused Code introduced by
The parameter $tagName is not used and could be removed. ( Ignorable by Annotation )

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

45
            function ($attributes, $content, /** @scrutinizer ignore-unused */ $tagName) use ($shortcodes) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
46
                $url = ltrim($attributes[0], '=');
47
                $url = \Xoops::getInstance()->url($url);
48
                $newcontent = '<a href="' .$url. '">' . $shortcodes->process($content) . '</a>';
49
                return $newcontent;
50 20
            }
51
        );
52
53 20
        $shortcodes->addShortcode(
54 20
            'url',
55
            function ($attributes, $content, $tagName) use ($shortcodes) {
0 ignored issues
show
Unused Code introduced by
The parameter $tagName is not used and could be removed. ( Ignorable by Annotation )

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

55
            function ($attributes, $content, /** @scrutinizer ignore-unused */ $tagName) use ($shortcodes) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
56
                $url = ltrim($attributes[0], '=');
57
                $url = \Xoops::getInstance()->url($url);
58
                $newcontent = '<a href="' .$url. '">' . $shortcodes->process($content) . '</a>';
59
                return $newcontent;
60 20
            }
61
        );
62
63 20
        $shortcodes->addShortcode(
64 20
            'color',
65
            function ($attributes, $content, $tagName) use ($shortcodes) {
0 ignored issues
show
Unused Code introduced by
The parameter $tagName is not used and could be removed. ( Ignorable by Annotation )

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

65
            function ($attributes, $content, /** @scrutinizer ignore-unused */ $tagName) use ($shortcodes) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
66
                $color = ltrim($attributes[0], '=');
67
                $color = preg_match('/^[a-f0-9]{3}$|^[a-f0-9]{6}$/i', $color) ? '#' . $color : $color;
68
                $newcontent = '<span style="color: ' .$color. '">' . $shortcodes->process($content) . '</span>';
69
                return $newcontent;
70 20
            }
71
        );
72
73 20
        $shortcodes->addShortcode(
74 20
            'size',
75
            function ($attributes, $content, $tagName) use ($shortcodes) {
0 ignored issues
show
Unused Code introduced by
The parameter $tagName is not used and could be removed. ( Ignorable by Annotation )

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

75
            function ($attributes, $content, /** @scrutinizer ignore-unused */ $tagName) use ($shortcodes) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
76
                $size = ltrim($attributes[0], '=');
77
                $newcontent = '<span style="font-size: ' .$size. '">' . $shortcodes->process($content) . '</span>';
78
                return $newcontent;
79 20
            }
80
        );
81
82 20
        $shortcodes->addShortcode(
83 20
            'font',
84
            function ($attributes, $content, $tagName) use ($shortcodes) {
0 ignored issues
show
Unused Code introduced by
The parameter $tagName is not used and could be removed. ( Ignorable by Annotation )

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

84
            function ($attributes, $content, /** @scrutinizer ignore-unused */ $tagName) use ($shortcodes) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
85
                $font = ltrim($attributes[0], '=');
86
                $newcontent = '<span style="font-family: ' .$font. '">' . $shortcodes->process($content) . '</span>';
87
                return $newcontent;
88 20
            }
89
        );
90
91 20
        $shortcodes->addShortcode(
92 20
            'email',
93
            function ($attributes, $content, $tagName) {
0 ignored issues
show
Unused Code introduced by
The parameter $tagName is not used and could be removed. ( Ignorable by Annotation )

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

93
            function ($attributes, $content, /** @scrutinizer ignore-unused */ $tagName) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
94
                $content = trim($content);
95
                $newcontent = '<a href="mailto:' . $content . '">' . $content . '</a>';
96
                return $newcontent;
97 20
            }
98
        );
99
100 20
        $shortcodes->addShortcode(
101 20
            'b',
102
            function ($attributes, $content, $tagName) use ($shortcodes) {
0 ignored issues
show
Unused Code introduced by
The parameter $tagName is not used and could be removed. ( Ignorable by Annotation )

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

102
            function ($attributes, $content, /** @scrutinizer ignore-unused */ $tagName) use ($shortcodes) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
103 1
                $newcontent = '<strong>' . $shortcodes->process($content) . '</strong>';
104 1
                return $newcontent;
105 20
            }
106
        );
107
108 20
        $shortcodes->addShortcode(
109 20
            'i',
110
            function ($attributes, $content, $tagName) use ($shortcodes) {
0 ignored issues
show
Unused Code introduced by
The parameter $tagName is not used and could be removed. ( Ignorable by Annotation )

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

110
            function ($attributes, $content, /** @scrutinizer ignore-unused */ $tagName) use ($shortcodes) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
111
                $newcontent = '<em>' . $shortcodes->process($content) . '</em>';
112
                return $newcontent;
113 20
            }
114
        );
115
116 20
        $shortcodes->addShortcode(
117 20
            'u',
118
            function ($attributes, $content, $tagName) use ($shortcodes) {
0 ignored issues
show
Unused Code introduced by
The parameter $tagName is not used and could be removed. ( Ignorable by Annotation )

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

118
            function ($attributes, $content, /** @scrutinizer ignore-unused */ $tagName) use ($shortcodes) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
119
                $newcontent = '<u>' . $shortcodes->process($content) . '</u>';
120
                return $newcontent;
121 20
            }
122
        );
123
124 20
        $shortcodes->addShortcode(
125 20
            'd',
126
            function ($attributes, $content, $tagName) use ($shortcodes) {
0 ignored issues
show
Unused Code introduced by
The parameter $tagName is not used and could be removed. ( Ignorable by Annotation )

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

126
            function ($attributes, $content, /** @scrutinizer ignore-unused */ $tagName) use ($shortcodes) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
127
                $newcontent = '<del>' . $shortcodes->process($content) . '</del>';
128
                return $newcontent;
129 20
            }
130
        );
131
132 20
        $shortcodes->addShortcode(
133 20
            'center',
134
            function ($attributes, $content, $tagName) use ($shortcodes) {
0 ignored issues
show
Unused Code introduced by
The parameter $tagName is not used and could be removed. ( Ignorable by Annotation )

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

134
            function ($attributes, $content, /** @scrutinizer ignore-unused */ $tagName) use ($shortcodes) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
135
                $newcontent = '<div style="text-align: center;">' . $shortcodes->process($content) . '</div>';
136
                return $newcontent;
137 20
            }
138
        );
139
140 20
        $shortcodes->addShortcode(
141 20
            'left',
142
            function ($attributes, $content, $tagName) use ($shortcodes) {
0 ignored issues
show
Unused Code introduced by
The parameter $tagName is not used and could be removed. ( Ignorable by Annotation )

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

142
            function ($attributes, $content, /** @scrutinizer ignore-unused */ $tagName) use ($shortcodes) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
143
                $newcontent = '<div style="text-align: left;">' . $shortcodes->process($content) . '</div>';
144
                return $newcontent;
145 20
            }
146
        );
147
148 20
        $shortcodes->addShortcode(
149 20
            'right',
150
            function ($attributes, $content, $tagName) use ($shortcodes) {
0 ignored issues
show
Unused Code introduced by
The parameter $tagName is not used and could be removed. ( Ignorable by Annotation )

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

150
            function ($attributes, $content, /** @scrutinizer ignore-unused */ $tagName) use ($shortcodes) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
151
                $newcontent = '<div style="text-align: right;">' . $shortcodes->process($content) . '</div>';
152
                return $newcontent;
153 20
            }
154
        );
155 20
    }
156
}
157