Completed
Pull Request — master (#561)
by Richard
08:57
created

XoopsCode   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 129
Duplicated Lines 9.3 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 64.04%

Importance

Changes 0
Metric Value
dl 12
loc 129
ccs 57
cts 89
cp 0.6404
rs 10
c 0
b 0
f 0
wmc 2
lcom 1
cbo 3

1 Method

Rating   Name   Duplication   Size   Complexity  
B registerExtensionProcessing() 12 116 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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 2
    public function registerExtensionProcessing()
40
    {
41 2
        $shortcodes = $this->shortcodes;
42
43 2
        $shortcodes->addShortcode(
44 2
            'siteurl',
45 2 View Code Duplication
            function ($attributes, $content, $tagName) use ($shortcodes) {
0 ignored issues
show
Unused Code introduced by
The parameter $tagName is not used and could be removed.

This check looks from 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 2
            }
51
        );
52
53 2
        $shortcodes->addShortcode(
54 2
            'url',
55 2 View Code Duplication
            function ($attributes, $content, $tagName) use ($shortcodes) {
0 ignored issues
show
Unused Code introduced by
The parameter $tagName is not used and could be removed.

This check looks from 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 2
            }
61
        );
62
63 2
        $shortcodes->addShortcode(
64 2
            'color',
65 2
            function ($attributes, $content, $tagName) use ($shortcodes) {
0 ignored issues
show
Unused Code introduced by
The parameter $tagName is not used and could be removed.

This check looks from 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 2
            }
71
        );
72
73 2
        $shortcodes->addShortcode(
74 2
            'size',
75 2
            function ($attributes, $content, $tagName) use ($shortcodes) {
0 ignored issues
show
Unused Code introduced by
The parameter $tagName is not used and could be removed.

This check looks from 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 2
            }
80
        );
81
82 2
        $shortcodes->addShortcode(
83 2
            'font',
84 2
            function ($attributes, $content, $tagName) use ($shortcodes) {
0 ignored issues
show
Unused Code introduced by
The parameter $tagName is not used and could be removed.

This check looks from 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 2
            }
89
        );
90
91 2
        $shortcodes->addShortcode(
92 2
            'email',
93 2
            function ($attributes, $content, $tagName) {
0 ignored issues
show
Unused Code introduced by
The parameter $tagName is not used and could be removed.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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