Completed
Pull Request — master (#51)
by Gino
06:03
created

UserXoopsCode::getUserBreadcrumbs()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 6
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
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
    * @var string
43
    */
44
    protected $usercode;
45
46
    /*
47
    *  @public function constructor
48
    *  @param null
49
    */
50
    /**
51
     *
52
     */
53
    public function __construct()
54
    {
55
        $this->phpcode = TDMCreatePhpCode::getInstance();
56
        $this->xoopscode = TDMCreateXoopsCode::getInstance();
57
    }
58
59
    /*
60
    *  @static function &getInstance
61
    *  @param null
62
    */
63
    /**
64
     * @return UserXoopsCode
65
     */
66
    public static function &getInstance()
67
    {
68
        static $instance = false;
69
        if (!$instance) {
70
            $instance = new self();
71
        }
72
73
        return $instance;
74
    }
75
76
    /*
77
    *  @public function getUserTplMain
78
    *  @param string $moduleDirname
79
    *  @param string $tableName
80
    *  @return string
81
    */
82
    public function getUserTplMain($moduleDirname, $tableName = 'index')
83
    {
84
        return "\$GLOBALS['xoopsOption']['template_main'] = '{$moduleDirname}_{$tableName}.tpl';\n";
85
    }
86
87
    /*
88
     * @public function getUserAddMeta
89
     * @param $type
90
     * @param $language
91
     * @param $tableName
92
     *  
93
     * @return string
94
     */
95
    public function getUserAddMeta($type = '', $language, $tableName = '')
96
    {
97
        $stuTableName = strtoupper($tableName);
98
99
        return "\$GLOBALS['xoTheme']->addMeta( 'meta', '{$type}', strip_tags({$language}{$stuTableName}));\n";
100
    }
101
102
    /*
103
    *  @public function getUserMetaKeywords
104
    *  @param string $moduleDirname
105
    *  
106
    *  @return string
107
    */
108
    public function getUserMetaKeywords($moduleDirname)
109
    {
110
        return "{$moduleDirname}MetaKeywords(\${$moduleDirname}->getConfig('keywords').', '. implode(', ', \$keywords));\n";
111
    }
112
113
    /*
114
    *  @public function getUserMetaDesc
115
    *  @param string $moduleDirname
116
    *  @param string $stuTableSoleName
117
    *  @param string $language
118
    *  
119
    *  @return string
120
    */
121
    public function getUserMetaDesc($moduleDirname, $stuTableSoleName, $language)
122
    {
123
        $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...
124
125
        return "{$moduleDirname}MetaDescription({$language}{$stuTableSoleName}_DESC);\n";
126
    }
127
128
    /*
129
    *  @public function getUserBreadcrumbs
130
    *  @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...
131
    *  @param string $language
132
    *  
133
    *  @return string
134
    */
135
    public function getUserBreadcrumbs($tableName, $language)
136
    {
137
        $stuTableName = strtoupper($tableName);
138
139
        return "\$xoBreadcrumbs[] = array('title' => {$language}{$stuTableName});\n";
140
    }
141
142
    /*
143
    *  @public function getUserBreadcrumbs
144
    *  @param string $moduleDirname
145
    *  
146
    *  @return string
147
    */
148
    public function getUserBreadcrumbsHeaderFile($moduleDirname)
149
    {
150
        $stuModuleDirname = strtoupper($moduleDirname);
151
        $ret = $this->phpcode->getPhpCodeCommentLine('Breadcrumbs');
152
        $ret .= "\$xoBreadcrumbs = array();\n";
153
        $ret .= "\$xoBreadcrumbs[] = array('title' => \$GLOBALS['xoopsModule']->getVar('name'), 'link' => {$stuModuleDirname}_URL . '/');\n";
154
155
        return $ret;
156
    }
157
158
    /*
159
    *  @public function getUserBreadcrumbs
160
    *  @param null
161
    *  
162
    *  @return string
163
    */
164
    public function getUserBreadcrumbsFooterFile()
165
    {
166
        $cond = $this->xoopscode->getXoopsCodeTplAssign('xoBreadcrumbs', '$xoBreadcrumbs');
167
        $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...
168
169
        return $ret;
170
    }
171
}
172