Completed
Push — master ( 54d4eb...375a6b )
by Michael
02:05
created

include/functions.php (5 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * Module: RandomQuote
4
 *
5
 * You may not change or alter any portion of this comment or credits
6
 * of supporting developers from this source code or any supporting source code
7
 * which is considered copyrighted (c) material of the original comment or credit authors.
8
 *
9
 * PHP version 5
10
 *
11
 * @category        Module
12
 * @package         Randomquote
13
 * @author          XOOPS Development Team, Mamba
14
 * @copyright       2001-2016 XOOPS Project (http://xoops.org)
15
 * @license         GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
16
 * @link            http://xoops.org/
17
 * @since           2.0.0
18
 */
19
20
/***************Blocks**************
21
 * @param $cats
22
 * @return string
23
 */
24
function randomquote_block_addCatSelect($cats)
25
{
26
    if (is_array($cats)) {
27
        $cat_sql = '(' . current($cats);
28
        array_shift($cats);
29
        foreach ($cats as $cat) {
30
            $cat_sql .= ',' . $cat;
31
        }
32
        $cat_sql .= ')';
33
    }
34
35
    return $cat_sql;
0 ignored issues
show
The variable $cat_sql does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
36
}
37
38
/**
39
 * @param               $global
40
 * @param               $key
41
 * @param  string       $default
42
 * @param  string       $type
43
 * @return mixed|string
44
 */
45
function cleanVarsRandomquote(&$global, $key, $default = '', $type = 'int')
46
{
47
    switch ($type) {
48
        case 'string':
49
            $ret = isset($global[$key]) ? filter_var($global[$key], FILTER_SANITIZE_MAGIC_QUOTES) : $default;
50
            break;
51
        case 'int':
52
        default:
53
            $ret = isset($global[$key]) ? filter_var($global[$key], FILTER_SANITIZE_NUMBER_INT) : $default;
54
            break;
55
    }
56
    if ($ret === false) {
57
        return $default;
58
    }
59
60
    return $ret;
61
}
62
63
/**
64
 * @param $content
65
 */
66 View Code Duplication
function setMetaKeywordsRandomquote($content)
0 ignored issues
show
This function seems to be duplicated in 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...
67
{
68
    global $xoopsTpl, $xoTheme;
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...
69
    $myts    = MyTextSanitizer::getInstance();
70
    $content = $myts->undoHtmlSpecialChars($myts->displayTarea($content));
71
    if (isset($xoTheme) && is_object($xoTheme)) {
72
        $xoTheme->addMeta('meta', 'keywords', strip_tags($content));
73
    } else { // Compatibility for old Xoops versions
74
        $xoopsTpl->assign('xoops_meta_keywords', strip_tags($content));
75
    }
76
}
77
78
/**
79
 * @param $content
80
 */
81 View Code Duplication
function setMetaDescriptionRandomquote($content)
0 ignored issues
show
This function seems to be duplicated in 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...
82
{
83
    global $xoopsTpl, $xoTheme;
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...
84
    $myts    = MyTextSanitizer::getInstance();
85
    $content = $myts->undoHtmlSpecialChars($myts->displayTarea($content));
86
    if (isset($xoTheme) && is_object($xoTheme)) {
87
        $xoTheme->addMeta('meta', 'description', strip_tags($content));
88
    } else { // Compatibility for old Xoops versions
89
        $xoopsTpl->assign('xoops_meta_description', strip_tags($content));
90
    }
91
}
92