Completed
Pull Request — master (#16)
by Michael
01:51
created

include/notification.inc.php (3 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
 * 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
/**
13
 * @copyright      {@link https://xoops.org/ XOOPS Project}
14
 * @license        {@link http://www.gnu.org/licenses/gpl-2.0.html GNU GPL 2 or later}
15
 * @package
16
 * @since
17
 * @author         XOOPS Development Team
18
 */
19
20
// 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...
21
22
/**
23
 * @param $category
24
 * @param $item_id
25
 *
26
 * @return null
27
 */
28
function news_notify_iteminfo($category, $item_id)
29
{
30
    if ('global' === $category) {
31
        $item['name'] = '';
0 ignored issues
show
Coding Style Comprehensibility introduced by
$item was never initialized. Although not strictly required by PHP, it is generally a good practice to add $item = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
32
        $item['url']  = '';
33
34
        return $item;
35
    }
36
37
    global $xoopsDB;
38
39 View Code Duplication
    if ('story' === $category) {
0 ignored issues
show
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...
40
        // Assume we have a valid story id
41
        $sql    = 'SELECT title FROM ' . $xoopsDB->prefix('news_stories') . ' WHERE storyid = ' . (int)$item_id;
42
        $result = $xoopsDB->query($sql);
43
        if ($result) {
44
            $result_array = $xoopsDB->fetchArray($result);
45
            $item['name'] = $result_array['title'];
46
            $item['url']  = XOOPS_URL . '/modules/news/article.php?storyid=' . (int)$item_id;
47
48
            return $item;
49
        } else {
50
            return null;
51
        }
52
    }
53
54
    // Added by Lankford on 2007/3/23
55 View Code Duplication
    if ('category' === $category) {
56
        $sql    = 'SELECT title FROM ' . $xoopsDB->prefix('news_topics') . ' WHERE topic_id = ' . (int)$item_id;
57
        $result = $xoopsDB->query($sql);
58
        if ($result) {
59
            $result_array = $xoopsDB->fetchArray($result);
60
            $item['name'] = $result_array['topic_id'];
61
            $item['url']  = XOOPS_URL . '/modules/news/index.php?storytopic=' . (int)$item_id;
62
63
            return $item;
64
        } else {
65
            return null;
66
        }
67
    }
68
69
    return null;
70
}
71