Passed
Pull Request — master (#19)
by Michael
02:30
created

VideosHandler   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 38
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getActiveCriteria() 0 16 2
1
<?php
2
3
namespace XoopsModules\Xoopstube;
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
/**
16
 *  Xoopstube class
17
 *
18
 * @copyright       The XUUPS Project http://sourceforge.net/projects/xuups/
19
 * @license         http://www.fsf.org/copyleft/gpl.html GNU public license
20
 * @package         Xoopstube
21
 * @subpackage      Utils
22
 * @since           1.0
23
 * @author          trabis <[email protected]>
24
 */
25
26
use XoopsModules\Xoopstube\{
27
    Helper
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, XoopsModules\Xoopstube\Helper. 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...
28
};
29
30
/** @var Helper $this ->helper */
31
32
/**
33
 * Class VideosHandler
34
 */
35
class VideosHandler extends \XoopsPersistableObjectHandler
36
{
37
    /**
38
     * @var Helper
39
     * @access public
40
     */
41
    public $helper = null;
42
43
    /**
44
     * @param null|\XoopsDatabase $db
45
     */
46
    public function __construct(\XoopsDatabase $db = null)
47
    {
48
        parent::__construct($db, 'xoopstube_videos', Videos::class, 'lid', 'title');
49
        $this->helper = Helper::getInstance();
50
    }
51
52
    /**
53
     * Get criteria for active videos
54
     *
55
     * @return \CriteriaCompo
56
     */
57
    public function getActiveCriteria()
58
    {
59
        $grouppermHandler = \xoops_getHandler('groupperm');
60
61
        $criteria = new \CriteriaCompo(new \Criteria('offline', false));
0 ignored issues
show
Bug introduced by
false of type false is incompatible with the type string expected by parameter $value of Criteria::__construct(). ( Ignorable by Annotation )

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

61
        $criteria = new \CriteriaCompo(new \Criteria('offline', /** @scrutinizer ignore-type */ false));
Loading history...
62
        $criteria->add(new \Criteria('published', 0, '>'));
63
        $criteria->add(new \Criteria('published', \time(), '<='));
64
        $expiredCriteria = new \CriteriaCompo(new \Criteria('expired', 0));
65
        $expiredCriteria->add(new \Criteria('expired', \time(), '>='), 'OR');
66
        $criteria->add($expiredCriteria);
67
        // add criteria for categories that the user has permissions for
68
        $groups                   = \is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getGroups() : [0 => XOOPS_GROUP_ANONYMOUS];
69
        $allowedDownCategoriesIds = $grouppermHandler->getItemIds('XTubeCatPerm', $groups, $this->helper->getModule()->mid());
0 ignored issues
show
Bug introduced by
The method getItemIds() does not exist on XoopsObjectHandler. It seems like you code against a sub-type of XoopsObjectHandler such as XoopsGroupPermHandler or XoopsPersistableObjectHandler. ( Ignorable by Annotation )

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

69
        /** @scrutinizer ignore-call */ 
70
        $allowedDownCategoriesIds = $grouppermHandler->getItemIds('XTubeCatPerm', $groups, $this->helper->getModule()->mid());
Loading history...
70
        $criteria->add(new \Criteria('cid', '(' . \implode(',', $allowedDownCategoriesIds) . ')', 'IN'));
71
72
        return $criteria;
73
    }
74
}
75