Completed
Push — master ( 496194...f5db64 )
by Richard
09:00 queued 01:45
created

CommentsWaitingPlugin::waiting()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 10

Duplication

Lines 15
Ratio 100 %

Importance

Changes 0
Metric Value
cc 2
eloc 10
nc 2
nop 0
dl 15
loc 15
rs 9.4285
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
/**
13
 * @copyright       The XOOPS Project http://sourceforge.net/projects/xoops/
14
 * @license         http://www.fsf.org/copyleft/gpl.html GNU public license
15
 *
16
 * @package         Comments
17
 * @since           2.6.0
18
 * @author          Laurent JEN (Aka DuGris)
19
 * @author          trabis <[email protected]>
20
 * @version         $Id$
21
 */
22 View Code Duplication
class CommentsWaitingPlugin implements WaitingPluginInterface
0 ignored issues
show
Duplication introduced by
This class 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...
23
{
24
25
    /**
26
     * @return array
27
     */
28
    public function waiting()
29
    {
30
        /* @var $comments Comments */
31
        $comments = \Xoops::getModuleHelper('comments'); //need this here to init constants
32
        $criteria = new CriteriaCompo(new Criteria('status', Comments::STATUS_PENDING));
33
        $ret = array();
34
        if ($count = $comments->getHandlerComment()->getCount($criteria)) {
0 ignored issues
show
Bug introduced by
The method getCount does only exist in XoopsPersistableObjectHandler, but not in XoopsObjectHandler.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
35
            $ret[] = [
36
                'count' => $count,
37
                'name' => $comments->getModule()->getVar('name'),
38
                'link' => $comments->url('admin/main.php')
39
            ];
40
        }
41
        return $ret;
42
    }
43
44
}