functions.php ➔ presenter_meta_description()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 11

Duplication

Lines 11
Ratio 100 %

Importance

Changes 0
Metric Value
cc 3
nc 2
nop 1
dl 11
loc 11
rs 9.9
c 0
b 0
f 0
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
 * presenter module for xoops
13
 *
14
 * @copyright       XOOPS Project (https://xoops.org)
15
 * @license         GPL 2.0 or later
16
 * @package         presenter
17
 * @since           2.5.5
18
 * @author          XOOPS Development Team <[email protected]> - <https://xoops.org>
19
 */
20
/***************Blocks**************
21
 * @param $cats
22
 * @return string
23
 */
24
function presenter_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
Bug introduced by
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 presenter_CleanVars(&$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 (false === $ret) {
57
        return $default;
58
    }
59
60
    return $ret;
61
}
62
63
/**
64
 * @param $content
65
 */
66 View Code Duplication
function presenter_meta_keywords($content)
0 ignored issues
show
Duplication introduced by
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;
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 presenter_meta_description($content)
0 ignored issues
show
Duplication introduced by
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;
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