Passed
Push — master ( 193549...c42bd6 )
by Michael
15:55 queued 12s
created

userlog::item()   B

Complexity

Conditions 7
Paths 6

Size

Total Lines 35
Code Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 25
nc 6
nop 1
dl 0
loc 35
rs 8.5866
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace XoopsModules\Newbb\Plugin;
4
5
/*
6
 You may not change or alter any portion of this comment or credits
7
 of supporting developers from this source code or any supporting source code
8
 which is considered copyrighted (c) material of the original comment or credit authors.
9
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
15
use Xmf\Request;
16
use XoopsModules\Newbb\Helper;
17
use XoopsModules\Userlog;
0 ignored issues
show
Bug introduced by
The type XoopsModules\Userlog 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...
Bug introduced by
This use statement conflicts with another class in this namespace, XoopsModules\Newbb\Plugin\Userlog. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
18
19
/** @var Helper $helper */
20
21
/**
22
 *  userlog module
23
 *
24
 * @copyright       XOOPS Project (https://xoops.org)
25
 * @license         GNU GPL 2 (https://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
26
 * @since           4.31
27
 * @author          irmtfan ([email protected])
28
 * @author          XOOPS Project <www.xoops.org> <www.xoops.ir>
29
 */
30
class userlog extends Userlog\Plugin\PluginAbstract implements Userlog\Plugin\PluginInterface
0 ignored issues
show
Bug introduced by
The type XoopsModules\Userlog\Plugin\PluginInterface 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...
Bug introduced by
The type XoopsModules\Userlog\Plugin\PluginAbstract 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...
31
{
32
    /**
33
     * @param string $subscribe_from Name of the script
34
     *
35
     * 'name' => 'thread';
36
     * 'title' => _MI_NEWBB_THREAD_NOTIFY;
37
     * 'description' => _MI_NEWBB_THREAD_NOTIFYDSC;
38
     * 'subscribe_from' => 'viewtopic.php';
39
     * 'item_name' => 'topic_id';
40
     * 'allow_bookmark' => 1;
41
     *
42
     * publisher:
43
     * 'name' = 'category_item';
44
     * 'title' = _MI_PUBLISHER_CATEGORY_ITEM_NOTIFY;
45
     * 'description' = _MI_PUBLISHER_CATEGORY_ITEM_NOTIFY_DSC;
46
     * 'subscribe_from' = array('index.php', 'category.php', 'item.php');
47
     * 'item_name' = 'categoryid';
48
     * 'allow_bookmark' = 1;
49
     *
50
     * empty($subscribe_from):
51
     * @return bool|array["item_name"] name of the item = array("subscribe_from1", "subscribe_from2") Name of the script
0 ignored issues
show
Documentation Bug introduced by
The doc comment bool|array["item_name"] at position 3 could not be parsed: Expected ']' at position 3, but found '['.
Loading history...
52
     *
53
     * !empty($subscribe_from):
54
     * @return bool|array $item["item_name"] name of the item, $item["item_id"] id of the item
55
     */
56
    public function item(string $subscribe_from)
57
    {
58
        if (empty($subscribe_from)) {
59
            $script_arr             = [];
60
            $script_arr['topic_id'] = ['viewtopic.php'];
61
            $script_arr['forum']    = ['viewforum.php'];
62
63
            return $script_arr;
64
        }
65
66
        switch ($subscribe_from) {
67
            case 'viewtopic.php':
68
                /** @var Newbb\TopicHandler $topicHandler */ $topicHandler = Helper::getInstance()->getHandler('Topic');
69
                $post_id                                                   = Request::getInt('post_id', 0); // !empty($_REQUEST["post_id"]) ? (int)($_REQUEST["post_id"]) : 0;
70
                $move                                                      = \mb_strtolower(Request::getString('move', '', 'GET')); // isset($_GET['move'])? strtolower($_GET['move']) : '';
71
                $topic_id                                                  = Request::getInt('topic_id', 0); // !empty($_REQUEST["topic_id"]) ? (int)($_REQUEST["topic_id"]) : 0;
72
                if (!empty($post_id)) {
73
                    $topicObject = $topicHandler->getByPost($post_id);
74
                    $topic_id    = $topicObject->getVar('topic_id');
75
                } elseif (!empty($move)) {
76
                    $forum_id    = Request::getInt('forum_id', 0); //!empty($_REQUEST["forum_id"]) ? (int)($_REQUEST["forum_id"]) : 0;
77
                    $topicObject = $topicHandler->getByMove($topic_id, ('prev' === $move) ? -1 : 1, $forum_id);
78
                    $topic_id    = $topicObject->getVar('topic_id');
79
                }
80
81
                return ['item_name' => 'topic_id', 'item_id' => $topic_id];
82
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
83
            case 'viewforum.php':
84
                $forum_id = Request::getInt('forum', 0); // !empty($_REQUEST["forum"]) ? (int)($_REQUEST["forum"]) : 0;
85
86
                return ['item_name' => 'forum', 'item_id' => $forum_id];
87
                break;
88
        }
89
90
        return false;
91
    }
92
}
93