Completed
Push — master ( a1059e...55b12e )
by Michael
01:29
created

Marqueex::constructMarquee()   F

Complexity

Conditions 22
Paths 12288

Size

Total Lines 93
Code Lines 78

Duplication

Lines 6
Ratio 6.45 %

Importance

Changes 0
Metric Value
cc 22
eloc 78
nc 12288
nop 1
dl 6
loc 93
rs 2
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php namespace XoopsModules\Marquee;
2
3
/**
4
 * ****************************************************************************
5
 * marquee - MODULE FOR XOOPS
6
 * Copyright (c) Hervé Thouzard (http://www.herve-thouzard.com)
7
 *
8
 * You may not change or alter any portion of this comment or credits
9
 * of supporting developers from this source code or any supporting source code
10
 * which is considered copyrighted (c) material of the original comment or credit authors.
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14
 *
15
 * @copyright          Hervé Thouzard (http://www.herve-thouzard.com)
16
 * @license            http://www.fsf.org/copyleft/gpl.html GNU public license
17
 * @package            marquee
18
 * @author             Hervé Thouzard (http://www.herve-thouzard.com)
19
 * ****************************************************************************
20
 */
21
22
use XoopsModules\Marquee;
23
24
// defined('XOOPS_ROOT_PATH') || exit('Restricted access.');
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
25
26
//require_once XOOPS_ROOT_PATH . '/kernel/object.php';
0 ignored issues
show
Unused Code Comprehensibility introduced by
44% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
27
//require_once XOOPS_ROOT_PATH . '/modules/marquee/class/Utility.php';
28
//if (!class_exists('MarqueePersistableObjectHandler')) {
29
//    require_once XOOPS_ROOT_PATH . '/modules/marquee/class/PersistableObjectHandler.php';
30
//}
31
32
/**
33
 * Class Marqueex
34
 */
