Passed
Branch timgno (61fada)
by Gino
05:14
created

UserRate::getUserRateForm()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 15

Duplication

Lines 18
Ratio 100 %
Metric Value
dl 18
loc 18
rs 9.4285
cc 1
eloc 15
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: UserRate.php 12258 2014-01-02 09:33:29Z timgno $
23
 */
24
defined('XOOPS_ROOT_PATH') || die('Restricted access');
25
26
/**
27
 * Class UserRate.
28
 */
29
class UserRate extends TDMCreateFile
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 $usercode = null;
35
36
    /*
37
    * @var mixed
38
    */
39
    private $phpcode = null;
40
41
    /*
42
    * @var string
43
    */
44
    private $xoopscode;
45
46
    /*
47
    *  @public function constructor
48
    *  @param null
49
    */
50
    /**
51
     *
52
     */
53
    public function __construct()
54
    {
55
        parent::__construct();
56
        $this->xoopscode = TDMCreateXoopsCode::getInstance();
0 ignored issues
show
Documentation Bug introduced by
It seems like \TDMCreateXoopsCode::getInstance() of type object<TDMCreateXoopsCode> is incompatible with the declared type string of property $xoopscode.

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...
57
        $this->phpcode = TDMCreatePhpCode::getInstance();
58
        $this->usercode = UserXoopsCode::getInstance();
59
    }
60
61
    /*
62
    *  @static function &getInstance
63
    *  @param null
64
    */
65
    /**
66
     * @return UserRate
67
     */
68
    public static function &getInstance()
69
    {
70
        static $instance = false;
71
        if (!$instance) {
72
            $instance = new self();
73
        }
74
75
        return $instance;
76
    }
77
78
    /*
79
    *  @public function write
80
    *  @param string $module
81
    *  @param mixed $table
82
    *  @param string $filename
83
    */
84
    /**
85
     * @param $module
86
     * @param $table
87
     * @param $filename
88
     */
89
    public function write($module, $table, $filename)
90
    {
91
        $this->setModule($module);
92
        $this->setTable($table);
93
        $this->setFileName($filename);
94
    }
95
96
    /**
97
     * @private function getUserRateHeader
98
     *
99
     * @param $moduleDirname
100
     * @param $tableName
101
     *
102
     * @return string
103
     */
104
    public function getUserRateHeader($moduleDirname, $tableName)
