PluginItem::doDecoration()   A
last analyzed

Complexity

Conditions 5
Paths 7

Size

Total Lines 19
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 9
nc 7
nop 1
dl 0
loc 19
rs 9.6111
c 0
b 0
f 0
1
<?php namespace XoopsModules\Mymenus\Plugins\Constant;
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         http://www.gnu.org/licenses/gpl-2.0.html GNU Public License
16
 * @package         Mymenus
17
 * @since           1.0
18
 * @author          trabis <[email protected]>
19
 */
20
21
use XoopsModules\Mymenus;
22
23
defined('XOOPS_ROOT_PATH') || die('Restricted access');
24
25
/**
26
 * Class PluginItem
27
 */
28
class PluginItem extends Mymenus\PluginItem
29
{
30
    public static function eventLinkDecoration()
31
    {
32
        $registry          = Mymenus\Registry::getInstance();
33
        $linkArray         = $registry->getEntry('link_array');
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $linkArray is correct as $registry->getEntry('link_array') targeting XoopsModules\Mymenus\Registry::getEntry() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
34
        $linkArray['link'] = self::doDecoration($linkArray['link']);
35
        $registry->setEntry('link_array', $linkArray);
36
    }
37
38
    public static function eventImageDecoration()
39
    {
40
        $registry           = Mymenus\Registry::getInstance();
41
        $linkArray          = $registry->getEntry('link_array');
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $linkArray is correct as $registry->getEntry('link_array') targeting XoopsModules\Mymenus\Registry::getEntry() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
42
        $linkArray['image'] = self::doDecoration($linkArray['image']);
43
        $registry->setEntry('link_array', $linkArray);
44
    }
45
46
    public static function eventTitleDecoration()
47
    {
48
        $registry           = Mymenus\Registry::getInstance();
49
        $linkArray          = $registry->getEntry('link_array');
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $linkArray is correct as $registry->getEntry('link_array') targeting XoopsModules\Mymenus\Registry::getEntry() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
50
        $linkArray['title'] = self::doDecoration($linkArray['title']);
51
        $registry->setEntry('link_array', $linkArray);
52
    }
53
54
    public static function eventAltTitleDecoration()
55
    {
56
        $registry               = Mymenus\Registry::getInstance();
57
        $linkArray              = $registry->getEntry('link_array');
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $linkArray is correct as $registry->getEntry('link_array') targeting XoopsModules\Mymenus\Registry::getEntry() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
58
        $linkArray['alt_title'] = self::doDecoration($linkArray['alt_title']);
59
        $registry->setEntry('link_array', $linkArray);
60
    }
61
62
    /**
63
     * @param $string
64
     *
65
     * @return mixed
66
     */
67
    protected static function doDecoration($string)
68
    {
69
        $registry = Mymenus\Registry::getInstance();
0 ignored issues
show
Unused Code introduced by
The assignment to $registry is dead and can be removed.
Loading history...
70
        //        $string = '';
71
72
        if (!preg_match('/{(.*\|.*)}/i', $string, $reg)) {
73
            return $string;
74
        }
75
76
        $expression = $reg[0];
77
        list($validator, $value) = array_map('strtoupper', explode('|', $reg[1]));
78
79
        if ('CONSTANT' === $validator) {
80
            if (defined($value)) {
81
                $string = str_replace($expression, constant($value), $string);
82
            }
83
        }
84
85
        return isset($string) ? $string : null;
86
    }
87
}
88