Completed
Push — master ( b2a01c...544d04 )
by Gino
04:24
created

UserXoopsCode::getUserModVersion()   D

Complexity

Conditions 10
Paths 48

Size

Total Lines 28
Code Lines 22

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 28
rs 4.8196
cc 10
eloc 22
nc 48
nop 6

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 29 and the first side effect is on line 24.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
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
 * tdmcreate module.
14
 *
15
 * @copyright       The XOOPS Project http://sourceforge.net/projects/xoops/
16
 * @license         GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
17
 *
18
 * @since           2.5.0
19
 *
20
 * @author          Txmod Xoops http://www.txmodxoops.org
21
 *
22
 * @version         $Id: UserXoopsCode.php 12258 2014-01-02 09:33:29Z timgno $
23
 */
24
defined('XOOPS_ROOT_PATH') || die('Restricted access');
25
26
/**
27
 * Class UserXoopsCode.
28
 */
29
class UserXoopsCode
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
30
{
31
    /*
32
    * @var mixed
33
    */
34
    private $phpcode = null;
35
36
    /*
37
    * @var mixed
38
    */
39
    private $xoopscode = null;
40
41
    /*
42
    *  @public function constructor
43
    *  @param null
44
    */
45
    /**
46
     *
47
     */
48
    public function __construct()
49
    {
50
        $this->phpcode = TDMCreatePhpCode::getInstance();
51
        $this->xoopscode = TDMCreateXoopsCode::getInstance();
52
    }
53
54
    /*
55
    *  @static function &getInstance
56
    *  @param null
57
    */
58
    /**
59
     * @return UserXoopsCode
60
     */
61
    public static function &getInstance()
62
    {
63
        static $instance = false;
64
        if (!$instance) {
65
            $instance = new self();
66
        }
67
68
        return $instance;
69
    }
70
71
    /*
72
    *  @public function getUserTplMain
73
    *  @param string $moduleDirname
74
    *  @param string $tableName
75
    *  @return string
76
    */
77
    public function getUserTplMain($moduleDirname, $tableName = 'index')
78
    {
79
        return "\$GLOBALS['xoopsOption']['template_main'] = '{$moduleDirname}_{$tableName}.tpl';\n";
80
    }
81
82
    /*
83
     * @public function getUserAddMeta
84
     * @param $type
85
     * @param $language
86
     * @param $tableName
87
     *  
88
     * @return string
89
     */
90
    public function getUserAddMeta($type = '', $language, $tableName = '')
91
    {
92
        $stuTableName = strtoupper($tableName);
93
94
        return "\$GLOBALS['xoTheme']->addMeta( 'meta', '{$type}', strip_tags({$language}{$stuTableName}));\n";
95
    }
96
97
    /*
98
    *  @public function getUserMetaKeywords
99
    *  @param string $moduleDirname
100
    *  
101
    *  @return string
102
    */
103
    public function getUserMetaKeywords($moduleDirname)
104
    {
105
        return "{$moduleDirname}MetaKeywords(\${$moduleDirname}->getConfig('keywords').', '. implode(', ', \$keywords));\n";
106
    }
107
108
    /*
109
    *  @public function getUserMetaDesc
110
    *  @param string $moduleDirname
111
    *  @param string $stuTableSoleName
112
    *  @param string $language
113
    *  
114
    *  @return string
115
    */
116
    public function getUserMetaDesc($moduleDirname, $stuTableSoleName, $language)
117
    {
118
        $stuModuleDirname = strtoupper($moduleDirname);
0 ignored issues
show
Unused Code introduced by
$stuModuleDirname is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
119
120
        return "{$moduleDirname}MetaDescription({$language}{$stuTableSoleName}_DESC);\n";
121
    }
122
123
    /*
124
    *  @public function getUserBreadcrumbs
125
    *  @param string $moduleDirname
0 ignored issues
show
Bug introduced by
There is no parameter named $moduleDirname. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
126
    *  @param string $language
127
    *  
128
    *  @return string
129
    */
130
    public function getUserBreadcrumbs($tableName, $language)
131
    {
132
        $stuTableName = strtoupper($tableName);
133
134
        return "\$xoBreadcrumbs[] = array('title' => {$language}{$stuTableName});\n";
135
    }
136
137
    /*
138
    *  @public function getUserBreadcrumbs
139
    *  @param string $moduleDirname
140
    *  
141
    *  @return string
142
    */
143
    public function getUserBreadcrumbsHeaderFile($moduleDirname)
144
    {
145
        $stuModuleDirname = strtoupper($moduleDirname);
146
        $ret = $this->phpcode->getPhpCodeCommentLine('Breadcrumbs');
147
        $ret .= "\$xoBreadcrumbs = array();\n";
148
        $ret .= "\$xoBreadcrumbs[] = array('title' => \$GLOBALS['xoopsModule']->getVar('name'), 'link' => {$stuModuleDirname}_URL . '/');\n";
149
150
        return $ret;
151
    }
152
153
    /*
154
    *  @public function getUserBreadcrumbs
155
    *  @param null
156
    *  
157
    *  @return string
158
    */
159
    public function getUserBreadcrumbsFooterFile()
160
    {
161
        $cond = $this->xoopscode->getXoopsCodeTplAssign('xoBreadcrumbs', '$xoBreadcrumbs');
162
        $ret .= $this->phpcode->getPhpCodeConditions('count($xoBreadcrumbs)', ' > ', '1', $cond, false, "\t\t");
0 ignored issues
show
Bug introduced by
The variable $ret does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
163
164
        return $ret;
165
    }
166
167
    /*
168
    *  @public function getUserModVersion
169
    *  @param $element
170
    *  @param $descriptions
171
    *  @param $left
172
    *  @param $index
173
    *  @param $right	
174
    *  @param $arrayOptions
175
    *  
176
    *  @return string
177
    */
178
    public function getUserModVersion($element = 1, $descriptions = array(), $left = '', $index = '', $right = '', $arrayOptions = '')
0 ignored issues
show
Unused Code introduced by
The parameter $arrayOptions is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
179
    {
180
        $i = (is_string($index) && !empty($index)) ? "'{$index}'" : $index;
0 ignored issues
show
Unused Code introduced by
$i is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
181
        $r = (is_string($right) && !empty($right)) ? "'{$right}'" : $right;
0 ignored issues
show
Unused Code introduced by
$r is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
182
        $mv = '$modversion';
183
        $ret = '';
184
        foreach ($descriptions as $key => $desc) {
185
            switch ($element) {
186
                case 1:
187
                default:
188
                    $ret .= $mv."['{$left}'] = {$desc};\n";
189
                    break;
190
                case 2:
0 ignored issues
show
Unused Code introduced by
case 2: $ret .= $mv ...{$desc};\n"; break; does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
191
                    $ret .= $mv."['{$left}'][{$i}] = {$desc};\n";
192
                    break;
193
                case 3:
194
                    if (empty($arrayOptions)) {
0 ignored issues
show
Bug introduced by
The variable $arrayOptions seems only to be defined at a later point. As such the call to empty() seems to always evaluate to true.

This check marks calls to isset(...) or empty(...) that are found before the variable itself is defined. These will always have the same result.

This is likely the result of code being shifted around. Consider removing these calls.

Loading history...
195
                        $ret .= $mv."['{$left}'][{$i}][{$r}] = {$desc};\n";
196
                    } else {
197
                        $ret .= $mv."['{$left}'][{$i}][{$r}] = {$desc};";
198
                        $ret .= $mv."['{$left}'][{$i}][{$r}] = {$arrayOptions};\n";
199
                    }
200
                break;
201
            }
202
        }
203
204
        return $ret;
205
    }
206
}
207