SystemPlugin   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 29
dl 0
loc 68
rs 10
c 0
b 0
f 0
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A waiting() 0 14 2
A userPosts() 0 11 1
A backend() 0 16 2
A userMenus() 0 3 1
1
<?php
2
3
namespace XoopsModules\Xooghost\Plugin;
4
5
/**
6
 * Xooghost module
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
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14
 *
15
 * @copyright       XOOPS Project (https://xoops.org)
16
 * @license         GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
17
 * @package         Xooghost
18
 * @since           2.6.0
19
 * @author          Laurent JEN (Aka DuGris)
20
 */
21
class SystemPlugin extends \Xoops\Module\Plugin\PluginAbstract implements \SystemPluginInterface
22
{
23
    /**
24
     * @param int $uid
25
     *
26
     * @return mixed
27
     */
28
    public function userPosts($uid)
29
    {
30
        $helper = \XoopsModules\Xooghost\Helper::getInstance();
31
        $pageHandler = $helper->getHandler('Page');
32
33
        $criteria = new \CriteriaCompo();
34
        $criteria->add(new \Criteria('xooghost_online', 1));
35
        $criteria->add(new \Criteria('xooghost_published', time(), '<='));
36
        $criteria->add(new \Criteria('xooghost_uid', $uid));
37
38
        return $pageHandler->getCount($criteria);
0 ignored issues
show
Bug introduced by
The method getCount() does not exist on XoopsObjectHandler. ( Ignorable by Annotation )

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

38
        return $pageHandler->/** @scrutinizer ignore-call */ getCount($criteria);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
39
    }
40
41
    /**
42
     * @return bool
43
     */
44
    public function waiting()
45
    {
46
        $helper = \XoopsModules\Xooghost\Helper::getInstance();
47
        $pageHandler = $helper->getHandler('Page');
48
        $criteria = new \CriteriaCompo(new \Criteria('xooghost_online', 0));
49
        if ($count = $pageHandler->getCount($criteria)) {
50
            $ret['count'] = $count;
0 ignored issues
show
Comprehensibility Best Practice introduced by
$ret was never initialized. Although not strictly required by PHP, it is generally a good practice to add $ret = array(); before regardless.
Loading history...
51
            $ret['name'] = \Xoops::getInstance()->getHandlerModule()->getByDirname('xooghost')->getVar('name');
52
            $ret['link'] = \Xoops::getInstance()->url('modules/xooghost/admin/pages.php?online=0');
53
54
            return $ret;
55
        }
56
57
        return false;
0 ignored issues
show
Bug Best Practice introduced by
The expression return false returns the type false which is incompatible with the return type mandated by SystemPluginInterface::waiting() of array.

In the issue above, the returned value is violating the contract defined by the mentioned interface.

Let's take a look at an example:

interface HasName {
    /** @return string */
    public function getName();
}

class Name {
    public $name;
}

class User implements HasName {
    /** @return string|Name */
    public function getName() {
        return new Name('foo'); // This is a violation of the ``HasName`` interface
                                // which only allows a string value to be returned.
    }
}
Loading history...
58
    }
59
60
    /**
61
     * @param int $limit
62
     *
63
     * @return array
64
     */
65
    public function backend($limit = 10)
66
    {
67
        $xoops = \Xoops::getInstance();
68
        $helper = \XoopsModules\Xooghost\Helper::getInstance();
69
        $pageHandler = $helper->getHandler('Page');
70
71
        $ret = [];
72
        $messages = $pageHandler->getPublished('published', 'desc', 0, $limit);
0 ignored issues
show
Bug introduced by
The method getPublished() does not exist on XoopsObjectHandler. ( Ignorable by Annotation )

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

72
        /** @scrutinizer ignore-call */ 
73
        $messages = $pageHandler->getPublished('published', 'desc', 0, $limit);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
73
        foreach ($messages as $k => $message) {
74
            $ret[$k]['title'] = $message['xooghost_title'];
75
            $ret[$k]['link'] = $xoops->url('modules/xooghost/' . $message['xooghost_url']);
76
            $ret[$k]['content'] = $message['xooghost_content'];
77
            $ret[$k]['date'] = $message['xooghost_time'];
78
        }
79
80
        return $ret;
81
    }
82
83
    /**
84
     * @return array
85
     */
86
    public function userMenus()
87
    {
88
        return [];
89
    }
90
}
91