Completed
Pull Request — master (#101)
by Gino
03:22
created

UserSingle::getUserSingleBody()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 9
rs 9.6666
cc 1
eloc 6
nc 1
nop 3
1
<?php
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: UserSingle.php 12258 2014-01-02 09:33:29Z timgno $
23
 */
24
25
/**
26
 * Class UserSingle.
27
 */
28
class UserSingle 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...
29
{
30
    /*
31
    * @var mixed
32
    */
33
    private $uc = null;
34
35
    /*
36
    * @var string
37
    */
38
    private $xc = null;
39
40
    /*
41
    *  @public function constructor
42
    *  @param null
43
    */
44
    /**
45
     *
46
     */
47
    public function __construct()
48
    {
49
        parent::__construct();
50
        $this->xc = 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 $xc.

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...
51
        $this->phpcode = TDMCreatePhpCode::getInstance();
0 ignored issues
show
Documentation Bug introduced by
It seems like \TDMCreatePhpCode::getInstance() of type object<TDMCreatePhpCode> is incompatible with the declared type string of property $phpcode.

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...
52
        $this->uc = UserXoopsCode::getInstance();
53
    }
54
55
    /*
56
    *  @static function &getInstance
57
    *  @param null
58
    */
59
    /**
60
     * @return UserSingle
61
     */
62
    public static function &getInstance()
63
    {
64
        static $instance = false;
65
        if (!$instance) {
66
            $instance = new self();
67
        }
68
69
        return $instance;
70
    }
71
72
    /*
73
    *  @public function write
74
    *  @param string $module
75
    *  @param mixed $table
76
    *  @param string $filename
77
    */
78
    /**
79
     * @param $module
80
     * @param $table
81
     * @param $filename
82
     */
83
    public function write($module, $table, $filename)
84
    {
85
        $this->setModule($module);
86
        $this->setTable($table);
87
        $this->setFileName($filename);
88
    }
89
90
    /**
91
     * @private function getUserSingleHeader
92
     *
93
     * @param $moduleDirname
94
     *
95
     * @return string
96
     */
97
    private function getUserSingleHeader($moduleDirname, $table, $fields)
98
    {
99
        $ret = $this->getInclude();
100
        foreach (array_keys($fields) as $f) {
101
            $fieldName = $fields[$f]->getVar('field_name');
102
            if (0 == $f) {
103
                $fieldId = $fieldName;
104
            }
105
            if (1 == $fields[$f]->getVar('field_parent')) {
106
                $fieldPid = $fieldName;
107
            }
108
        }
109
        if ($table->getVar('table_category') == 1) {
110
            $ccFieldPid = $this->getCamelCase($fieldPid, false, true);
0 ignored issues
show
Bug introduced by
The variable $fieldPid does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
111
            $ret .= $this->xc->getXcXoopsRequest("{$ccFieldPid}", "{$fieldPid}", '0', 'Int');
0 ignored issues
show
Bug introduced by
The method getXcXoopsRequest cannot be called on $this->xc (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...
112
        }
113
        $ccFieldId = $this->getCamelCase($fieldId, false, true);
0 ignored issues
show
Bug introduced by
The variable $fieldId does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
114
        $ret .= $this->xc->getXcXoopsRequest("{$ccFieldId}", "{$fieldId}", '0', 'Int');
0 ignored issues
show
Bug introduced by
The method getXcXoopsRequest cannot be called on $this->xc (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...
115
        $ret .= $this->uc->getUserTplMain($moduleDirname);
116
        $ret .= $this->phpcode->getPhpCodeIncludeDir('XOOPS_ROOT_PATH', 'header', true);
0 ignored issues
show
Bug introduced by
The method getPhpCodeIncludeDir cannot be called on $this->phpcode (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...
117
        $ret .= $this->phpcode->getPhpCodeCommentLine('Define Stylesheet');
0 ignored issues
show
Bug introduced by
The method getPhpCodeCommentLine cannot be called on $this->phpcode (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...
118
        $ret .= $this->xc->getXcAddStylesheet();
0 ignored issues
show
Bug introduced by
The method getXcAddStylesheet cannot be called on $this->xc (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...
119
120
        return $ret;
121
    }
122
123
    /*
124
     * @public function getUserSingleBody     
125
     * @param $moduleDirname
126
     * @param $tableName
127
     * @param $language
128
     *
129
     * @return string
130
     */
131
    public function getUserSingleBody($moduleDirname, $tableName, $language)
0 ignored issues
show
Unused Code introduced by
The parameter $moduleDirname 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...
Unused Code introduced by
The parameter $tableName 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...
Unused Code introduced by
The parameter $language 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...
132
    {
133
        $ret = <<<EOT
134
135
EOT;
136
        $ret .= $this->getSimpleString('$keywords = array();');
137
138
        return $ret;
139
    }
140
141
    /**
142
     * @private function getUserSingleFooter
143
     *
144
     * @param $moduleDirname
145
     * @param $tableName
146
     * @param $language
147
     *
148
     * @return string
149
     */
150
    private function getUserSingleFooter($moduleDirname, $tableName, $language)
151
    {
152
        $stuModuleDirname = strtoupper($moduleDirname);
153
        $stuTableName = strtoupper($tableName);
154
        $ret = $this->phpcode->getPhpCodeCommentLine('Breadcrumbs');
0 ignored issues
show
Bug introduced by
The method getPhpCodeCommentLine cannot be called on $this->phpcode (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...
155
        $ret .= $this->uc->getUserBreadcrumbs($language, $stuTableName);
156
        $ret .= $this->phpcode->getPhpCodeCommentLine('Keywords');
0 ignored issues
show
Bug introduced by
The method getPhpCodeCommentLine cannot be called on $this->phpcode (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->uc->getUserMetaKeywords($moduleDirname);
158
        $ret .= $this->phpcode->getPhpCodeUnset('keywords');
0 ignored issues
show
Bug introduced by
The method getPhpCodeUnset cannot be called on $this->phpcode (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
        $ret .= $this->phpcode->getPhpCodeCommentLine('Description');
0 ignored issues
show
Bug introduced by
The method getPhpCodeCommentLine cannot be called on $this->phpcode (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...
160
        $ret .= $this->uc->getUserMetaDesc($moduleDirname, $language, $stuTableName);
161
        $ret .= $this->xc->getXcTplAssign('xoops_mpageurl', "{$stuModuleDirname}_URL.'/index.php'");
0 ignored issues
show
Bug introduced by
The method getXcTplAssign cannot be called on $this->xc (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...
162
        $ret .= $this->xc->getXcTplAssign('xoops_icons32_url', 'XOOPS_ICONS32_URL');
0 ignored issues
show
Bug introduced by
The method getXcTplAssign cannot be called on $this->xc (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...
163
        $ret .= $this->xc->getXcTplAssign("{$moduleDirname}_upload_url", "{$stuModuleDirname}_UPLOAD_URL");
0 ignored issues
show
Bug introduced by
The method getXcTplAssign cannot be called on $this->xc (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...
164
        $ret .= $this->getInclude('footer');
165
166
        return $ret;
167
    }
168
169
    /*
170
    *  @public function render
171
    *  @param null
172
    */
173
    /**
174
     * @return bool|string
175
     */
176
    public function render()
177
    {
178
        $module = $this->getModule();
179
        $table = $this->getTable();
180
        $filename = $this->getFileName();
181
        $moduleDirname = $module->getVar('mod_dirname');
182
        $tableId = $table->getVar('table_id');
183
        $tableMid = $table->getVar('table_mid');
184
        $tableName = $table->getVar('table_name');
185
        $fields = $this->getTableFields($tableMid, $tableId);
186
        $language = $this->getLanguage($moduleDirname, 'MA');
187
        $content = $this->getHeaderFilesComments($module, $filename);
188
        $content .= $this->getUserSingleHeader($moduleDirname, $table, $fields);
189
        $content .= $this->getUserSingleBody($module, $tableName, $language);
190
        $content .= $this->getUserSingleFooter($moduleDirname, $tableName, $language);
191
        $this->create($moduleDirname, '/', $filename, $content, _AM_TDMCREATE_FILE_CREATED, _AM_TDMCREATE_FILE_NOTCREATED);
192
193
        return $this->renderFile();
194
    }
195
}
196