Special::loadModule()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 6
c 0
b 0
f 0
nc 2
nop 0
dl 0
loc 10
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace XoopsModules\Rssfit\Plugins;
6
7
/*
8
 * You may not change or alter any portion of this comment or credits
9
 * of supporting developers from this source code or any supporting source code
10
 * which is considered copyrighted (c) material of the original comment or credit authors.
11
 *
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15
 */
16
17
/**
18
 * @copyright    XOOPS Project (https://xoops.org)
19
 * @license      GNU GPL 2 or later (https://www.gnu.org/licenses/gpl-2.0.html)
20
 * @package      RSSFit - Extendable XML news feed generator
21
 * @author       NS Tai (aka tuff) <http://www.brandycoke.com>
22
 * @author       XOOPS Development Team
23
 */
24
25
/**
26
 * This file is a dummy for making a RSSFit plug-in, follow the following steps
27
 * if you really want to do so.
28
 *
29
 * Step 0: Stop here if you are not sure what you are doing, it's no fun at all
30
 * Step 1: Clone this file and rename as something like rssfit.[mod_dir].php
31
 * Step 2: Replace the class name "RssfitSpecial" with "Rssfit[mod_dir]" at line 60,
32
 *         i.e. "RssfitNews" for the module "News"
33
 * Step 3: Modify the definition of $dirname in line 62 to your modules dirname, i.e. 'news'
34
 * Step 4: Modify the function "grabEntries" method to satisfy your needs
35
 * Step 5: Move your new plug-in file to the RSSFit plugins folder,
36
 *         i.e. your-xoops-root/modules/rssfit/plugins
37
 * Step 6: Install your plug-in by pointing your browser to
38
 *         your-xoops-url/modules/rssfit/admin/?do=plugins
39
 * Step 7: Finally, tell us about yourself and this file by modifying the
40
 *         "About this RSSFit plug-in" section located below.
41
 *
42
 * About this RSSFit plug-in
43
 * Author: John Doe <http://www.your.site>
44
 * Requirements (or Tested with):
45
 *  Module: Blah <http://www.where.to.find.it>
46
 *  Version: 1.0
47
 *  RSSFit verision: 1.2 / 1.5
48
 *  XOOPS version: 2.0.13.2 / 2.2.3
49
 */
50
if (!\defined('RSSFIT_ROOT_PATH')) {
51
    exit();
52
}
53
54
/**
55
 * Class Special
56
 * @package XoopsModules\Rssfit\Plugins
57
 */
58
class Special
59
{
60
    public $dirname = 'special';
61
    public $modname;
62
    public $grab;                // will be set to the maximum number of items to grab
63
    public $module;
64
65
    /**
66
     * @return \XoopsModule
67
     */
68
    public function loadModule():?\XoopsModule
69
    {
70
        $mod = $GLOBALS['module_handler']->getByDirname($this->dirname);
71
        if (!$mod || !$mod->getVar('isactive')) {
72
            return null;
73
        }
74
        $this->modname = $mod->getVar('name');
75
        $this->module = $mod;   // optional, remove this line if there is nothing
76
        // to do with module info when grabbing entries
77
        return $mod;
78
    }
79
80
    /**
81
     * @return array
82
     */
83
    public function grabEntries(\XoopsMySQLDatabase $xoopsDB):?array
0 ignored issues
show
Unused Code introduced by
The parameter $xoopsDB is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

83
    public function grabEntries(/** @scrutinizer ignore-unused */ \XoopsMySQLDatabase $xoopsDB):?array

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
84
    {
85
        $ret = null;
86
        @require_once XOOPS_ROOT_PATH . '/modules/special/class/stuff.php';
87
        $myts = \MyTextSanitizer::getInstance();
88
        $items = SpecialStuff::getAllPublished($this->grab, 0);
0 ignored issues
show
Bug introduced by
The type XoopsModules\Rssfit\Plugins\SpecialStuff 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...
89
        foreach ($items as $item) {
90
            $ret[] = [
91
                'title' => $myts->undoHtmlSpecialChars($item->title()),
92
                'link' => XOOPS_URL . '/modules/special/article.php?itemid=' . $item->itemid(),
93
                'guid' => XOOPS_URL . '/modules/special/article.php?itemid=' . $item->itemid(),
94
                'timestamp' => $item->published(),
95
                'description' => $item->hometext(),
96
                'category' => $this->modname,
97
                'domain' => XOOPS_URL . '/modules/' . $this->dirname . '/',
98
            ];
99
        }
100
101
        return $ret;
102
    }
103
}
104