Passed
Push — master ( dcbd4a...4bb7b0 )
by Michael
02:37
created

b_marquee_show()   B

Complexity

Conditions 4
Paths 4

Size

Total Lines 30
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 22
c 0
b 0
f 0
nc 4
nop 1
dl 0
loc 30
rs 8.5806
1
<?php
2
/**
3
 * ****************************************************************************
4
 * marquee - MODULE FOR XOOPS
5
 * Copyright (c) Hervé Thouzard (http://www.herve-thouzard.com)
6
 *
7
 * You may not change or alter any portion of this comment or credits
8
 * of supporting developers from this source code or any supporting source code
9
 * which is considered copyrighted (c) material of the original comment or credit authors.
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
 *
14
 * @copyright         Hervé Thouzard (http://www.herve-thouzard.com)
15
 * @license           http://www.fsf.org/copyleft/gpl.html GNU public license
16
 * @package           marquee
17
 * @author            Hervé Thouzard (http://www.herve-thouzard.com)
18
 *
19
 * Version :
20
 * ****************************************************************************
21
 *
22
 * @param $options
23
 *
24
 * @return array
25
 */
26
27
use XoopsModules\Marquee;
28
29
/**
30
 * @param $options
31
 * @return array
32
 */
33
function b_marquee_show($options)
34
{
35
    global $xoopsTpl;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
36
    $marquee = null;
0 ignored issues
show
Unused Code introduced by
The assignment to $marquee is dead and can be removed.
Loading history...
37
//    require_once XOOPS_ROOT_PATH . '/modules/marquee/class/Utility.php';
38
    $marqueeHandler = XoopsModules\Marquee\Helper::getInstance()->getHandler('Marqueex');
39
    $block          = [];
40
    $marqueeId      = (int)$options[0];
41
    if ($marqueeId > 0) {
42
        /** @var Marquee\Marqueex $marquee */
43
        $marquee = $marqueeHandler->get($marqueeId);
44
        if (is_object($marquee)) {
45
            $uniqid = md5(uniqid(mt_rand(), true));
46
            if ('DHTML' === Marquee\Utility::getModuleOption('methodtouse')) {
0 ignored issues
show
introduced by
The condition 'DHTML' === XoopsModules...leOption('methodtouse') is always false.
Loading history...
47
                $link = '<script type="text/javascript" src="' . XOOPS_URL . '/modules/marquee/assets/js/xbMarquee.js"></script>';
0 ignored issues
show
Bug introduced by
The constant XOOPS_URL was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
48
                $link .= "\n<script type=\"text/javascript\">\n";
49
                $link .= 'var marquee' . $uniqid . ";\n";
50
                $link .= "var html$uniqid = '';\n";
51
                $link .= "function init_$uniqid()\n";
52
                $link .= "{\n";
53
                $link .= "\tmarquee$uniqid.start();\n";
54
                $link .= "}\n";
55
                $link .= "</script>\n";
56
                $xoopsTpl->assign('xoops_module_header', $link);
57
            }
58
            $block['marqueecode'] = $marquee->constructMarquee($uniqid);
59
        }
60
    }
61
62
    return $block;
63
}
64
65
/**
66
 * @param $options
67
 *
68
 * @return string
69
 */
70
function b_marquee_edit($options)
71
{
72
    /** @var Marquee\MarqueexHandler $marqueeHandler */
73
    $marqueeHandler = Marquee\Helper::getInstance()->getHandler('Marqueex');
74
    $form           = "<table border='0'>";
75
    $form           .= '<tr><td>' . _MB_MARQUEE_SELECT . "</td><td><select name='options[0]'>" . $marqueeHandler->getHtmlMarqueesList($options[0]) . '</select></td></tr>';
76
    $form           .= '</table>';
77
78
    return $form;
79
}
80
81
/*
82
 * Block on the fly
83
 */
84
/**
85
 * @param $options
86
 */
87
function b_marquee_custom($options)
88
{
89
    $options = explode('|', $options);
90
    $block   = b_marquee_show($options);
91
92
    $tpl = new \XoopsTpl();
0 ignored issues
show
Bug introduced by
The type XoopsTpl 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...
93
    $tpl->assign('block', $block);
94
    $tpl->display('db:marquee_block.tpl');
95
}
96