Completed
Push — master ( 88111b...b3fce7 )
by Michael
05:58
created

CustomtagHandler   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 47
rs 10
c 0
b 0
f 0
wmc 6
lcom 1
cbo 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
B getCustomtagsByName() 0 29 5
1
<?php namespace XoopsModules\Smartobject;
2
3
/*
4
 * You may not change or alter any portion of this comment or credits
5
 * of supporting developers from this source code or any supporting source code
6
 * which is considered copyrighted (c) material of the original comment or credit authors.
7
 *
8
 * This program is distributed in the hope that it will be useful,
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11
 */
12
13
/**
14
 * @copyright    XOOPS Project https://xoops.org/
15
 * @license      GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
16
 * @package
17
 * @since
18
 * @author     XOOPS Development Team
19
 */
20
21
use XoopsModules\Smartobject;
22
23
// defined('XOOPS_ROOT_PATH') || die('Restricted access');
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
24
25
//require_once XOOPS_ROOT_PATH . '/modules/smartobject/class/smartobject.php';
0 ignored issues
show
Unused Code Comprehensibility introduced by
38% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
26
27
28
/**
29
 * Class SmartobjectCustomtagHandler
30
 */
31
class CustomtagHandler extends Smartobject\PersistableObjectHandler
32
{
33
    public $objects = false;
34
35
    /**
36
     * SmartobjectCustomtagHandler constructor.
37
     * @param \XoopsDatabase $db
38
     */
39
    public function __construct(\XoopsDatabase $db)
40
    {
41
        parent::__construct($db, Customtag::class, 'customtagid', 'name', 'description', 'smartobject');
42
        $this->addPermission('view', _CO_SOBJECT_CUSTOMTAG_PERMISSION_VIEW, _CO_SOBJECT_CUSTOMTAG_PERMISSION_VIEW_DSC);
43
    }
44
45
    /**
46
     * @return array|bool
47
     */
48
    public function getCustomtagsByName()
49
    {
50
        if (!$this->objects) {
51
            global $xoopsConfig;
52
53
            $ret = [];
54
55
            $criteria = new \CriteriaCompo();
56
57
            $criteria_language = new \CriteriaCompo();
58
            $criteria_language->add(new \Criteria('language', $xoopsConfig['language']));
59
            $criteria_language->add(new \Criteria('language', 'all'), 'OR');
60
            $criteria->add($criteria_language);
61
62
            $smartobjectPermissionsHandler = new PermissionHandler($this);
63
            $granted_ids                   = $smartobjectPermissionsHandler->getGrantedItems('view');
64
65
            if ($granted_ids && count($granted_ids) > 0) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $granted_ids of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
66
                $criteria->add(new \Criteria('customtagid', '(' . implode(', ', $granted_ids) . ')', 'IN'));
67
                $customtagsObj =& $this->getObjects($criteria, true);
68
                foreach ($customtagsObj as $customtagObj) {
69
                    $ret[$customtagObj->getVar('name')] = $customtagObj;
70
                }
71
            }
72
            $this->objects = $ret;
0 ignored issues
show
Documentation Bug introduced by
It seems like $ret of type array is incompatible with the declared type boolean of property $objects.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
73
        }
74
75
        return $this->objects;
76
    }
77
}
78