35
class Marqueex extends \XoopsObject
36
{
37
    /**
38
     * marquee constructor.
39
     */
40
    public function __construct()
41
    {
42
        parent::__construct();
43
        $this->initVar('marquee_marqueeid', XOBJ_DTYPE_INT, null, false);
44
        $this->initVar('marquee_uid', XOBJ_DTYPE_INT, null, false);
45
        $this->initVar('marquee_direction', XOBJ_DTYPE_INT, null, false);
46
        $this->initVar('marquee_scrollamount', XOBJ_DTYPE_INT, null, false);
47
        $this->initVar('marquee_behaviour', XOBJ_DTYPE_INT, null, false);
48
        $this->initVar('marquee_bgcolor', XOBJ_DTYPE_TXTBOX, null, false, 7);
49
        $this->initVar('marquee_align', XOBJ_DTYPE_INT, null, false);
50
        $this->initVar('marquee_height', XOBJ_DTYPE_INT, null, false);
51
        $this->initVar('marquee_width', XOBJ_DTYPE_TXTBOX, null, false, 4);
52
        $this->initVar('marquee_hspace', XOBJ_DTYPE_INT, null, false);
53
        $this->initVar('marquee_scrolldelay', XOBJ_DTYPE_INT, null, false);
54
        $this->initVar('marquee_stoponmouseover', XOBJ_DTYPE_INT, null, false);
55
        $this->initVar('marquee_loop', XOBJ_DTYPE_INT, null, false);
56
        $this->initVar('marquee_vspace', XOBJ_DTYPE_INT, null, false);
57
        $this->initVar('marquee_content', XOBJ_DTYPE_OTHER, null, false);
58
        $this->initVar('marquee_source', XOBJ_DTYPE_TXTBOX, null, false, 255);
59
        // To be able to use html
60
        $this->initVar('dohtml', XOBJ_DTYPE_INT, 1);
61
    }
62
63
    /**
64
     * @param string $uniqid
65
     *
66
     * @return mixed|string
67
     */
68
    public function constructMarquee($uniqid = '')
69
    {
70
        //        require_once XOOPS_ROOT_PATH . '/modules/marquee/class/Utility.php';
71
        $tblalign     = ['top', 'bottom', 'middle'];
72
        $tblbehaviour = ['scroll', 'slide', 'alternate'];
73
        $tbldirection = ['right', 'left', 'up', 'down'];
74
        $stop         = 1 == $this->getVar('marquee_stoponmouseover') ? ' onmouseover="this.stop()" onmouseout="this.start()"' : '';
75
        $bgcolor      = '' !== trim($this->getVar('marquee_bgcolor')) ? " bgcolor='" . $this->getVar('marquee_bgcolor') . "'" : '';
76
        $height       = 0 != $this->getVar('marquee_height') ? ' height=' . $this->getVar('marquee_height') : '';
77
        $hspace       = 0 != $this->getVar('marquee_hspace') ? ' hspace=' . $this->getVar('marquee_hspace') : '';
78
        $width        = '' !== trim($this->getVar('marquee_width')) ? " width='" . $this->getVar('marquee_width') . "'" : '';
79
        $scrolldelay  = 0 != $this->getVar('marquee_scrolldelay') ? ' scrolldelay=' . $this->getVar('marquee_scrolldelay') : '';
80
        $loop         = 0 != $this->getVar('marquee_loop') ? ' loop=' . $this->getVar('marquee_loop') : " loop='infinite'";
81
        $vspace       = 0 != $this->getVar('marquee_vspace') ? ' vspace=' . $this->getVar('marquee_vspace') : '';
82
        $scrollamount = 0 != $this->getVar('marquee_scrollamount') ? ' scrollamount=' . $this->getVar('marquee_scrollamount') : '';
83
        $br           = ' - ';
84
85
        if ($this->getVar('marquee_direction') > 1) {
86
            $br = '<br>';
87
        }
88
89
        $content = '';
90
        if ('fixed' !== $this->getVar('marquee_source')) {
91
            require_once XOOPS_ROOT_PATH . '/modules/marquee/plugins/' . $this->getVar('marquee_source') . '.php';
92
            $function_name = 'b_marquee_' . $this->getVar('marquee_source'); // For example b_marquee_comments
93
            if (function_exists($function_name)) {
94
                $limit      = Marquee\Utility::getModuleOption('itemscount');
95
                $dateFormat = Marquee\Utility::getModuleOption('dateformat');
96
                $itemsSize  = Marquee\Utility::getModuleOption('itemssize');
97
                $retval     = $function_name($limit, $dateFormat, $itemsSize);
98
                if (is_array($retval) && count($retval) > 0) {
99
                    foreach ($retval as $onevalue) {
100 View Code Duplication
                        if (isset($onevalue['category']) && '' !== xoops_trim($onevalue['category'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
101
                            $onevalue['category'] = ' - ' . $onevalue['category'];
102
                        }
103 View Code Duplication
                        if (isset($onevalue['link']) && '' !== xoops_trim($onevalue['link'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
104
                            $onevalue['link'] = ' - ' . $onevalue['link'];
105
                        }
106
                        $content .= $onevalue['date'] . $onevalue['category'] . $onevalue['link'] . $br;
107
                    }
108
                }
109
            }
110
        } else {
111
            $content = $this->getVar('marquee_content');
112
        }
113
        if (!Marquee\Utility::isBot()) { // We are using the microsoft html tag
114
            if ('dhtml' !== strtolower(Utility::getModuleOption('methodtouse'))) {
115
                return "<marquee align='"
116
                       . $tblalign[$this->getVar('marquee_align')]
117
                       . "' behavior='"
118
                       . $tblbehaviour[$this->getVar('marquee_behaviour')]
119
                       . "' direction='"
120
                       . $tbldirection[$this->getVar('marquee_direction')]
121
                       . "' "
122
                       . $stop
123
                       . $scrollamount
124
                       . $bgcolor
125
                       . $height
126
                       . $hspace
127
                       . $width
128
                       . $scrolldelay
129
                       . $loop
130
                       . $vspace
131
                       . '>'
132
                       . $content
133
                       . '</marquee>';
134
            } else { // We are using the javascript method
135
                $jscontent = '';
136
                $jscontent .= "<script type=\"text/javascript\">\n";
137
                $jscontent .= "html$uniqid = '';\n";
138
                $jscontent .= "html$uniqid += '" . Marquee\Utility::javascriptEscape($content) . "' ;\n";
139
                $jscontent .= "marquee$uniqid = new XbMarquee('marquee$uniqid', "
140
                              . $this->getVar('marquee_height')
141
                              . ', '
142
                              . $this->getVar('marquee_width')
143
                              . ', '
144
                              . $this->getVar('marquee_scrollamount')
145
                              . ', '
146
                              . $this->getVar('marquee_scrolldelay')
147
                              . ", '"
148
                              . $tbldirection[$this->getVar('marquee_direction')]
149
                              . "', '"
150
                              . $tblbehaviour[$this->getVar('marquee_behaviour')]
151
                              . "', html$uniqid);\n";
152
                $jscontent .= "init_$uniqid();\n";
153
                $jscontent .= "</script>\n";
154
155
                return $jscontent;
156
            }
157
        } else {
158
            return $content;
159
        }
160
    }
161
}
162
163