105
    {
106
        $ret = $this->getInclude();
107
        $ret .= $this->xoopscode->getXoopsCodeXoopsRequest('op', 'op', 'form');
0 ignored issues
show
Bug introduced by
The method getXoopsCodeXoopsRequest cannot be called on $this->xoopscode (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
108
        $ret .= $this->xoopscode->getXoopsCodeXoopsRequest('lid', 'lid', '', 'Int');
0 ignored issues
show
Bug introduced by
The method getXoopsCodeXoopsRequest cannot be called on $this->xoopscode (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
109
        $ret .= $this->usercode->getUserTplMain($moduleDirname, $tableName);
110
        $ret .= $this->phpcode->getPhpCodeIncludeDir('XOOPS_ROOT_PATH', 'header', true);
111
        $ret .= $this->getCommentLine('Define Stylesheet');
112
        $ret .= $this->xoopscode->getXoopsCodeAddStylesheet();
0 ignored issues
show
Bug introduced by
The method getXoopsCodeAddStylesheet cannot be called on $this->xoopscode (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
113
114
        return $ret;
115
    }
116
117
    /*
118
     *  @private function getUserRateSwitch
119
     *  @param $moduleDirname
120
     *  @param $tableId
121
     *  @param $tableMid
122
     *  @param $tableName
123
     *  @param $tableSoleName
124
     *  @param $language
125
     *
126
     * @return string
127
     */
128 View Code Duplication
    private function getUserRateSwitch($moduleDirname, $tableId, $tableMid, $tableName, $tableSoleName, $language)
0 ignored issues
show
Unused Code introduced by
The parameter $tableSoleName 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...
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
129
    {
130
        $fields = $this->getTableFields($tableMid, $tableId);
131
        $cases = array('form' => array($this->getUserRateForm($tableName, $language)),
132
                    'save' => array($this->getUserRateSave($moduleDirname, $fields, $tableName, $language)), );
133
134
        return $this->xoopscode->getXoopsCodeSwitch('op', $cases, true);
0 ignored issues
show
Bug introduced by
The method getXoopsCodeSwitch cannot be called on $this->xoopscode (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
135
    }
136
137
    /*
138
     * @public function getAdminPagesList
139
     * @param $tableName
140
     * @param $language
141
     *
142
     * @return string
143
     */
144 View Code Duplication
    public function getUserRateForm($tableName, $language)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
145
    {
146
        $ret = $this->getCommentLine('Mavigation');
147
        $ret .= $this->xoopscode->getXoopsCodeEqualsOperator('$navigation', "{$language}RATE");
0 ignored issues
show
Bug introduced by
The method getXoopsCodeEqualsOperator cannot be called on $this->xoopscode (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
148
        $ret .= $this->xoopscode->getXoopsCodeTplAssign('navigation', '$navigation');
0 ignored issues
show
Bug introduced by
The method getXoopsCodeTplAssign cannot be called on $this->xoopscode (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
149
        $ret .= $this->getCommentLine('Title of page');
150
        $ret .= $this->xoopscode->getXoopsCodeEqualsOperator('$title', "{$language}RATE . '&nbsp;-&nbsp;'");
0 ignored issues
show
Bug introduced by
The method getXoopsCodeEqualsOperator cannot be called on $this->xoopscode (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
151
        $ret .= $this->xoopscode->getXoopsCodeEqualsOperator('$title.', "\$GLOBALS['xoopsModule']->name()");
0 ignored issues
show
Bug introduced by
The method getXoopsCodeEqualsOperator cannot be called on $this->xoopscode (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
152
        $ret .= $this->xoopscode->getXoopsCodeTplAssign('xoops_pagetitle', '$title');
0 ignored issues
show
Bug introduced by
The method getXoopsCodeTplAssign cannot be called on $this->xoopscode (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
153
        $ret .= $this->getCommentLine('Description');
154
        $ret .= $this->usercode->getUserAddMeta('description', $language, 'RATE');
155
        $ret .= $this->getCommentLine('Form Create');
156
        $ret .= $this->xoopscode->getXoopsCodeObjHandlerCreate($tableName);
0 ignored issues
show
Bug introduced by
The method getXoopsCodeObjHandlerCreate cannot be called on $this->xoopscode (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
157
        $ret .= $this->xoopscode->getXoopsCodeGetForm('form', $tableName, 'Obj');
0 ignored issues
show
Bug introduced by
The method getXoopsCodeGetForm cannot be called on $this->xoopscode (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
158
        $ret .= $this->xoopscode->getXoopsCodeTplAssign('form', '$form->render()');
0 ignored issues
show
Bug introduced by
The method getXoopsCodeTplAssign cannot be called on $this->xoopscode (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
159
160
        return $ret;
161
    }
162
163
    /*
164
    *  @public function getUserRateSave
165
    *  @param string $moduleDirname
166
    *  @param string $tableName
167
    */
168
    /**
169
     * @param $moduleDirname
170
     * @param $table_id
171
     * @param $tableName
172
     *
173
     * @return string
174
     */
175 View Code Duplication
    public function getUserRateSave($moduleDirname, $fields, $tableName, $language)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
176
    {
177
        $ucfTableName = ucfirst($tableName);
0 ignored issues
show
Unused Code introduced by
$ucfTableName 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...
178
        $ret = $this->phpcode->getPhpCodeCommentLine('Security Check');
179
        $xoopsSecurityCheck = $this->xoopscode->getXoopsCodeSecurityCheck();
0 ignored issues
show
Bug introduced by
The method getXoopsCodeSecurityCheck cannot be called on $this->xoopscode (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
180
        $securityError = $this->xoopscode->getXoopsCodeSecurityErrors();
0 ignored issues
show
Bug introduced by
The method getXoopsCodeSecurityErrors cannot be called on $this->xoopscode (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
181
        $implode = $this->phpcode->getPhpCodeImplode(',', $securityError);
182
        $redirectError = $this->xoopscode->getXoopsCodeRedirectHeader($tableName, '', '3', $implode);
0 ignored issues
show
Bug introduced by
The method getXoopsCodeRedirectHeader cannot be called on $this->xoopscode (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
183
        $ret .= $this->phpcode->getPhpCodeConditions($xoopsSecurityCheck, '', '', $redirectError, false, "\t");
184
        $ret .= $this->xoopscode->getXoopsCodeObjHandlerCreate($tableName);
0 ignored issues
show
Bug introduced by
The method getXoopsCodeObjHandlerCreate cannot be called on $this->xoopscode (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
185
186
        $ret .= $this->xoopscode->getXoopsCodeSaveElements($moduleDirname, $tableName, $fields);
0 ignored issues
show
Bug introduced by
The method getXoopsCodeSaveElements cannot be called on $this->xoopscode (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
187
188
        $ret .= $this->getCommentLine('Insert Data');
189
        $insert = $this->xoopscode->getXoopsCodeInsert($tableName, $tableName, 'Obj', true);
0 ignored issues
show
Bug introduced by
The method getXoopsCodeInsert cannot be called on $this->xoopscode (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
190
        $confirmOk = $this->xoopscode->getXoopsCodeRedirectHeader('index', '', '2', "{$language}FORM_OK");
0 ignored issues
show
Bug introduced by
The method getXoopsCodeRedirectHeader cannot be called on $this->xoopscode (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
191
        $ret .= $this->phpcode->getPhpCodeConditions($insert, '', '', $confirmOk, false, "\t");
192
193
        $ret .= $this->getCommentLine('Get Form Error');
194
        $ret .= $this->xoopscode->getXoopsCodeTplAssign('error', "\${$tableName}Obj->getHtmlErrors()");
0 ignored issues
show
Bug introduced by
The method getXoopsCodeTplAssign cannot be called on $this->xoopscode (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
195
        $ret .= $this->xoopscode->getXoopsCodeGetForm('form', $tableName, 'Obj');
0 ignored issues
show
Bug introduced by
The method getXoopsCodeGetForm cannot be called on $this->xoopscode (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
196
        $ret .= $this->xoopscode->getXoopsCodeTplAssign('form', '$form->display()');
0 ignored issues
show
Bug introduced by
The method getXoopsCodeTplAssign cannot be called on $this->xoopscode (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
197
198
        return $ret;
199
    }
200
201
    /*
202
    *  @public function getUserRateFooter
203
    *  @param null
204
    */
205
    /**
206
     * @return string
207
     */
208 View Code Duplication
    public function getUserRateFooter($moduleDirname, $language)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
209
    {
210
        $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...
211
        $ret = $this->getCommentLine('Breadcrumbs');
212
        $ret .= $this->usercode->getUserBreadcrumbs('RATE', $language);
213
        $ret .= $this->getInclude('footer');
214
215
        return $ret;
216
    }
217
218
    /*
219
    *  @public function render
220
    *  @param null
221
    */
222
    /**
223
     * @return bool|string
224
     */
225 View Code Duplication
    public function render()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
226
    {
227
        $module = $this->getModule();
228
        $table = $this->getTable();
229
        $filename = $this->getFileName();
230
        $moduleDirname = $module->getVar('mod_dirname');
231
        $tableId = $table->getVar('table_id');
232
        $tableMid = $table->getVar('table_mid');
233
        $tableName = $table->getVar('table_name');
234
        $tableSoleName = $table->getVar('table_solename');
235
        $fields = $this->getTableFields($tableMid, $tableId);
0 ignored issues
show
Unused Code introduced by
$fields 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...
236
        $language = $this->getLanguage($moduleDirname, 'MA');
237
        $content = $this->getHeaderFilesComments($module, $filename);
238
        $content .= $this->getUserRateHeader($moduleDirname, $tableName);
239
        $content .= $this->getUserRateSwitch($moduleDirname, $tableId, $tableMid, $tableName, $tableSoleName, $language);
240
        $content .= $this->getUserRateFooter($moduleDirname, $language);
241
242
        $this->create($moduleDirname, '/', $filename, $content, _AM_TDMCREATE_FILE_CREATED, _AM_TDMCREATE_FILE_NOTCREATED);
243
244
        return $this->renderFile();
245
    }
246
}
247